[RMXP] Enemy HP Error

Discussion in 'RGSSx Script Support' started by Qeo, May 28, 2019.

    Tags:
  1. Qeo

    Qeo Veteran Veteran

    Messages:
    98
    Likes Received:
    19
    I already posted a thread about this but it was in the wrong section. Basically enemies have slightly more [sometimes double] the HP they should have, and sometimes less.

    My Timed Hit script was edited to be able to use skills in menu, but strangely that's when enemy hp issues and crashing began to occur. The crashing problem appears to have been solved though.

    This is the edited script
    Code:
    #==============================================================================
    # ** Game_Battler
    #------------------------------------------------------------------------------
    #  This class deals with battlers. It's used as a superclass for the Game_Actor
    #  and Game_Enemy classes.
    #==============================================================================
    
    class Game_Battler
      #--------------------------------------------------------------------------
      # * Alias Listings
      #--------------------------------------------------------------------------
      alias timed_hit_attack_effect attack_effect
      alias timed_hit_skill_effect skill_effect
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_accessor :timed_hit_hit_percent
      attr_accessor :timed_hit_use_percent
      attr_accessor :timed_hit_state_to_add
      #--------------------------------------------------------------------------
      # * Applying Normal Attack Effects
      #     attacker : battler
      #--------------------------------------------------------------------------
      def attack_effect(attacker)  
        effective = false
        # If part of Timed Hits
        if @timed_hit_use_percent
          hp = self.hp
          # Perform the original call and get effective
          effective = timed_hit_attack_effect(attacker)
          if self.damage != "Miss"
            self.hp = hp
            self.damage = Integer((@timed_hit_hit_percent * self.damage) / 100.0)
            if @timed_hit_state_to_add != nil
              self.add_state(@timed_hit_state_to_add)
            end
          end
        # If not part of Timed Hits
        else
          # Perform the original call and get effective
          effective = timed_hit_attack_effect(attacker)
        end
        @timed_hit_use_percent  = false
        @timed_hit_state_to_add = nil
        return effective
      end
      #--------------------------------------------------------------------------
      # * Apply Skill Effects
      #     user  : the one using skills (battler)
      #     skill : skill
      #--------------------------------------------------------------------------
      def skill_effect(user, skill)
        effective = false
        # If part of Timed Hits
        if @timed_hit_use_percent
          hp = self.hp
          # Perform the original call and get effective
          effective = timed_hit_skill_effect(user, skill)
                if self.damage != "Miss"
     self.hp = hp
    self.damage = ((@timed_hit_hit_percent * self.damage.to_i) / 100.0).to_i
          end
        # If not part of Timed Hits
        else
          # Perform the original call and get effective
          effective = timed_hit_skill_effect(user, skill)
        end
        @timed_hit_use_percent = false
        return effective
      end
    end
    
    
    
    #==============================================================================
    # ** Game_Actor
    #------------------------------------------------------------------------------
    #  This class handles the actor. It's used within the Game_Actors class
    #  ($game_actors) and refers to the Game_Party class ($game_party).
    #==============================================================================
    
    class Game_Actor < Game_Battler
      #--------------------------------------------------------------------------
      # * Public Instance Variables
      #--------------------------------------------------------------------------
      attr_reader   :actor_id
    end
    When I start a new project, the problem script appears to be Timed_Hits 2. When that is gone, the enemy HP issue is too, but then of course the timed hits don't work.

    This is the script
    Code:
    class Scene_Battle
      alias timed_hit_start_phase4 start_phase4
      def start_phase4
        if $game_party.timed_hit == nil
          $game_party.timed_hit= Timed_Hit.new
          $game_party.timed_hit.setup
        end
       
        @timed_hit = $game_party.timed_hit
       
        timed_hit_start_phase4
      end
     
      alias timed_hit_update_phase4_step3 update_phase4_step3
      def update_phase4_step3
        if @active_battler.is_a?(Game_Actor) &&    
           @active_battler.current_action.kind != 2 &&
           @active_battler.current_action.basic != 1
    #Get the active battlers id
          id = @active_battler.actor_id
    #If the bar exists and wait > 0
          if @timed_hit_bar != nil && @timed_hit_wait > 0  
           
    #Update the bar
            @timed_hit_bar.update
           
            key = -1
           
    #Test for a pressed button
            for button in @timed_hit.key_list
              if Input.trigger?(button)
                key = button
                break
              end
            end
           
    #Test for a hit
            if key > 0
              if @timed_hit_bar.hit?(key)
                @timed_hit_bar.update
                $game_system.se_play(@timed_hit.hit_sound)
              else
                $game_system.se_play(@timed_hit.miss_sound)
              end
            end
           
            @timed_hit_bar.percent = ((@max_wait - @timed_hit_wait) * 100) / @max_wait
           
            @timed_hit_wait -= @timed_hit_wait_increment
           
            return
    #If there is no bar      
          elsif @timed_hit_bar == nil
            if @active_battler.current_action.kind == 0
              if @timed_hit.actor_attack_data(id) != nil && @timed_hit.actor_data(id) != nil
                r_id = rand(@timed_hit.actor_data(id).size)
                data = @timed_hit.actor_attack_data(@timed_hit.actor_data(id)[r_id])
                timed_hit_make_bar(data)
                return
              end
            elsif @active_battler.current_action.kind == 1
              if @timed_hit.skill_data(@active_battler.current_action.skill_id) != nil
                timed_hit_make_bar(@timed_hit.skill_data(@active_battler.current_action.skill_id))
                return
              end
            end
          end
        end
       
        if @active_battler.is_a?(Game_Actor)
          if @timed_hit_bar != nil
            damage_percent = @timed_hit_bar.damage_percent
          end
           
          if @active_battler.current_action.kind == 0 &&
             @active_battler.current_action.basic != 1
           
            for target in @target_battlers
              if @timed_hit_bar != nil
                target.timed_hit_hit_percent = damage_percent + 1
                if @timed_hit.weapon_states(@active_battler.weapon_id) != nil
                  if damage_percent > @timed_hit.weapon_states(@active_battler.weapon_id)[1]
                    target.timed_hit_state_to_add = @timed_hit.weapon_states(@active_battler.weapon_id)[0]
                  end
                end
                target.timed_hit_use_percent = true
                target.attack_effect(@active_battler)
              else
                target.timed_hit_hit_percent = 100
                target.timed_hit_use_percent = true
                target.attack_effect(@active_battler)
              end
            end
          elsif @active_battler.current_action.kind == 1
            for target in @target_battlers
              if @timed_hit_bar != nil
                target.timed_hit_hit_percent = damage_percent + 1
                target.timed_hit_use_percent = true
                target.skill_effect(@active_battler, @skill)
              else
                target.timed_hit_hit_percent = 100            
                target.timed_hit_use_percent = true
                target.skill_effect(@active_battler, @skill)
              end
            end
          end
        end
       
        if @active_battler.is_a?(Game_Actor)
          if @timed_hit_bar != nil
            @timed_hit_bar.dispose
            @timed_hit_bar = nil
          end
        end
       
        timed_hit_update_phase4_step3
      end
     
      def timed_hit_make_bar(data)
        @max_wait = data[0]
        @timed_hit_wait_increment = data[1]
        damage_mod = data[2]
        key = data[3]
        target = data[4]
        marker = data[5]
        bar_mode = data[6]
        @timed_hit_wait = @max_wait
        @timed_hit_bar = Spriteset_timerbar.new(@timed_hit.bar_x, @timed_hit.bar_y, damage_mod, key, target, marker, bar_mode)
        @timed_hit_bar.update
      end
    end
    Also the number 0 shows up when I fix a status ailment as though they consider it an attack.

    This is my last thread about this subject. Anyone see anything wrong with this script?
     
    Last edited: May 28, 2019
    #1
  2. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,366
    Likes Received:
    10,405
    First Language:
    English
    Primarily Uses:
    RMVXA
    @Qeo 'Scripts' is where people who have written completed scripts which they wish to share with others can post them. This is also the section for XP scripts. Could you post and clarify which engine this script is written for? It would be helpful if you edited your Profile Page to include the engine in the info under your avatar.


    I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #2
  3. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,212
    Likes Received:
    4,665
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    I'm confused. When I read the script, there's already an alias to a method that doesn't exist in the default script. I assume these code you posted is an extension of an already existing script out there, but you didn't post the original script.
     
    #3
  4. Qeo

    Qeo Veteran Veteran

    Messages:
    98
    Likes Received:
    19
    My bad, so that was the right section after all, some people were talking about VX ace scripts to me about that problem so I thought I had put it in the wrong section.... Now I have two threads in the same section that are mostly the same. Oops..

    I'm not primarily using only one RPG Maker as I'm working on two projects at once, one finishing off my old XP game and making a new VX Ace game. The problems are with the XP one.
     
    #4
  5. Qeo

    Qeo Veteran Veteran

    Messages:
    98
    Likes Received:
    19
    It's an edit of zephren's timed hit script "https://save-point.org/thread-2780.html" edited because skills in menu weren't working. I didn't it edit it myself as I'm no scripter.

    This is the old version:

    Code:
    class Game_Battler
    attr_accessor :timed_hit_hit_percent
    attr_accessor :timed_hit_use_percent
    attr_accessor :timed_hit_state_to_add
    
    alias timed_hit_attack_effect attack_effect
    def attack_effect(attacker)
    if @timed_hit_use_percent
    hp = self.hp
    
    timed_hit_attack_effect(attacker)
    
    if self.damage.is_a?(Numeric)
    self.hp = hp
    self.damage = Integer((@timed_hit_hit_percent * self.damage) / 100.0)
    self.hp -= Integer(self.damage)
    if @timed_hit_state_to_add != nil
    self.add_state(@timed_hit_state_to_add)
    end
    end
    elsif attacker.is_a?(Game_Enemy)
    timed_hit_attack_effect(attacker)
    end
    
    @timed_hit_use_percent = false
    @timed_hit_state_to_add = nil
    end
    
    alias timed_hit_skill_effect skill_effect
    def skill_effect(user, skill)
    if @timed_hit_use_percent
    hp = self.hp
    
    timed_hit_skill_effect(user, skill)
    
    if self.damage.is_a?(Numeric)
    self.hp = hp
    self.damage = Integer((@timed_hit_hit_percent * self.damage) / 100.0)
    self.hp -= Integer(self.damage)
    end
    elsif user.is_a?(Game_Enemy)
    timed_hit_skill_effect(user, skill)
    end
    
    @timed_hit_use_percent = false
    end
    end
    
    #--------------------------------------------------------------------------
    # Game_Actor
    #--------------------------------------------------------------------------
    class Game_Actor < Game_Battler
    attr_reader :actor_id
    end
    When it was edited that's when the new problems happened. Would be nice to be able to be able to use skills in menu and not have enemies hp be messed up at the same time :\
     
    #5
  6. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,212
    Likes Received:
    4,665
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    @Qeo you stated later on that you use XP, as I don't use XP, I can't help you much here. Sorry for bothering you

    P.S: You can add a tag in your thread title to be something like "[XP] Enemy HP Error" so no one would mistaken it even if you have no main engine to use.
     
    #6
  7. Qeo

    Qeo Veteran Veteran

    Messages:
    98
    Likes Received:
    19
    No apology needed I appreciate all help, thank you I'll do that
     
    #7

Share This Page