SetPickpocketableFlag doesn't work?

On custom items created in npc inventory? SetDroppableFlag works fine but SetPickpocketableFlag isn’t. on a successful pickpocket; just getting “target has no valuables or gold.” Any ideas? Thanks as always in advance!

Can you post the full code where you’re encountering this problem? It might be a game bug that causes that strange behaviour. items, that are already stored in the NPC’s inventory, just don’t get updated. In this case set Pickpocketable flag with SetPickpocketableFlag(), copy that item with CopyItem() and than destroy the original item with DestroyObject(). See if it helps.

1 Like

Thanks Aqvilinus for your quick reply. The npc’s inventory is empty. Here is what I have so far:
//other stuff
object oitem=GetObjectByTag(“customitem”);
case 1:
CreateItemOnObject(“customitem”,onpc);
SetPickpocketableFlag(oitem,TRUE);
break;

1 Like

There’s an error in your code. Here are corrections:

object oitem;
case 1:
oitem = CreateItemOnObject(“customitem”,onpc);
SetPickpocketableFlag(oitem,TRUE);
break;

The object stored in oItem is not the same object you’ve created. Moreover, GetObjectByTag() skips items in the inventories. To find a specific item in the inventory of the given creature you have too loop through all the items in that inventory using GetFirstItemInInventory() and GetNextItemInInventory().
Well, I guess someone else could explain it better. I’m not sure my english is good enough for that.
In addition, CreateItemOnObject() requires ResRef of the item as its argument, not Tag. Do they coincide in your case?

* Casts a spell to summon @TheBarbarian *

1 Like

ResRef and tag are the same, if it matters, I’m creating 2 custom items on a random npc. oitem is droppable, the other, litem, is pickpocketable.

1 Like

Then try my corrected version. It should work for what you want.

Something like that:

object oItem;
case 1:
oItem = CreateItemOnObject(“customitem1”, oNPC);
SetPickpocketableFlag(oItem, TRUE);
oItem = CreateItemOnObject(“customitem2”, oNPC);
SetDroppableFlag(oItem, TRUE);
break;
1 Like

Can’t thank you enough Aqvilinus! You just put the cherry on a very complicated,but challenging puzzle script! Many, Many thanks to you! Curious tho’ how come my deceleration of object litem=(GetObjectByTag" "); didn’t work inside the case: break;?

1 Like

because code runs sequentially (at least in NwScript, since it doesn’t do multi-threading) – line after line, statement after statement, etc.

in your original:

object oitem = GetObjectByTag(“customitem”);
CreateItemOnObject(“customitem”,onpc);
SetPickpocketableFlag(oitem,TRUE);

that tried to define ‘oitem’ before it was even created … so when the script got to SetPickpocketableFlag(), ‘oitem’ was simply invalid (unless there was already an object w/ tag “customitem” somewhere, in which case the script would create a second one, and the first’d be flagged pickpocketable)

this could also work:

CreateItemOnObject(“uniquetag”,onpc);
object oitem = GetObjectByTag(“uniquetag”);
SetPickpocketableFlag(oitem,TRUE);

but it’s not as efficient as using the return (the item itself) from CreateItemOnObject. Hence Aqvi’s solution:

object oitem = CreateItemOnObject(“customitem”,onpc);
SetPickpocketableFlag(oitem,TRUE);

 
Note that by using the return from CreateItemOnObject() … the item is uniquely referenced even if there are other objects w/ the same tag in the module.

1 Like

Thanks kevL_s for the explanation. I love this vault because of posters like you who actually care to respond even if the topical question was resolved only to help mod builders with a better understanding of why scripts fire correctly or why a script won’t. Neverwinter Vault the better, because of you and Aqvilinus and others who help resolve mod builders questions. Love this site!

4 Likes

bump just testing