Author Topic: Make a monster ract to being damaged?  (Read 250 times)

Offline John Candlebury

  • Contributor
  • Survivor
  • ****
  • Posts: 3214
    • View Profile
    • My deviantart
Make a monster ract to being damaged?
« on: June 02, 2017, 01:26:25 AM »
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?

Offline Coolthulhu

  • Contributor
  • Survivor
  • ****
  • Posts: 3729
    • View Profile
Re: Make a monster ract to being damaged?
« Reply #1 on: June 02, 2017, 05:02:13 AM »
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.

Offline Zhilkin

  • NPC
  • **
  • Posts: 134
    • View Profile
Re: Make a monster ract to being damaged?
« Reply #2 on: June 02, 2017, 08:13:47 AM »
There is an on_hurt function in player class:

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

Offline John Candlebury

  • Contributor
  • Survivor
  • ****
  • Posts: 3214
    • View Profile
    • My deviantart
Re: Make a monster ract to being damaged?
« Reply #3 on: June 02, 2017, 11:22:51 PM »
Thanks!

I'll go forth with it then.