kts.SetBearTrap

Name

kts.SetBearTrap – set a bear trap in front of the current actor

Synopsis

kts.SetBearTrap(item_type)

result = kts.Can_SetBearTrap(item_type)

Description

If the actor (cxt.actor) is a knight, who is standing in the centre of a square (i.e. not currently approaching another square), and if the square one ahead of the knight is clear (i.e. contains no walking creature, nor any item on the ground), then calling kts.SetBearTrap(item_type) will remove any item that the knight is currently holding in their hands, and will place a new item of type item_type into the dungeon, at a position one square ahead of where the knight is currently standing.

Calling kts.Can_SetBearTrap(item_type) will return true if all of the above is currently possible, or false otherwise.

Return Value

kts.SetBearTrap returns nothing, and kts.Can_SetBearTrap returns a boolean as described above.

Notes

kts.SetBearTrap and kts.Can_SetBearTrap are usually used as the action and possible functions (respectively) of a Control. The item_type is usually set to the "open bear trap" ItemType, although of course mods might define other item types that behave similarly to bear traps.

Examples

An example is provided by the "bear trap" item in the standard Knights data files: see items.lua.

Observe in particular that there are two different ItemTypes defined: one for the open bear trap, and another for the closed. The closed bear trap can be carried by knights, and contains the Control which sets the trap. When the player activates that Control, the closed bear trap is removed from the knight's hands, and an open bear trap item is created instead, and placed in front of the knight. The open bear trap then contains an on_walk_over function which turns the item back into a closed bear trap again, as well as damaging the creature that walked over it.

See Also

The cxt table

kts.ItemType

kts.SetBladeTrap

kts.SetBladeTrapOld

kts.SetPoisonTrap

kts.SetPoisonTrapOld