# Make a monster ract to being damaged?

**URL:** https://discourse.cataclysmdda.org/t/make-a-monster-ract-to-being-damaged/13818
**Category:** The Toolbox
**Created:** [June 2, 2017, 12:26am UTC](https://discourse.cataclysmdda.org/t/make-a-monster-ract-to-being-damaged/13818 "2017-06-02T00:26:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)
#### Post date: [June 2, 2017, 12:26am UTC](https://discourse.cataclysmdda.org/t/make-a-monster-ract-to-being-damaged/13818/1 "2017-06-02T00:26:25Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)
#### Post date: [June 2, 2017, 4:02am UTC](https://discourse.cataclysmdda.org/t/make-a-monster-ract-to-being-damaged/13818/2 "2017-06-02T04:02:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)
#### Post date: [June 2, 2017, 7:13am UTC](https://discourse.cataclysmdda.org/t/make-a-monster-ract-to-being-damaged/13818/3 "2017-06-02T07:13:47Z")

</div>

There is an on\_hurt function in player class:

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

---

<div class="post-metadata">

### Author: ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)
#### Post date: [June 2, 2017, 10:22pm UTC](https://discourse.cataclysmdda.org/t/make-a-monster-ract-to-being-damaged/13818/4 "2017-06-02T22:22:51Z")

</div>

Thanks!

I’ll go forth with it then.
