item-trigger update: specify inventory mode#49
item-trigger update: specify inventory mode#49lethosor merged 2 commits intoDFHack:masterfrom AtomicChicken:item-trigger-update
Conversation
Previously, item-trigger's inventory update checks only differentiated between equipping and unequipping items. This means that something like modtools/item-trigger -itemType ITEM_HELM_CAP -onEquip -command [ foo ] would trigger foo both in cases where a cap was being worn, and in cases where it was simply being held in the unit’s hand. With this update, the user will now be able to specify the inventory mode alongside onEquip and onUnequip to allow for greater selectivity. Taking the above example, if we wanted to trigger foo only in cases were a cap was being worn, we could specify this via modtools/item-trigger -itemType ITEM_HELM_CAP -onEquip 2 -command [ foo ] or modtools/item-trigger -itemType ITEM_HELM_CAP -onEquip [ 2 ] -command [ foo ] where ‘2’ is the mode type corresponding to ‘Worn’. Multiple inventory mode can be specified. For example, modtools/item-trigger -itemType RING -onUnequip [ 0 1 2 ] -command [ foo ] would trigger foo when a ring in unequipped in cases were it was being hauled, held or worn. A list of inventory mode values has been included in the -help printout. Specifying mode remains optional, preserving backwards compatibility.
modtools/item-trigger.lua
Outdated
| utils.fillTable(command,table) | ||
| processTrigger(command) | ||
| utils.unfillTable(command,table) | ||
| end |
There was a problem hiding this comment.
Huh, now how did that get in there?
modtools/item-trigger.lua
Outdated
| -onUnequip | ||
| Optionally, the equipment mode can be specified | ||
| Possible values for mode: | ||
| 0 = Hauled |
There was a problem hiding this comment.
Is this a DF enum? If so, you should use human-readable names instead of making people look up numbers every time they want to want to read/write a command.
There was a problem hiding this comment.
On second glance, it looks like you just documented this. Not a big deal, then, but it would be nice to be able to use enum values (if this is in fact an enum).
There was a problem hiding this comment.
Noted. I suppose it'd cause far less hassle to everyone involved.
modtools/item-trigger.lua
Outdated
| table.item = df.item.find(item) | ||
| table.unit = df.unit.find(unit) | ||
| if table.item and table.unit then -- they must both be not nil or errors will occur after this point with instant reactions. | ||
| if table.item and table.unit then--they must both be not nil or errors will occur after this point with instant reactions. |
There was a problem hiding this comment.
Spaces around comments make them more readable. No need to remove them.
There was a problem hiding this comment.
My bad, not sure why I did that.
… + other minor corrections as per lethosor's feedback
Previously, item-trigger's inventory update checks only differentiated between equipping and unequipping items. This means that something like
modtools/item-trigger -itemType ITEM_HELM_CAP -onEquip -command [ foo ]
would trigger foo both in cases where a cap was being worn, and in cases where it was simply being held in the unit’s hand.
With this update, the user will now be able to specify the inventory mode alongside onEquip and onUnequip to allow for greater selectivity. Taking the above example, if we wanted to trigger foo only in cases where a cap was being worn, we could specify this via
modtools/item-trigger -itemType ITEM_HELM_CAP -onEquip 2 -command [ foo ]
or
modtools/item-trigger -itemType ITEM_HELM_CAP -onEquip [ 2 ] -command [ foo ]
where ‘2’ is the mode type corresponding to ‘Worn’.
Multiple inventory modes can be specified. For example,
modtools/item-trigger -itemType RING -onUnequip [ 0 1 2 ] -command [ foo ]
would trigger foo when a ring is unequipped in cases where it was being hauled, held or worn.
A list of inventory mode values has been included in the -help printout.
Specifying mode remains optional, preserving backwards compatibility.