Enemy HP error

The enemies HP are drastically lower than they should be in battle. This only happens with this script, but I still want to keep the script. How should I edit it so that this glitch doesn't occur?

Spoiler: Script
#==============================================================================
# ** 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)
self.hp -= Integer(self.damage)
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 = Integer((@timed_hit_hit_percent * self.damage) / 100.0)
self.hp -= Integer(self.damage)
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
@Qeo You say it only happens with this script. What is the enemy HP without the script and how does that change when the script runs?
@Qeo You say it only happens with this script. What is the enemy HP without the script and how does that change when the script runs?

Enemy HP without the script just works as you'd expect, an enemy with 10,000 HP has 10,000 HP. With it, an enemy with 10 thousand hp died at a little over 5000. So it seemed like enemies health were reduced by half, then I fight something with 80,000 health and it dies in less than 40,000.
@Qeo It looks like the script is doing double duty. If an enemy is being dealt normal damage noted by the engine and then your script also subtracts the damage from the enemy, they will effectively have half hit points because they are taking damage twice, once from the source code and once again from your script. What happens if you just take out the self.hp -= Integer(self.damage) lines from the code?
@Qeo It looks like the script is doing double duty. If an enemy is being dealt normal damage noted by the engine and then your script also subtracts the damage from the enemy, they will effectively have half hit points because they are taking damage twice, once from the source code and once again from your script. What happens if you just take out the self.hp -= Integer(self.damage) lines from the code?

This seems to have fixed the problem entirely. Thank you!
@Qeo You're welcome. 🙂 Happy to have helped.

Original thread: https://forums.rpgmakerweb.com/threads/enemy-hp-error.109124/