kts.GetNumHeld – count how many items of a particular type a creature is carrying
result = kts.GetNumHeld(creature, item_type)
Given a Creature and an ItemType, returns the number of copies of the ItemType that the Creature is currently holding.
A number (non-negative integer) is returned.
If the inputs are invalid, then an error will be generated.
The following could be used to detect whether the current actor is carrying any gems. (It is assumed that this code is being called from within an action function of some sort, for example on_walk_over
in a Tile, and also, that the ItemType i_gem
is defined somewhere.)
if kts.GetNumHeld(cxt.actor, i_gem) > 0 then -- Do something... end