Frank Sym Posted November 4, 2017 Share Posted November 4, 2017 I am trying to build an armor that when its owner gets hit, the armor will enable the character to regenerate health 2 points per second for the next 10 seconds. So I write the following code: local function OnTakeDamage(attacked, data) local attacker = data.attacker if attacker ~= nil then local target = attacker.components.combat.target if target and target:IsValid() and target.components.health and target.components.health.currenthealth > 0 then for i = 1, 10 do target:DoTaskInTime(1.0, function() target.components.health:DoDelta(2.0) end) end end end end local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_body", "armor_wood", "swap_body") inst:ListenForEvent("attacked", OnTakeDamage, owner) end local function OnUnequip(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body") inst:RemoveEventCallback("attacked", OnTakeDamage, owner) end However, when the character is attacked while wearing this armor, the health regeneration starts 1 second later than the attack and increase 10 times of 2 points all at once instead of 2 points per second over 10 seconds. So I would like to know which part goes wrong? Is there anyone who have encountered similar problem? Thank you very much if you can help me with this! Link to comment Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!Register a new account
Already have an account? Sign in here.Sign In Now