Make a monster ract to being damaged?

I’m halfway through making a moster whose gimmick is teleporting randomly and frequently. I would want for this same ability to have a higher chance to trigger after the monster has taken damage.

Problem is that Im not entirely sure about the proper wat to do that.

I was thinking to add a new monster exclusive effect “efffect_monster_was_hit” and then make void monster::apply_damage() add the effect everytime a monster is damaged. Maybe limit the aplication of said effect if the monster has a certain flag.

Then make the monattack check if the monster has said effect and up the chances to teleport based on it.

Is this a decent way of implementing this behavior?

The effect doesn’t need to be monster exclusive - could be just “took_damage” (not “was_hit”, because not all damage comes from hits).
But yes, the idea for implementation from the code side sounds good.
Not so sure about the whole teleportation part, though.

There is an on_hurt function in player class:

/** Handles effects that happen when the player is damaged and aware of the fact. */
void on_hurt( Creature *source, bool disturb = true );

Thanks!

I’ll go forth with it then.