kts.HOOK_CREATURE_SQUELCH

Name

kts.HOOK_CREATURE_SQUELCH – function called when a monster is killed or a knight takes damage

Synopsis

kts.HOOK_CREATURE_SQUELCH = function() ... end

Description

If kts.HOOK_CREATURE_SQUELCH is non-nil, then it is called as a Lua function (with no parameters) in either of the following two cases: (a) a knight takes any non-zero amount of damage; or (b) a monster takes sufficient damage to kill it.

During the function call, the cxt table will be available; for example, cxt.pos will give the position of the damaged creature.

An exception is that if the source of damage was a call to kts.Damage, and the inhibit_squelch parameter of kts.Damage was true, then kts.HOOK_CREATURE_SQUELCH is not run.

Examples

In the standard Knights data files, this hook is set to a function which plays a "squelching" sound. This means that the "squelch" sound is heard whenever a monster is killed, or a knight takes any amount of damage. (Note that a knight being poisoned does not count as "damage", and hence knights dying to poison do not trigger the squelch sound.)

The code that sets this up can be found in sounds.lua.

Note that if a knight is damaged by a bear trap, the squelch sound does not play. This is achieved by setting the inhibit_squelch parameter (the third parameter) when kts.Damage is called from the bear trap code. This can be seen in items.lua. (Note that setting the third parameter to 1 is equivalent to setting it to true, because Lua treats any non-zero, non-false value as being equivalent to true.)

Other modules could replace kts.HOOK_CREATURE_SQUELCH (or any of the other "hook" functions) with their own code if desired.

See Also

kts.HOOK_KNIGHT_DAMAGE