Jump to content

Event "killed" can fire multiple times


CarlZalph
  • Pending

Something I saw while creating a boomerang juggler.

If something hits a dying/dead entity, such as a rabbit, then it will repeatedly fire off the "killed" event since its health threshold is dead.

 

It can be watched easily by using multiple boomerangs against one rabbit in that it will "die" several times, and Krampus will count it as such.

This can be done to incur huge naughtiness levels by weakening a high valued target, such as a catcoon, and then flinging multiple boomargs at it quickly to finish it off and then get counted multiple times.

 

The fault lies within the combat component:

            self.inst.components.health:DoDelta(-damage, nil, cause ~= nil and (cause.nameoverride or cause.prefab) or "NIL", nil, cause)
            if self.inst.components.health:IsDead() then
                if attacker ~= nil then
                    attacker:PushEvent("killed", { victim = self.inst })
                end
                if self.onkilledbyother ~= nil then
                    self.onkilledbyother(self.inst, attacker)
                end
            end

Hotfixed by first checking that the thing isn't dead before applying the delta:

            if not self.inst.components.health:IsDead() then
                self.inst.components.health:DoDelta(-damage, nil, cause ~= nil and (cause.nameoverride or cause.prefab) or "NIL", nil, cause)
                if self.inst.components.health:IsDead() then
                    if attacker ~= nil then
                        attacker:PushEvent("killed", { victim = self.inst })
                    end
                    if self.onkilledbyother ~= nil then
                        self.onkilledbyother(self.inst, attacker)
                    end
                end
            end

 

I don't think that anyone would need the DoDelta to fire when a dead thing takes more damage.

Seeming as a few lines above is checks for only if the damage is positive (to do negative health) and the dead can't die more.


Steps to Reproduce
Using several boomerangs to delay attacks over time, throw multiple boomerangs at one rabbit and watch the "killed" event fire multiple times.



User Feedback


There are no comments to display.



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

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...