kts.GiveItem – give one or more items to a knight
kts.GiveItem(knight, itemtype)
kts.GiveItem(knight, itemtype, number)
The first parameter (knight) must be a Creature representing a knight, and the second parameter (itemtype) must be an ItemType. The third parameter (number) is optional; if present it must be a non-negative integer, but if absent it defaults to 1.
The effect of the function is as follows:
itemtype is a backpack item, then number copies of that item type are added to the knight's backpack. itemtype is a held-in-hand item (like a hammer or staff), then a new copy of that item is created, and given to the knight as their current held item. kts.DEFAULT_ITEM, usually the sword). If they are carrying something else then kts.GiveItem will have no effect; the knight must drop the other item first. number must be equal to 1 (or omitted) – knights can't carry more than one item in hand at a time. No value is returned.
Errors may result if the input parameters are invalid.
This function is used in the Knights Tutorial to create a custom "stuff bag" item. When the bag is picked up, kts.GiveItem is called three times to give various items to the knight. See tutorial/init.lua.
The function is also used as part of the Staff Pile tile, to give a staff when the player selects "Take Staff". See tiles.lua.