Author Topic: Monster Proposal  (Read 1021 times)

Stephen

  • Administrator
  • Hero Member
  • *****
  • Posts: 240
Monster Proposal
« on: October 20, 2012, 01:03:37 PM »
ImpassIve made a comment in another thread about wanting a CREATURE_DEATH hook. I have also wanted some more flexible monster hooks in the past.

I propose we add the following fields to the "MonsterType" table:

* on_attack -- this is called when the monster makes an attack / swings its weapon
* on_damage -- this is called when the monster receives non-fatal damage
* on_death -- this is called when the monster is killed

(These are a bit like HOOK_CREATURE_SQUELCH etc, but there is one for each monster type instead of one "global" hook. I think this is better than using hooks :) )

Romanio(Rus)

  • Jr. Member
  • **
  • Posts: 13
  • FOR MOTHER RUSSIA!
Re: Monster Proposal
« Reply #1 on: October 23, 2012, 11:36:39 AM »
Fully support this initiative, as it will give much more space to write mods =)

Stephen

  • Administrator
  • Hero Member
  • *****
  • Posts: 240
Re: Monster Proposal
« Reply #2 on: December 27, 2012, 04:07:51 PM »
This is now implemented. A snapshot is available here: http://www.solarflare.org.uk/snapshots/knights_src_2012_12_27.tar.gz (source code) or http://www.solarflare.org.uk/snapshots/knights_2012_12_27.zip (Windows binary)

In addition to "on_attack", "on_damage" and "on_death", I also added "on_move" which is called whenever the monster moves to a new square.

I also removed the "sound" property because monster sounds can now be implemented using a combination of on_attack, on_damage, on_death and on_move, as required. For example, zombies make a sound whenever on_attack, on_damage, on_death are called, and also 5% of the time when on_move is called. Bats only make their "screeching" sound when on_damage is called.

ImpassIve_rus

  • Sr. Member
  • ****
  • Posts: 71
  • 0_o
Re: Monster Proposal
« Reply #3 on: December 27, 2012, 05:20:42 PM »
Nice news, hehe)
Will try it later

P.S. I just have installed a new router (because from today I have a VDSL connection instead of ADSL) but I have problems with playing some games in online (including Knights)
I hope I will fix this until Sunday... -_-


Moo

  • Sr. Member
  • ****
  • Posts: 62
Re: Monster Proposal
« Reply #4 on: August 19, 2014, 03:06:27 PM »
I was playing with these...

Currently they give a userdata in cxt.actor and a "monster" in cxt.originator. I presume these are both the thing that was killed/damaged? Neither of those seem to be much use on their own, so I guess to be able to determine what kind of monster, there would need to be something similar to kts.IsKnight added to return the monster type?

It seems like there's no way to get the killer/damage-causer?
on_damage isn't called when fatal damage is done, so that couldn't be used to determine killer either.

on_death and on_damage seem to get called for bats, but not zombies. I didn't try custom monsters.

Stephen

  • Administrator
  • Hero Member
  • *****
  • Posts: 240
Re: Monster Proposal
« Reply #5 on: August 21, 2014, 04:50:05 PM »
I suppose this is what happens when you make an API up as you go along...

  • From my reading of the source code, it seems that actor/originator refer to the thing that is being damaged. IMO this is wrong, "actor" should be the thing causing the damage, and "victim" should be the thing being damaged. (That is why I added the "victim" field in the first place... it refers to the thing that is the "target" of an action, as opposed to the thing carrying out the action.)
  • You are right, there ought to be a "kts.GetMonsterType" function that takes a creature and returns a monster-type (or nil if it is not a monster).
  • I have no idea why the on_death and on_damage functions don't work for zombies. They should do. I'll look into it when I have a chance.