Jump to content

Salvage Script Optimizations


jtull1127

Recommended Posts

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 ObjectReference
Formlist Property Woodlist Auto
Formlist Property Glasslist Auto
Formlist Property Strawlist Auto
Formlist Property Steellist Auto
Formlist Property Paperlist Auto
Formlist Property Silverlist Auto
Formlist Property Ironlist Auto
Formlist Property Goldlist Auto
Formlist Property Hidelist Auto
Formlist Property Bonelist Auto
Formlist Property Claylist Auto
Formlist Property Featherlist Auto
Formlist Property Dwarvenlist Auto
ObjectReference property OutputChest auto
Keyword property VendorItemClothing auto
MiscObject Property Cloth auto
MiscObject Property paper auto
MiscObject Property Glass auto
MiscObject Property Wood auto
MiscObject Property Straw auto
MiscObject Property Hide auto
MiscObject Property Clay auto
ingredient property bone Auto
ingredient property Feathers Auto
MiscObject Property Steelp auto
MiscObject Property Ironp auto
MiscObject Property Goldp auto
MiscObject Property Silvep auto
MiscObject 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)
endif
If Mytype ==27
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Paper, aiItemcount)
endif If
Mytype ==23
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Paper, aiItemcount)
endif

if Glasslist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Glass, aiItemcount)
endif
if Woodlist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Wood, aiItemcount)
endif
if Strawlist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Straw, aiItemcount)
endif
if Steellist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Steelp, aiItemcount)
endif
if Paperlist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Paper, aiItemcount)
endif
if Silverlist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Silvep, aiItemcount)
endif
if Ironlist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Ironp, aiItemcount)
endif
if Goldlist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Goldp, 3 * aiItemcount)
endif
if Hidelist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Hide, aiItemcount)
endif
if Bonelist.HasForm(akBaseItem)
self.RemoveItem(akBaseItem, aiItemCount, true)
OutputChest.additem (Bone, aiItemcount)
endif
if 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 if

Dwarvenlist.HasForm(akBaseItem)

self.RemoveItem(akBaseItem, aiItemCount, true)

OutputChest.additem (Dwarvenp, aiItemcount)

endif

endevent

Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...