jstwinkles Posted February 8, 2021 Share Posted February 8, 2021 (edited) Hey folks, beginner scripter/modder in need of some help. I've got this mod that uses an OnDeath event handler to move a merchant's inventory from their vendor container to their corpse when they die. Everything works great except when it comes to ammo boxes. Basically, duplicates of the boxes are getting created during the transfer, and if I loot said boxes they won't get converted to ammo in my inventory, like the OnAdd block isn't getting executed. Is there anything about the RemoveAllItems function that could be doing this? I even tried changing it to iterate over each item individually and moving it using foreach and RemoveMeIR, but the results were the same. Any help is very much appreciated! Full sequence to reproduce the issue and script source below. Find a merchant with ammo boxes in their buy menu. Let's say there are 5 .223 boxes. Kill the merchant -> OnDeath event handler gets called Some checks are done and RemoveAllItems is called to move the inventory to their corpse Their corpse will mysteriously have 9 .223 boxes rather than the original 5 (note that a debug print in the transfer script correctly reported 5, not 9) Taking the first 3 boxes does nothing. No ammo gets added to the player inventory. Taking the 4th box suddenly triggers all 4 boxes to be converted to ammo. Taking the remaining 5 boxes after that works correctly, converting them to ammo.Quest Script: scriptName KMGLQuestScript begin gameMode if getGameRestarted ; TODO: See if there's a way to filter on merchants here setEventHandler "OnDeath" KMGLOnDeathFunction endif end OnDeath Event Handler: scriptName KMGLOnDeathFunction ref containerRef ref killed ref killer begin function { killed, killer } ; Make sure we're not operating on the player if (killed.GetIsReference player == 0) ; Try to get the merchant container reference let containerRef := killed.GetMerchantContainer ; Only proceed if we actually got something if (isFormValid containerRef) if (isReference containerRef) ; Move all items from the vendor's container to the vendor containerRef.removeAllItems killed 1 1 ; Print some debug ; messageEx "%n killed %n" killer killed ; messageEx "Transferred from %n to %n" containerRef killed endif endif endif end Edited February 8, 2021 by jstwinkles Link to comment Share on other sites More sharing options...
ashtonlp101 Posted February 8, 2021 Share Posted February 8, 2021 (edited) Could you remove the white highlighting please? I'm having trouble reading some of the lighter colored text. Also, what do you mean by ammo boxes? Do you mean the surplus ammo you can buy under the misc tab? If you're talking about surplus ammo that is a bug in game where sometimes surplus ammo doesn't convert into actual ammunition. That's on Obsidian, not you. Edited February 8, 2021 by ashtonlp101 Link to comment Share on other sites More sharing options...
jstwinkles Posted February 8, 2021 Author Share Posted February 8, 2021 Sorry, not sure what caused the weird highlighting. I think it's fixed now. Do you mean the surplus ammo you can buy under the misc tab? Yes, that's what I'm referring to. Does the Obsidian bug also cause the duplicate boxes like I described above? And do you know of a bugfix mod I could try to rule that out, or is it something baked into the engine that a mod can't fix? Link to comment Share on other sites More sharing options...
ashtonlp101 Posted February 8, 2021 Share Posted February 8, 2021 I think it has something to do with the OnAdd function. It only seems to work 100% effectively if you pick something up off the ground. If you loot it from someone's inventory or buy it through a barter menu, I've noticed surplus ammo sometimes does not turn into actual ammo. So I wouldn't worry about it. As for your script, nothing at least to my attention is showing any red flags. I think this may have something to do with the glitchiness of the ammo boxes, not you. Link to comment Share on other sites More sharing options...
jstwinkles Posted February 8, 2021 Author Share Posted February 8, 2021 Good to know, thanks for the feedback! Link to comment Share on other sites More sharing options...
Recommended Posts