I made some parchement item that trigger a lua script on destroy.
However I dont’ understand why it’s triggered both when the character pick up the item and when it’s destroyed (when parchment is used).
The Lua script is only in the entry “ondestroy”.
Is it a bug ?
Probably not intended in this way but from theory, when you pick up an item from the ground, the game does not need to hold it’s worldobject anymore and therefore destroys it = triggers ondestroy.
(having an item in the inventory is from a promatical point way different than having one laying on the ground so this is why these are two different objects)
You may want to work around it by giving the parchment directly into your character’s inventory or using an item that executes a summon skill that will summon an invisible pet for 0.1 sec duration and execute your script as “ondeath” or “onaddtoworld”.
Thanks Elfe, well hopefully for me even if the script is executed on pick up that’s not an issue for my mod but it feels awkward as I made a UI notification that is supposed to only trigger when the item is used.I have a hundred of this item, each triggering a different script event so I think I will keep it as it is for now.
The item is given when the character craft it to the blacksmith and it’s script is triggred at this moment (item never touches the ground) but I intended it to be triggered only when destroyed.