How do I check on how an enemy died?

Enemies don’t have to be killed by the player. They could be killed by spikes. They could be killed by falling. They could be eaten by other enemies. How do I check to see if the player killed an enemy when they died? Furthermore, is there any way I could check to see if the enemy got killed in some specific freak accident like a rock falling on their head in a way that could only be caused intentionally by the player?

You could add an object variable like CauseOfDeath and every time damage is applied to the object then the variable could be set to a cause. If it was instant death like through a collision with spikes then the same could be done. Once deceased, the variable wouldn’t be able to be changed. That way if a character was shot then crushed on the same frame only the bullet would count. You would then have a variable with the most recent possible cause of death.

If you were checking for a collision with a group object then you could set the variable to the group object name.

This is a good idea, I guess. And I could always duplicate objects like sprites so that if the player managed to “accidentally” trigger a spike trap to squish an npc, I could give them a tongue-in-cheek trophy.

1 Like

However, this would be difficult to do in a top-down text adventure . . . possibly. Then again, it could be surprisingly easy. I could say that if a dog’s death was preceded by the player attempting to “smash” it, then the owner is mad at player. This is theoretical, at the moment, though.