Hey, I'm wondering if it's feasible? For example, if and when PC opens/closes his magic bag, catch the event and react accordingly in handler. Any idea?
Thanks
Kato
Depends. There is a way to do this, but it's pretty cpu-intensive, so I wouldn't recommend this for a PW. Proleric is correct about there being no custom-fit event for this - with or without nwnx, so far as I have seen. You can, however, always resort to the fallback, the heartbeat event. If you want to go more than every 6 seconds to more closely align the event with the addition/removal from the container, you could use a psuedo, but then you would really be slamming your module with extra load.
So, how to do this? Well, you can detect if a given item is in a container, using these two functions (which include CEP container item types, as well):
int GetItemIsContainer (object oItem) {
switch (GetBaseItemType(oItem)) {
case 23:
case 67:
case BASE_ITEM_CEP_THINBOX:
case BASE_ITEM_CEP_SMALLBOX:
case BASE_ITEM_LARGEBOX:
return TRUE;
}
return FALSE;
}
object GetContainerOfItem (object oItem) {
object oPossessor = GetItemPossessor(oItem);
if (!GetIsObjectValid(oPossessor))
return OBJECT_INVALID;
object oContents, oCheck;
object oContainer = GetFirstItemInInventory(oPossessor);
while (GetIsObjectValid(oContainer)) {
if (GetItemIsContainer(oContainer)) {
oCheck = GetFirstItemInInventory(oContainer);
while (GetIsObjectValid(oCheck)) {
if (oCheck == oItem)
return oContainer;
oCheck = GetNextItemInInventory(oContainer);
}
}
oContainer = GetNextItemInInventory(oPossessor);
}
return OBJECT_INVALID;
}
From there, it's just a question of tracking object ids of the pcs items' containers (if any), storing them (I would probably recommend a hash with nwnx, if you have it), and checking to see if they have changed each heartbeat. If so, if the item's container has changed (to a new container, or none), you can fire the appropriate 'event' code.
We don't use these functions for this purpose on HG, but they still come in handy for people who try to exploit 'binding items' that attach to a pc, becoming undroppable, by 'binding them' while they are in a container, like so:
if (GetIsObjectValid(GetContainerOfItem(oItem))) {
FloatingTextStringOnCreature("<cþ >Your unlimited ammunition container cannot be used in a container.</c>", oPC, FALSE);
return;
}
Funky