News:

SMF - Just Installed!

Main Menu

Monster Proposal

Started by Stephen, October 20, 2012, 01:03:37 PM

Previous topic - Next topic

Stephen

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)

Fully support this initiative, as it will give much more space to write mods =)

Stephen

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

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

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

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.