GetInventoryDisturbItem
Contents |
[edit] GetInventoryDisturbItem()
Returns the disturbing item in an inventory OnDisturbed event.
[edit] Description
Description: Returns the item that caused the objectâs OnDisturbed event to fire. There are three events that will cause this event to fire â when an item is added to, taken from, or stolen from inventory.
Returns OBJECT_INVALID on error, which will never happen if this function is used exclusively in OnDisturbed events of objects with inventories. (At least in theory - check the bug list below)
[edit] Known Bugs
It has been previously noted that the event OnDisturbed does not fire when the item being disturbed is gold. Thereâs still something odd going on with that function. I made this little script and put OnDisturbed of a container:
void main()
{
object oPC=GetLastDisturbed();
object oDisturb=GetInventoryDisturbItem();
SendMessageToPC(oPC, "this: "+GetName(oDisturb));
}
When I put gold into the container, I get a message telling me âthis: Gold pieceâ. So it does fire for gold. When I take it back from the container, I get the message âthis:â
I tested it, and when removing gold from a container, GetInventoryDisturbItem() returns OBJECT_INVALID.
Also, thereâs a bug with stackable items. If a stackable item is added to another stack in either the givers or receivers inventory, the OnDisturbed event never fires (except for gold pieces, apparently).
[edit] Version
1.30
[edit] Example
// put this OnDisturbed of a container. Whenever anybody // removes an item from the container, they'll be charged // that items value for it... Lilac Soul void main() { object oItem=GetInventoryDisturbItem(); object oPC=GetLastDisturbed(); int nType=GetInventoryDisturbType(); switch (nType) { case INVENTORY_DISTURB_TYPE_REMOVED: case INVENTORY_DISTURB_TYPE_STOLEN: int nAmount=GetGoldPieceValue(oItem); AssignCommand(oPC, TakeGoldFromCreature(nAmount, oPC, TRUE)); SendMessageToPC(oPC, "Stealing is wrong. Give me your money!"); break; } }
[edit] See Also
functions: | |
events: |
author: Charles Feduke, editor: Lilac Soul, additional contributor(s): Lilac Soul