jtull1127 Posted October 3, 2023 Share Posted October 3, 2023 Hello nexus I've been working on a salvage/breakdown item script based on item type and keywords for a mod I am making and I have the first half of it done and working.however because most misc items lack keywords I used form lists to sort them, the problem is my script it just a bunch of if statements and while it works it is kind of slow and laggy and I am worried since I still have to add the weapon and armor breakdown section using keywords. if there is someone with some knowledge of papyrus that could take a look at my script give me any advice on how to improve it I would greatly appreciate it Scriptname sh_recycler_script extends ObjectReferenceFormlist Property Woodlist AutoFormlist Property Glasslist AutoFormlist Property Strawlist AutoFormlist Property Steellist AutoFormlist Property Paperlist AutoFormlist Property Silverlist AutoFormlist Property Ironlist AutoFormlist Property Goldlist AutoFormlist Property Hidelist AutoFormlist Property Bonelist AutoFormlist Property Claylist AutoFormlist Property Featherlist AutoFormlist Property Dwarvenlist AutoObjectReference property OutputChest autoKeyword property VendorItemClothing autoMiscObject Property Cloth autoMiscObject Property paper autoMiscObject Property Glass autoMiscObject Property Wood autoMiscObject Property Straw autoMiscObject Property Hide autoMiscObject Property Clay autoingredient property bone Autoingredient property Feathers AutoMiscObject Property Steelp autoMiscObject Property Ironp autoMiscObject Property Goldp autoMiscObject Property Silvep autoMiscObject Property Dwarvenp auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) int MyType = (akBaseItem).GetType()If akBaseItem.HasKeyword (VendorItemClothing)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (cloth, aiItemcount)endifIf Mytype ==27self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Paper, aiItemcount)endif IfMytype ==23self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Paper, aiItemcount)endif if Glasslist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Glass, aiItemcount)endifif Woodlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Wood, aiItemcount)endifif Strawlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Straw, aiItemcount)endifif Steellist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Steelp, aiItemcount)endifif Paperlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Paper, aiItemcount)endifif Silverlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Silvep, aiItemcount)endifif Ironlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Ironp, aiItemcount)endifif Goldlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Goldp, 3 * aiItemcount)endifif Hidelist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Hide, aiItemcount)endifif Bonelist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Bone, aiItemcount)endifif Featherlist.HasForm(akBaseItem) self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (Feathers, aiItemcount) endif if Claylist.HasForm(akBaseItem) self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Clay, aiItemcount)endif ifDwarvenlist.HasForm(akBaseItem)self.RemoveItem(akBaseItem, aiItemCount, true)OutputChest.additem (Dwarvenp, aiItemcount)endifendevent Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 3, 2023 Share Posted October 3, 2023 Since your IF blocks are all at the same level, use ElseIf such that Papyrus will only proceed to the next block if a match is not found. You can also use Return to ensure that the script jumps out of the IF block and ceases to process. Example: Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) int MyType = (akBaseItem).GetType() If akBaseItem.HasKeyword (VendorItemClothing) self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (cloth, aiItemcount) Return ElseIf Mytype ==27 self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (Paper, aiItemcount) Return ElseIf Mytype ==23 self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (Paper, aiItemcount) Return ElseIf ;the rest of the stuff endif EndEvent With this setup, once an item qualifies it will process and be done, giving only one item in return. With your existing setup, if an item qualifies for more than one section, it will process all those valid sections and thus give more than one item. It depends on what you want to do as to the approach you take. It may be better to have multiple containers to handle different types of objects (i.e., one for armor, one for weapons, etc...) Link to comment Share on other sites More sharing options...
jtull1127 Posted October 3, 2023 Author Share Posted October 3, 2023 Since your IF blocks are all at the same level, use ElseIf such that Papyrus will only proceed to the next block if a match is not found. You can also use Return to ensure that the script jumps out of the IF block and ceases to process. Example: Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) int MyType = (akBaseItem).GetType() If akBaseItem.HasKeyword (VendorItemClothing) self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (cloth, aiItemcount) Return ElseIf Mytype ==27 self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (Paper, aiItemcount) Return ElseIf Mytype ==23 self.RemoveItem(akBaseItem, aiItemCount, true) OutputChest.additem (Paper, aiItemcount) Return ElseIf ;the rest of the stuff endif EndEvent With this setup, once an item qualifies it will process and be done, giving only one item in return. With your existing setup, if an item qualifies for more than one section, it will process all those valid sections and thus give more than one item. It depends on what you want to do as to the approach you take. It may be better to have multiple containers to handle different types of objects (i.e., one for armor, one for weapons, etc...)Hey Thank you for the reply, elseif worked a lot better and you are probably right about splitting it into different chests I'll see if I can do it in a way that isn't clunky Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts