icecreamassassin Posted March 17, 2017 Share Posted March 17, 2017 So I have this script and as far as I can tell it's optimized as tightly as I can get it using conventional means and has its conditional checks set to the "most likely to fail first" setup but I'm trying to figure out if there is any way to juice this up more, perhaps with some SKSE functions I'm not familiar with. This script basically checks to see if references on various fomlists are enabled and if not checks if a player has an item on a matching list index and then goes about "displaying" the item. The issue is that there are so many lists and items on these lists that the while loop setup really slows things down and it can take up to 3 minutes to run the whole thing. I was told that there was some means of exporting the items on a formlist into an external text or xml file and that it could somehow be checked in game and would run faster? Maybe I'm just getting my lines crossed on more than one concept, but if there is a faster way than While Loops I'd love to hear it. Any help is appreciated. Scriptname DBM_PrepStationScript2 extends ObjectReference Actor Property PlayerRef AutoFormList Property DBM_ExcludeList AutoFormList Property DisplayActivators AutoFormList Property DisplayItems AutoFormList Property DBM_DaedricDisplays AutoFormList Property DBM_DaedricItems AutoFormList Property OddityDisplays AutoFormList Property OddityItems AutoFormList Property DBM_HOLEDisplays AutoFormList Property DBM_HOLEItems AutoFormList Property DBM_HOSDisplays AutoFormList Property DBM_HOSItems AutoFormList Property DBM_BCSDisplays AutoFormList Property DBM_BCSItems AutoFormList Property DBM_UTDisplays AutoFormList Property DBM_UTItems AutoFormList Property DBM_KADisplays AutoFormList Property DBM_KAItems AutoFormList Property DBM_JARDisplays AutoFormList Property DBM_JARItems AutoFormList Property DBM_AetherealDisplays AutoFormList Property DBM_AetherealItems AutoFormList Property DBM_MILDisplays AutoFormList Property DBM_MILItems AutoFormList Property DBM_FairyDisplays AutoFormList Property DBM_FairyItems AutoFormList Property DBM_MadMaskerDisplays AutoFormList Property DBM_MadMaskerItems AutoFormList Property DBM_HelgenDisplays AutoFormList Property DBM_HelgenItems AutoFormList Property DBM_GrayCowlDisplays AutoFormList Property DBM_GrayCowlItems AutoFormList Property DBM_WyrmstoothDisplays AutoFormList Property DBM_WyrmstoothItems AutoFormList Property DBM_FalskaarDisplays AutoFormList Property DBM_FalskaarItems AutoFormList Property DBM_LullDisplaysList AutoFormList Property DBM_LullItems AutoFormList Property DBM_HeadsDisplays AutoFormList Property DBM_HeadsItems AutoFormList Property UpperDisplays AutoFormList Property UpperItems AutoFormList Property GemstoneDisplays AutoFormList Property GemstoneList AutoFormList Property ShellDisplays AutoFormList Property ShellList AutoFormList Property DBM_FishDisplays AutoFormList Property DBM_FishItems AutoFormList Property DBM_IWIADisplays AutoFormList Property DBM_IWIAItems AutoFormList Property DBM_JewelryUnique AutoFormList Property DBM_MASItems AutoFormList Property DBM_MASDisplays AutoFormList Property DBM_AOBItems AutoFormList Property DBM_AOBDisplays AutoFormList Property DBM_OAPItems AutoFormList Property DBM_OAPDisplays AutoFormList Property DBM_SUGItems AutoFormList Property DBM_SUGDisplays AutoFormList Property DBM_RAItems AutoFormList Property DBM_RADisplays AutoFormList Property DBM_EDItems AutoFormList Property DBM_EDDisplays AutoFormList Property DBM_AOSCaseList AutoFormList Property DBM_ArmoryIron AutoFormList Property DBM_ArmorySteel AutoFormList Property DBM_ArmoryNordic AutoFormList Property DBM_ArmoryElven AutoFormList Property DBM_ArmoryGlass AutoFormList Property DBM_ArmoryOrcish AutoFormList Property DBM_ArmoryDwarven AutoFormList Property DBM_ArmoryStalhrim AutoFormList Property DBM_ArmoryEbony AutoFormList Property DBM_ArmoryDaedric AutoFormList Property DBM_ArmoryDragon AutoFormList Property DBM_ArmoryDawnguard AutoFormList Property DBM_ArmoryFalmer AutoFormList Property DBM_ArmoryBlades AutoFormList Property DBM_ArmoryForsworn AutoFormList Property DBM_ArmoryAncientNord AutoDBM_JewelryDisplayScript Property JewelryDisplays AutoDBM_JewelryDisplayScript Property JewelryDisplays2 AutoDBM_JewelryDisplayScript Property ScaleDisplays AutoQuest Property DBM_GuidebookHandler AutoInt IndexWeapon MArmor NInt Index2FormList ITEMLISTFormList DISPLAYLISTObjectReference Property DisplaySafe AutoObjectReference Property DisplaySafe2 AutoObjectReference Property ArmorySafe AutoObjectReference Property JewelryCase AutoObjectReference Property JewelryCase2 AutoObjectReference Property ScaleCase AutoGlobalVariable Property DBM_DisplayMAX AutoMessage Property SortMsg AutoGlobalVariable Property DBM_SortWait AutoobjectReference OForm fauto state ready Event OnActivate(ObjectReference akActionRef) if(akActionRef == PlayerRef) if DBM_SortWait.GetValue() == 1 Debug.messagebox("You must wait for the current sorting opperation to complete before removing displays") Return Elseif DBM_SortWait.GetValue() == 0 int SortBtn = SortMsg.show() if SortBtn == 0 ; Sort all display items gotostate("busy") DBM_SortWait.SetValue(1) Debug.Notification("All items being displayed, this will take a moment") ;JEWELRY SORTING ITEMLIST = DBM_JewelryUnique DISPLAYLIST = DBM_JewelryUnique SortJewelry() ;MAIN MUSEUM ITEMLIST = DisplayItems DISPLAYLIST = DisplayActivators SortGroup() ;UPPER GALLERY ITEMLIST = UpperItems DISPLAYLIST = UpperDisplays SortGroup()debug.notification("Still sorting displays") ;DAEDRIC GALLERY ITEMLIST = DBM_DaedricItems DISPLAYLIST = DBM_DaedricDisplays SortGroup() ;HALL OF LOST EMPIRES ITEMLIST = DBM_HOLEItems DISPLAYLIST = DBM_HOLEDisplays SortGroup() ;HALL OF SECRETS ITEMLIST = DBM_HOSItems DISPLAYLIST = DBM_HOSDisplays SortGroup() ;HALL OF ODDITIES ITEMLIST = OddityItems DISPLAYLIST = OddityDisplays SortGroup()debug.notification("Still sorting displays") ;LIBRARY SORTING ITEMLIST = DBM_BCSItems DISPLAYLIST = DBM_BCSDisplays SortBooks() ;----------------------------------ARMORY-------------------------------------- ArmorySafe.BlockActivation() ITEMLIST = DBM_ArmoryIron DISPLAYLIST = DBM_ArmoryIron ArmorySort() ITEMLIST = DBM_ArmorySteel DISPLAYLIST = DBM_ArmorySteel ArmorySort() ITEMLIST = DBM_ArmoryNordic DISPLAYLIST = DBM_ArmoryNordic ArmorySort() ITEMLIST = DBM_ArmoryElven DISPLAYLIST = DBM_ArmoryElven ArmorySort() ITEMLIST = DBM_ArmoryGlass DISPLAYLIST = DBM_ArmoryGlass ArmorySort() ITEMLIST = DBM_ArmoryOrcish DISPLAYLIST = DBM_ArmoryOrcish ArmorySort() ITEMLIST = DBM_ArmoryDwarven DISPLAYLIST = DBM_ArmoryDwarven ArmorySort() ITEMLIST = DBM_ArmoryStalhrim DISPLAYLIST = DBM_ArmoryStalhrim ArmorySort() ITEMLIST = DBM_ArmoryEbony DISPLAYLIST = DBM_ArmoryEbony ArmorySort() ITEMLIST = DBM_ArmoryDaedric DISPLAYLIST = DBM_ArmoryDaedric ArmorySort() ITEMLIST = DBM_ArmoryDragon DISPLAYLIST = DBM_ArmoryDragon ArmorySort() ITEMLIST = DBM_ArmoryDawnguard DISPLAYLIST = DBM_ArmoryDawnguard ArmorySort() ITEMLIST = DBM_ArmoryFalmer DISPLAYLIST = DBM_ArmoryFalmer ArmorySort() ITEMLIST = DBM_ArmoryForsworn DISPLAYLIST = DBM_ArmoryForsworn ArmorySort() ITEMLIST = DBM_ArmoryBlades DISPLAYLIST = DBM_ArmoryBlades ArmorySort() ITEMLIST = DBM_ArmoryAncientNord DISPLAYLIST = DBM_ArmoryAncientNord ArmorySort() ArmorySafe.BlockActivation(false) ;----------------------------------------------------------------------debug.notification("Still sorting displays") ;GEMSTONE DISPLAYS index = GemstoneDisplays.GetSize() ITEMLIST = Gemstonelist DISPLAYLIST = Gemstonedisplays SortGroup() ;SHELL DISPLAYS index = ShellDisplays.GetSize() ITEMLIST = ShellList DISPLAYLIST = ShellDisplays SortGroup() ;SUT COLLECTION int i = Game.GetModByName("SkyrimsUniqueTreasures.esp") if i != 255 ITEMLIST = DBM_UTItems DISPLAYLIST = DBM_UTDisplays SortGroup() Endif ;TROPHY HEADS i = Game.GetModByName("BGTrophyHeads.esp") if i != 255 ITEMLIST = DBM_HeadsItems DISPLAYLIST = DBM_HeadsDisplays SortGroup() endif ;JAR COLLECTION i = Game.GetModByName("BadGremlinsJarHunt.esp") if i != 255 ITEMLIST = DBM_JarItems DISPLAYLIST = DBM_JarDisplays SortGroup() endifdebug.notification("Still sorting displays") ;AETHERIUM COLLECTION i = Game.GetModByName("AetheriumSwordsnArmor.esp") if i != 255 ITEMLIST = DBM_AetherealItems DISPLAYLIST = DBM_AetherealDisplays SortGroup() Endif ;MORE INTERESTING LOOT index = DBM_MILDisplays.GetSize() i = Game.GetModByName("More Interesting Loot for Skyrim.esp") if i != 255 ITEMLIST = DBM_MILItems DISPLAYLIST = DBM_MILDisplays SortGroup() Endif ;CAPTURED FAIRIES index = DBM_FairyDisplays.GetSize() i = Game.GetModByName("BGTheCapturedFairies.esp") if i != 255 ITEMLIST = DBM_FairyItems DISPLAYLIST = DBM_FairyDisplays SortGroup() Endif ;MAD MASKER index = DBM_MadMaskerDisplays.GetSize() i = Game.GetModByName("TheMadMasker.esp") if i != 255 ITEMLIST = DBM_MadMaskerItems DISPLAYLIST = DBM_MadMaskerDisplays SortGroup() Endif ;FISH DISPLAYS index = DBM_FishDisplays.GetSize() i = Game.GetModByName("BGSomethingFishy.esp") if i != 255 ITEMLIST = DBM_FishItems DISPLAYLIST = DBM_FishDisplays SortGroup() Endif ;HELGEN i = Game.GetModByName("Helgen Reborn.esp") if i != 255 ITEMLIST = DBM_HelgenItems DISPLAYLIST = DBM_HelgenDisplays SortGroup() Endifdebug.notification("Still sorting displays") ;GrayCowl i = Game.GetModByName("Gray Fox Cowl.esm") if i != 255 ITEMLIST = DBM_GrayCowlItems DISPLAYLIST = DBM_GrayCowlDisplays SortGroup() Endif ;WYRMSTOOTH i = Game.GetModByName("Wyrmstooth.esp") if i != 255 ITEMLIST = DBM_WyrmstoothItems DISPLAYLIST = DBM_WyrmstoothDisplays SortGroup() Endif ;FALSKAAR i = Game.GetModByName("Falskaar.esm") if i != 255 ITEMLIST = DBM_FalskaarItems DISPLAYLIST = DBM_FalskaarDisplays SortGroup() Endif ;WHEELS OF LULL i = Game.GetModByName("WheelsOfLull.esp") if i != 255 ITEMLIST = DBM_LullItems DISPLAYLIST = DBM_LullDisplaysList SortGroup() Endif ;MOON AND STAR i = Game.GetModByName("Moonandstar_MAS.esp") if i != 255 ITEMLIST = DBM_MASItems DISPLAYLIST = DBM_MASDisplays SortGroup() Endif ;IWIA i = Game.GetModByName("Immersive Weapons.esp") int j = Game.GetModByName("Hothtrooper44_ArmorCompilation.esp") if i != 255 || j != 255 ITEMLIST = DBM_IWIAItems DISPLAYLIST = DBM_IWIADisplays SortGroup() Endif ;KA displays i = Game.GetModByName("Konahrik_Accoutrements.esp") if i != 255 ITEMLIST = DBM_KAItems DISPLAYLIST = DBM_KADisplays SortGroup() Endif ;AOB Displays i = Game.GetModByName("ArtifactsOfBoethiah.esp") if i != 255 ITEMLIST = DBM_AOBItems DISPLAYLIST = DBM_AOBDisplays SortGroup() Endif ;Oblivion artifacts Displays i = Game.GetModByName("escutcheonredwave.esp") if i != 255 ITEMLIST = DBM_OAPItems DISPLAYLIST = DBM_OAPDisplays SortGroup() Endif ;AMULETS OF SKYRIM SORTING i = Game.GetModByName("SL01AmuletsSkyrim.esp") if i != 255 ITEMLIST = DBM_AOSCaseList DISPLAYLIST = DBM_AOSCaseList SortJewelry2() Endif ;Skyrim Underground i = Game.GetModByName("akskyrimunderground.esp") if i != 255 ITEMLIST = DBM_SUGItems DISPLAYLIST = DBM_SUGDisplays SortGroup() Endif ;Royal Armory i = Game.GetModByName("PrvtIRoyalArmory.esp") if i != 255 ITEMLIST = DBM_RAItems DISPLAYLIST = DBM_RADisplays SortGroup() Endif ;ElementalDragons i = Game.GetModByName("Elemental_Dragons.esp") if i != 255 ITEMLIST = DBM_EDItems DISPLAYLIST = DBM_EDDisplays SortScales() Endif Debug.Messagebox("All items displayed") DBM_GuidebookHandler.SetStage(10) if DBM_Utils.getSharingEnabled() SendModEvent("DBM_Message","DoFullScan") Endif DBM_SortWait.SetValue(0) gotostate("ready") elseif SortBtn == 1 ; Exit Return endif Endif Endif EndEventendstatestate busy event OnActivate(ObjectReference akActionRef) if (akActionRef == PlayerRef) Debug.messagebox("You must wait for the current sorting opperation to complete before starting another") endif endEventendStateFunction SortGroup() index = DISPLAYLIST.GetSize() While index index -= 1 F = ITEMLIST.GetAt(index) as form O = DISPLAYLIST.GetAt(index) as ObjectReference if O.IsDisabled() && DISPLAYSAFE.GetItemCount(F) == 0 && (PlayerRef.GetItemCount(F)) && PlayerRef.IsEquipped(F) == 0 && Game.IsObjectFavorited(F) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(F, 1, true, DisplaySafe) DBM_DisplayMax.Value += 1 O.Enable() endif EndWhile O = noneEndFunctionFunction SortBooks() index = DISPLAYLIST.GetSize() While index index -= 1 F = ITEMLIST.GetAt(index) as form O = DISPLAYLIST.GetAt(index) as ObjectReference if(O.IsDisabled() && DISPLAYSAFE2.GetItemCount(F) == 0 && PlayerRef.GetItemCount(F)) && PlayerRef.IsEquipped(F) == 0 && Game.IsObjectFavorited(F) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(F, 1, true, DisplaySafe2) DBM_DisplayMax.Value += 1 O.Enable() endif EndWhile O = noneEndFunctionFunction SortJewelry() index = ITEMLIST.GetSize() While index index -= 1 N = ITEMLIST.GetAt(index) as Armor if N as armor if JewelryCase.GetItemCount(N) == 0 &&(PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, JewelryCase) endif Else FormList Sublist = ITEMLIST.GetAt(index) as FormList Index2 = Sublist.GetSize() While Index2 index2 -= 1 N = Sublist.GetAt(index2) as Armor if JewelryCase.GetItemCount(N) == 0 &&(PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, JewelryCase) endif Endwhile Endif EndWhile JewelryDisplays.ResetDisplay() JewelryDisplays.UpdateDisplay()EndFunctionFunction SortJewelry2() index = ITEMLIST.GetSize() While index index -= 1 N = ITEMLIST.GetAt(index) as Armor if N as armor if JewelryCase.GetItemCount(N) == 0 &&(PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, JewelryCase2) endif Else FormList Sublist = ITEMLIST.GetAt(index) as FormList Index2 = Sublist.GetSize() While Index2 index2 -= 1 N = Sublist.GetAt(index2) as Armor if JewelryCase.GetItemCount(N) == 0 && (PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, JewelryCase2) endif Endwhile Endif EndWhile JewelryDisplays2.ResetDisplay() JewelryDisplays2.UpdateDisplay()EndFunctionFunction SortScales() index = ITEMLIST.GetSize() While index index -= 1 N = ITEMLIST.GetAt(index) as Armor if N as armor if ScaleCase.GetItemCount(N) == 0 && (PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, ScaleCase) endif Else FormList Sublist = ITEMLIST.GetAt(index) as FormList Index2 = Sublist.GetSize() While Index2 index2 -= 1 N = Sublist.GetAt(index2) as Armor if ScaleCase.GetItemCount(N) == 0 && (PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, ScaleCase) endif Endwhile Endif EndWhile ScaleDisplays.ResetDisplay() ScaleDisplays.UpdateDisplay()EndFunctionFunction ArmorySort() index = DISPLAYLIST.GetSize() While index Index -= 1 O = DisplayList.GetAt(index) as Objectreference if O.GetBaseObject() as Weapon M = O.GetBaseObject() as Weapon if ArmorySafe.GetItemCount(M) == 0 &&(PlayerRef.GetItemCount(M)) && PlayerRef.IsEquipped(M) == 0 && O.IsDisabled() && Game.IsObjectFavorited(M) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(M, 1, true, ArmorySafe) DBM_DisplayMax.Value += 1 O.Enable() Endif Elseif O.GetBaseObject() as Armor N = O.GetBaseObject() as Armor if ArmorySafe.GetItemCount(N) == 0 &&(PlayerRef.GetItemCount(N)) && PlayerRef.IsEquipped(N) == 0 && O.IsDisabled() && Game.IsObjectFavorited(N) == False && DBM_ExcludeList.HasForm(F) == 0 PlayerRef.Removeitem(N, 1, true, ArmorySafe) DBM_DisplayMax.Value += 1 O.Enable() endif Endif EndWhileEndFunction Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 18, 2017 Share Posted March 18, 2017 (edited) Maybe you have fun with these. Not compiled, errors are possible. I split your script in two scripts a parent and a child script.You are using some more scripts, which could also slow down the sort process. parent: DBM_PrepStationScript2Extender Scriptname DBM_PrepStationScript2Extender extends ObjectReference {written by ReDragon 2017, parent of "DBM_PrepStationScript2"} ; contains outsourced Functions and Properties ; https://forums.nexusmods.com/index.php?/topic/5458177-optimizing-a-monster-script/ GlobalVariable PROPERTY DBM_DisplayMAX auto ; Do you need all three scripts here, not only one for the object? (ReDragon) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; answer: ? DBM_JewelryDisplayScript PROPERTY ScaleDisplays auto DBM_JewelryDisplayScript PROPERTY JewelryDisplays auto DBM_JewelryDisplayScript PROPERTY JewelryDisplays2 auto ; How many objects have that script attached? (ReDragon) ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; answer: ? ObjectReference PROPERTY DisplaySafe auto ; SortGroup() ObjectReference PROPERTY DisplaySafe2 auto ; SortBooks() ObjectReference PROPERTY ArmorySafe auto ; ArmorySort() ObjectReference PROPERTY JewelryCase auto ; SortJewelry() ObjectReference PROPERTY JewelryCase2 auto ; SortJewelry2() ObjectReference PROPERTY ScaleCase auto ; SortScales() ; -- FUNCTIONs -- 2 + 2 + 4 = 8 ;--------------------------------------------------------------------------------- FUNCTION myF_SortByMOD(String s, FormList DisplayList, FormList ItemList, Int n=0) ; helper ;--------------------------------------------------------------------------------- ; s = "ModName.esp" ; n = 0 --> SortGroup() ; n = 1 --> SortJewelry() ; n = 2 --> SortJewelry2() ; n = 3 --> SortScales() ; n = 4 --> SortBooks() IF (Game.GetModByName(s) == 255) ; SKSE required ;; Debug.Trace(self+" Mod: " +s+ " not found!") RETURN ; - STOP - mod not found ENDIF ;--------------------- IF (n == 0) SortGroup(Game.GetPlayer(), DisplayList, ItemList) ELSEIF (n == 1) SortJewelry(Game.GetPlayer(), DisplayList, ItemList, JewelryCase, JewelryDisplays) ELSEIF (n == 2) SortJewelry2(Game.GetPlayer(), DisplayList, ItemList, JewelryCase2, JewelryDisplays2) ELSEIF (n == 3) SortScales(Game.GetPlayer(), DisplayList, ItemList, ScaleCase, ScaleDisplays) ELSEIF (n == 4) SortBooks(Game.GetPlayer(), DisplayList, ItemList) ENDIF ENDFUNCTION ;--------------------------------- FUNCTION myF_UpdateGlobal(Float f) ; helper ;--------------------------------- f = f + DBM_DisplayMax.GetValue() DBM_DisplayMax.SetValue(f) ; set globalVar ENDFUNCTION ;---------------------------------------------------------------------- FUNCTION SortGroup(Actor aRef, FormList DisplayList, FormList ItemList) ;---------------------------------------------------------------------- ; "aRef" should be actionRef, which is Game.GetPlayer() form fm objectReference oRef objectReference dsRef = DisplaySafe float f = 0 ; (0) init variables int i = DisplayList.GetSize() WHILE (i > 0) i = i - 1 oRef = DisplayList.GetAt(i) as ObjectReference ; (1) get the object Ref IF (oRef) && oRef.IsDisabled() ; (2) is it valid and currently disabled fm = ItemList.GetAt(i) ; (3) get the item now IF (!fm) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (dsRef.GetItemCount(fm) > 0) ; do nothing // SKSE: "Game.IsObjectFavorited(fm)" ; http://www.creationkit.com/index.php?title=IsObjectFavorited_-_Game ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, dsRef) ; (4) object is disabled, move it to DisplaySafe f = f + 1 oRef.Enable() ; (5) enable it ENDIF ENDIF ENDWHILE myF_UpdateGlobal(f) ; (6) update globalVar ENDFUNCTION ;---------------------------------------------------------------------- FUNCTION SortBooks(Actor aRef, FormList DisplayList, FormList ItemList) ;---------------------------------------------------------------------- ; "aRef" should be actionRef, which is Game.GetPlayer() form fm objectReference oRef objectReference ds2Ref = DisplaySafe2 float f = 0 ; (0) init variables int i = DisplayList.GetSize() WHILE (i > 0) i = i - 1 oRef = DisplayList.GetAt(i) as ObjectReference IF (oRef) && oRef.IsDisabled() fm = ItemList.GetAt(i) IF (!fm) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (ds2Ref.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, ds2Ref) f = f + 1 oRef.Enable() ENDIF ENDIF ENDWHILE myF_UpdateGlobal(f) ENDFUNCTION ;------------------------------------------------------------------- FUNCTION Sort_SubList(Actor aRef, Form fmL, ObjectReference caseRef) ; helper for the next three functions ;------------------------------------------------------------------- ; "aRef" should be actionRef, which is Game.GetPlayer() ; "caseRef" is property ScaleCase, JewelryCase or JewelryCase2 ;;; formList Sublist = fmL as FormList form fm int i = (fmL as FormList).GetSize() WHILE (i > 0) i = i - 1 fm = (fmL as FormList).GetAt(i) IF (fm.GetBaseObject() as Armor) IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (caseRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, caseRef) ENDIF ENDIF ENDWHILE ENDFUNCTION ;--------------------------------------------------------------------------------------------------------------------------- FUNCTION SortScales(Actor aRef, FormList DisplayList, FormList ItemList, ObjectReference scRef, DBM_JewelryDisplayScript ps) ;--------------------------------------------------------------------------------------------------------------------------- ; "aRef" should be actionRef, which is Game.GetPlayer() ; "scRef" is property ScaleCase ; "ps" is property ScaleDisplays form fm ;;; objectReference oRef int i = ItemList.GetSize() WHILE (i > 0) i = i - 1 ;;; oRef = DisplayList.GetAt(i) as Objectreference ; missing in original !!! ;;; IF (oRef) && oRef.IsDisabled() ; missing in original !!! fm = ItemList.GetAt(i) IF (fm.GetBaseObject() as Armor) IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (scRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, scRef) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, scRef) ENDIF ;;; ENDIF ENDWHILE ; ScaleDisplays ps.ResetDisplay() ; How much time consume these both functions? ps.UpdateDisplay() ENDFUNCTION ;---------------------------------------------------------------------------------------------------------------------------- FUNCTION SortJewelry(Actor aRef, FormList DisplayList, FormList ItemList, ObjectReference jcRef, DBM_JewelryDisplayScript ps) ;---------------------------------------------------------------------------------------------------------------------------- ; "aRef" should be actionRef, which is Game.GetPlayer() ; "scRef" is property JewelryCase ; "ps" is property JewelryDisplays form fm ;;; objectReference oRef int i = ItemList.GetSize() WHILE (i > 0) i = i - 1 ;;; oRef = DisplayList.GetAt(i) as Objectreference ; missing in original !!! ;;; IF (oRef) && oRef.IsDisabled() ; missing in original !!! fm = ItemList.GetAt(i) IF (fm.GetBaseObject() as Armor) IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (jcRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, jcRef) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, jcRef) ENDIF ;;; ENDIF ENDWHILE ; JewelryDisplays ps.ResetDisplay() ps.UpdateDisplay() ENDFUNCTION ;------------------------------------------------------------------------------------------------------------------------------ FUNCTION SortJewelry2(Actor aRef, FormList DisplayList, FormList ItemList, ObjectReference jc2Ref, DBM_JewelryDisplayScript ps) ;------------------------------------------------------------------------------------------------------------------------------ ; "aRef" should be actionRef, which is Game.GetPlayer() ; "scRef" is property JewelryCase2 ; "ps" is property JewelryDisplays2 form fm ;;; objectReference oRef int i = ItemList.GetSize() WHILE (i > 0) i = i - 1 ;;; oRef = DisplayList.GetAt(i) as Objectreference ; missing in original !!! ;;; IF (oRef) && oRef.IsDisabled() ; missing in original !!! fm = ItemList.GetAt(i) IF (fm.GetBaseObject() as Armor) IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (jcRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, jc2Ref) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, jc2Ref) ENDIF ;;; ENDIF ENDWHILE ; JewelryDisplays2 ps.ResetDisplay() ps.UpdateDisplay() ENDFUNCTION ;################################################################### ;### FormLists ### ;################# FormList Property DBM_ExcludeList Auto FormList Property DisplayActivators Auto FormList Property DisplayItems Auto FormList Property DBM_DaedricDisplays Auto FormList Property DBM_DaedricItems Auto FormList Property OddityDisplays Auto FormList Property OddityItems Auto FormList Property DBM_HOLEDisplays Auto FormList Property DBM_HOLEItems Auto FormList Property DBM_HOSDisplays Auto FormList Property DBM_HOSItems Auto FormList Property DBM_BCSDisplays Auto FormList Property DBM_BCSItems Auto FormList Property DBM_UTDisplays Auto FormList Property DBM_UTItems Auto FormList Property DBM_KADisplays Auto FormList Property DBM_KAItems Auto FormList Property DBM_JARDisplays Auto FormList Property DBM_JARItems Auto FormList Property DBM_AetherealDisplays Auto FormList Property DBM_AetherealItems Auto FormList Property DBM_MILDisplays Auto FormList Property DBM_MILItems Auto FormList Property DBM_FairyDisplays Auto FormList Property DBM_FairyItems Auto FormList Property DBM_MadMaskerDisplays Auto FormList Property DBM_MadMaskerItems Auto FormList Property DBM_HelgenDisplays Auto FormList Property DBM_HelgenItems Auto FormList Property DBM_GrayCowlDisplays Auto FormList Property DBM_GrayCowlItems Auto FormList Property DBM_WyrmstoothDisplays Auto FormList Property DBM_WyrmstoothItems Auto FormList Property DBM_FalskaarDisplays Auto FormList Property DBM_FalskaarItems Auto FormList Property DBM_LullDisplaysList Auto FormList Property DBM_LullItems Auto FormList Property DBM_HeadsDisplays Auto FormList Property DBM_HeadsItems Auto FormList Property UpperDisplays Auto FormList Property UpperItems Auto FormList Property GemstoneDisplays Auto FormList Property GemstoneList Auto FormList Property ShellDisplays Auto FormList Property ShellList Auto FormList Property DBM_FishDisplays Auto FormList Property DBM_FishItems Auto FormList Property DBM_IWIADisplays Auto FormList Property DBM_IWIAItems Auto FormList Property DBM_JewelryUnique Auto FormList Property DBM_MASItems Auto FormList Property DBM_MASDisplays Auto FormList Property DBM_AOBItems Auto FormList Property DBM_AOBDisplays Auto FormList Property DBM_OAPItems Auto FormList Property DBM_OAPDisplays Auto FormList Property DBM_SUGItems Auto FormList Property DBM_SUGDisplays Auto FormList Property DBM_RAItems Auto FormList Property DBM_RADisplays Auto FormList Property DBM_EDItems Auto FormList Property DBM_EDDisplays Auto FormList Property DBM_AOSCaseList Auto ;------------------------------------------------- ;;; FormList PROPERTY DBM_Armory auto ; variant 1: Try to use 1 armory formlist instead of 16! ; DBM_Armory.GetAt(0) = DBM_ArmoryIron ; DBM_Armory.GetAt(1) = DBM_ArmorySteel ; ... ; DBM_Armory.GetAt(13)= DBM_ArmoryAncientNord ;;; FormList[] PROPERTY DBM_ArmoryList auto ; variant 2: Try to use 1 armory array instead of 16 formlist properties!! ; DBM_ArmoryList[0] = DBM_ArmoryIron ; DBM_ArmoryList[1] = DBM_ArmorySteel ; ... ; DBM_ArmoryList[13]= DBM_ArmoryAncientNord FormList Property DBM_ArmoryIron Auto ; 16x FormList Property DBM_ArmorySteel Auto FormList Property DBM_ArmoryNordic Auto FormList Property DBM_ArmoryElven Auto FormList Property DBM_ArmoryGlass Auto FormList Property DBM_ArmoryOrcish Auto FormList Property DBM_ArmoryDwarven Auto FormList Property DBM_ArmoryEbony Auto FormList Property DBM_ArmoryDaedric Auto FormList Property DBM_ArmoryDragon Auto FormList Property DBM_ArmoryFalmer Auto FormList Property DBM_ArmoryBlades Auto FormList Property DBM_ArmoryForsworn Auto FormList Property DBM_ArmoryAncientNord Auto FormList Property DBM_ArmoryDawnguard Auto ; DLC1 FormList Property DBM_ArmoryStalhrim Auto ; DLC2 child: DBM_PrepStationScript2 Scriptname DBM_PrepStationScript2 extends DBM_PrepStationScript2Extender ; ObjectReference {rewritten by ReDragon 2017, original by iceCreamAssassin} ; https://forums.nexusmods.com/index.php?/topic/5458177-optimizing-a-monster-script/ ; Purpose: "This script basically checks to see if references on various fomlists are enabled and ; if not checks if a player has an item on a matching list index and then goes about 'displaying the item'." ; Issue: ".. there are so many lists and items on these lists that the while loop setup ; really slows things down and it can take up to 3 minutes to run the whole thing." ; ------------------------------------------------------------------------------------- Quest PROPERTY DBM_GuidebookHandler auto Message PROPERTY SortMsg auto GlobalVariable PROPERTY DBM_SortWait auto ;Actor PROPERTY PlayerRef auto ; DO NOT USE !!! ;FormList ITEMLIST ;FormList DISPLAYLIST ;ObjectReference O ;Form f ;Weapon M ;Armor N ;Int Index ;Int Index2 Bool bArmoryDone ; added by ReDragon ; -- FUNCTION -- ;/ *** older version *** ;------------------------------------------------------------------------------ FUNCTION ArmorySort(Actor aRef, FormList DisplayList, FormList ItemList = None) ;------------------------------------------------------------------------------ ; "aRef" should be actionRef, which is Game.GetPlayer() ; Note: "ItemList == DisplayList" form fm objectReference oRef objectReference asRef = ArmorySafe ItemList = DisplayList float f = 0 ; (0) init variables int i = DisplayList.GetSize() WHILE (i > 0) i = i - 1 ;;; oRef = DisplayList.GetAt(i) as ObjectReference ;;; IF (oRef) && oRef.IsDisabled() fm = ItemList.GetAt(i) ; missing in original !!! IF (!fm) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (asRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) form fmBase = oRef.GetBaseObject() ; store the baseobject IF (fmBase as Weapon) || (fmBase as Armor) aRef.RemoveItem(fm, 1, TRUE, asRef) f = f + 1 oRef.Enable() ENDIF ENDIF ;;; ENDIF ENDWHILE myF_UpdateGlobal(f) ENDFUNCTION *** /; ;------------------------------------------------------------------------------ FUNCTION ArmorySort(Actor aRef, FormList DisplayList, FormList ItemList = None) ; older version was not good enough ;------------------------------------------------------------------------------ ; "aRef" is Game.GetPlayer(), see OnUpdateGameTime() ; Note: "ItemList == DisplayList" form fm objectReference oRef ;;; objectReference asRef = ArmorySafe ;;; ItemList = DisplayList float f = 0 ; (0) init variables int i = DisplayList.GetSize() WHILE (i > 0) i = i - 1 oRef = DisplayList.GetAt(i) as ObjectReference IF (oRef) && oRef.IsDisabled() fm = oRef as Form ; == ItemList.GetAt(i) IF Game.IsObjectFavorited(fm) || (ArmorySafe.GetItemCount(fm) > 0) || DBM_ExcludeList.HasForm(fm) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) ;;; form fmBase = oRef.GetBaseObject() ; store the baseobject ;;; IF (fmBase as Weapon) || (fmBase as Armor) IF (fm as Weapon) || (fm as Armor) aRef.RemoveItem(fm, 1, TRUE, ArmorySafe) f = f + 1 oRef.Enable() ENDIF ENDIF ENDIF ENDWHILE myF_UpdateGlobal(f) ; see parent script ENDFUNCTION ; -- EVENTs -- "Busy" + "ready" ;========================================================= state busy ;========= EVENT OnActivate(ObjectReference actionRef) IF (actionRef == Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - not the player ENDIF ;--------------------- Debug.MessageBox("Please wait.. until sorting operation is completed!") ENDEVENT EVENT OnUpdateGameTime() ArmorySafe.BlockActivation(TRUE) ; -------------------------- Utility.Wait(0.1) actor aRef = Game.GetPlayer() ArmorySort(aRef, DBM_ArmoryIron) ;;; ArmorySort(aRef, DBM_Armory.GetAt(0)) ; see parent script "DBM_PrepStationScript2Extender.psc" for optimization ;;; ArmorySort(aRef, DBM_ArmoryList[0]) ArmorySort(aRef, DBM_ArmorySteel) ;;; ArmorySort(aRef, DBM_Armory.GetAt(1)) ; variant 1: one formlist for 16 ;;; ArmorySort(aRef, DBM_ArmoryList[1]) ; variant 2: one array which contains 16 formlists (my favorite) ArmorySort(aRef, DBM_ArmoryNordic) ArmorySort(aRef, DBM_ArmoryElven) ArmorySort(aRef, DBM_ArmoryGlass) ArmorySort(aRef, DBM_ArmoryOrcish) ArmorySort(aRef, DBM_ArmoryDwarven) ArmorySort(aRef, DBM_ArmoryEbony) ArmorySort(aRef, DBM_ArmoryDaedric) ArmorySort(aRef, DBM_ArmoryDragon) ArmorySort(aRef, DBM_ArmoryFalmer) ArmorySort(aRef, DBM_ArmoryForsworn) ArmorySort(aRef, DBM_ArmoryBlades) ArmorySort(aRef, DBM_ArmoryAncientNord) ArmorySort(aRef, DBM_ArmoryDawnguard) ; DLC1 required ArmorySort(aRef, DBM_ArmoryStalhrim) ; DLC2 required ; -------------------------- ArmorySafe.BlockActivation(False) bArmoryDone = TRUE Debug.Notification("Armory sorting done!") ; *** ENDEVENT ;======= endState ;========================================================= auto state ready ;=============== EVENT OnActivate(ObjectReference actionRef) IF (actionRef == Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - not the player ENDIF ;--------------------- IF DBM_SortWait.GetValue() == 1 Debug.MessageBox("You must wait for the current sorting operation to complete before removing displays") RETURN ; - STOP - I am busy while sorting! ENDIF ;--------------------- IF (SortMsg.Show() == 1) RETURN ; - STOP - cancel, no sorting ENDIF ;===================== if SortBtn == 0 ; Sort all display items gotostate("busy") ; ### STATE ### DBM_SortWait.SetValue(1) Debug.Notification("All items being displayed, this will take a while..") ; ##################### bArmoryDone = False RegisterForSingleUpdateGameTime(0.0) ; armory sorting not sequential, let it run parallel with another thread ; ###################################### ; **************************************************************** ;;; SortGroup(Actor aRef, FormList DisplayList, FormList ItemList) ; **************************************************************** ; JEWELRY SORTING SortJewelry(actionRef, DBM_JewelryUnique, DBM_JewelryUnique, JewelryCase, JewelryDisplays) ; MAIN MUSEUM SortGroup(actionRef, DisplayActivators, DisplayItems) ; edited ; UPPER GALLERY SortGroup(actionRef, UpperDisplays, UpperItems) ; edited Debug.Notification("Still sorting displays 1") ; *** ; ------------------ ; DAEDRIC GALLERY SortGroup(actionRef, DBM_DaedricDisplays, DBM_DaedricItems) ; HALL OF LOST EMPIRES SortGroup(actionRef, DBM_HOLEDisplays, DBM_HOLEItems) ; HALL OF SECRETS SortGroup(actionRef, DBM_HOSDisplays, DBM_HOSItems) ; HALL OF ODDITIES SortGroup(actionRef, OddityDisplays, OddityItems) Debug.Notification("Still sorting displays 2") ; *** ; ------------------ ; LIBRARY SORTING SortBooks(actionRef, DBM_BCSDisplays, DBM_BCSItems) ; ####################################### see event OnUpdateGameTime() ;; ARMORY ; ArmorySafe.BlockActivation(TRUE) ; ; ArmorySort(actionRef, DBM_ArmoryIron) ; ArmorySort(actionRef, DBM_ArmorySteel) ; ArmorySort(actionRef, DBM_ArmoryNordic) ; ArmorySort(actionRef, DBM_ArmoryElven) ; ArmorySort(actionRef, DBM_ArmoryGlass) ; ArmorySort(actionRef, DBM_ArmoryOrcish) ; ArmorySort(actionRef, DBM_ArmoryDwarven) ; ArmorySort(actionRef, DBM_ArmoryStalhrim) ; DLC2 required ; ArmorySort(actionRef, DBM_ArmoryEbony) ; ArmorySort(actionRef, DBM_ArmoryDaedric) ; ArmorySort(actionRef, DBM_ArmoryDragon) ; ArmorySort(actionRef, DBM_ArmoryDawnguard) ; DLC1 required ; ArmorySort(actionRef, DBM_ArmoryFalmer) ; ArmorySort(actionRef, DBM_ArmoryForsworn) ; ArmorySort(actionRef, DBM_ArmoryBlades) ; ArmorySort(actionRef, DBM_ArmoryAncientNord) ; ; ArmorySafe.BlockActivation(False) ;; end of ARMORY ; ############################################## ; GEMSTONE DISPLAYS SortGroup(actionRef, GemstoneDisplays, Gemstonelist) ; SHELL DISPLAYS SortGroup(actionRef, ShellDisplays, ShellList) Debug.Notification("Still sorting displays 3") ; *** ; ------------------ ; *************************************************************************** ;;; myF_SortByMOD(String s, FormList DisplayList, FormList ItemList, Int n=0) ; *************************************************************************** ; n = 0 --> SortGroup() ; n = 1 --> SortJewelry() ; n = 2 --> SortJewelry2() ; n = 3 --> SortScales() ; n = 4 --> SortBooks() ; ElementalDragons myF_SortByMOD("Elemental_Dragons.esp", DBM_EDDisplays, DBM_EDItems, 3) ; // SortScales() ; AMULETS OF SKYRIM SORTING myF_SortByMOD("SL01AmuletsSkyrim.esp", DBM_AOSCaseList, DBM_AOSCaseList, 2) ; // SortJewelry2() ; SUT COLLECTION myF_SortByMOD("SkyrimsUniqueTreasures.esp", DBM_UTDisplays, DBM_UTItems) ; // SortGroup() 0 by Default ; TROPHY HEADS myF_SortByMOD("BGTrophyHeads.esp", DBM_HeadsDisplays, DBM_HeadsItems) ; JAR COLLECTION myF_SortByMOD("BadGremlinsJarHunt.esp", DBM_JarDisplays, DBM_JarItems) Debug.Notification("Still sorting displays 4") ; *** ; ------------------ ; AETHERIUM COLLECTION myF_SortByMOD("AetheriumSwordsnArmor.esp", DBM_AetherealDisplays, DBM_AetherealItems) ; MORE INTERESTING LOOT myF_SortByMOD("More Interesting Loot for Skyrim.esp", DBM_MILDisplays, DBM_MILItems) ; CAPTURED FAIRIES myF_SortByMOD("BGTheCapturedFairies.esp", DBM_FairyDisplays, DBM_FairyItems) ; MAD MASKER myF_SortByMOD("TheMadMasker.esp", DBM_MadMaskerDisplays, DBM_MadMaskerItems) ; FISH DISPLAYS myF_SortByMOD("BGSomethingFishy.esp", DBM_FishDisplays, DBM_FishItems) ; HELGEN myF_SortByMOD("Helgen Reborn.esp", DBM_HelgenDisplays, DBM_HelgenItems) Debug.Notification("Still sorting displays 5") ; *** ; ------------------ ; GrayCowl myF_SortByMOD("Gray Fox Cowl.esm", DBM_GrayCowlDisplays, DBM_GrayCowlItems) ; ESM-file ; WYRMSTOOTH myF_SortByMOD("Wyrmstooth.esp", DBM_WyrmstoothDisplays, DBM_WyrmstoothItems) ; FALSKAAR myF_SortByMOD("Falskaar.esm", DBM_FalskaarDisplays, DBM_FalskaarItems) ; ESM-file ; WHEELS OF LULL myF_SortByMOD("WheelsOfLull.esp", DBM_LullDisplaysList, DBM_LullItems) ; MOON AND STAR myF_SortByMOD("Moonandstar_MAS.esp", DBM_MASDisplays, DBM_MASItems) ; IWIA myF_SortByMOD("Immersive Weapons.esp", DBM_IWIADisplays, DBM_IWIAItems) myF_SortByMOD("Hothtrooper44_ArmorCompilation.esp", DBM_IWIADisplays, DBM_IWIAItems) Debug.Notification("Still sorting displays 6") ; *** ; ------------------ ; KA displays myF_SortByMOD("Konahrik_Accoutrements.esp", DBM_KADisplays, DBM_KAItems) ; AOB Displays myF_SortByMOD("ArtifactsOfBoethiah.esp", DBM_AOBDisplays, DBM_AOBItems) ; Oblivion artifacts Displays myF_SortByMOD("escutcheonredwave.esp", DBM_OAPDisplays, DBM_OAPItems) ; Skyrim Underground myF_SortByMOD("akskyrimunderground.esp", DBM_SUGDisplays, DBM_SUGItems) ; Royal Armory myF_SortByMOD("PrvtIRoyalArmory.esp", DBM_RADisplays, DBM_RAItems) ; SortGroup() ;---------------------------------------------------------------------- IF ( !bArmoryDone ) ; (bArmoryDone == False) Debug.Notification("Sorting of displays done.. waiting for armory") ; *** ENDIF WHILE (!bArmoryDone) Utility.Wait(0.25) ; We are waiting for armory!! ENDWHILE ; ---------------------- Debug.Messagebox("Done! All items displayed..") ; *** END *** DBM_GuidebookHandler.SetStage(10) ; update quest stages IF DBM_Utils.GetSharingEnabled() SendModEvent("DBM_Message", "DoFullScan") ENDIF DBM_SortWait.SetValue(0) gotoState("ready") ; ### STATE ### ENDEVENT ;======= endState Edited March 19, 2017 by ReDragon2013 Link to comment Share on other sites More sharing options...
icecreamassassin Posted March 18, 2017 Author Share Posted March 18, 2017 So just getting ready to pop this in and compile and test it out (thanks for putting this together BTW) but I noticed that you commented on not to use a property for the player. I have been told by multiple sources that using Game.GetPlayer() is slower than defining a player property. Why should I not be using that? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 19, 2017 Share Posted March 19, 2017 Properties take up more memory.Running Game.GetPlayer() multiple times takes up processing time. It is a ying-yang balancing act of which is best for the script at hand. If I had to choose between doing only one or the other, I would err on the side of using the property. However, there is a middle approach and that would be something as follows: Actor PlayerRef Event OnInit() PlayerRef = Game.GetPlayer() EndEventThis approach allows you to store the player into a single variable usable throughout the script as a property. While limiting the processing calls to a single Game.GetPlayer(). In theory then it reduces both memory and processing time. In a nutshell...Game.GetPlayer() approach is fine for a few callsproperty approach is better when many calls would be requiredlocal var with single Game.GetPlayer() approach is best whenever possible to do ***************************Even tho the sort time can take up to 3 minutes, I still find that better than trying to locate where to manually place each object. The museum is so big that I easily take up more than 3 minutes trying to place the few items I can locate displays for and then still end up waiting for the sorter. Here is an idea. A portable container that will only hold items that you will display (I have a script which does this already for v18 of LOTD). Then when the player interacts with the prep station the container is sorted from rather than the player inventory. You'll be able to speed up the process by not having to check that each armor or weapon type is equipped and/or favorited. You'll still have the while loops of course. Link to comment Share on other sites More sharing options...
icecreamassassin Posted March 19, 2017 Author Share Posted March 19, 2017 I thought that a property only takes up extra memory if it's a new property. PlayerRef is pretty universal. That's how the string count limit works at least. I'm trying to debug the script provided but it seems that it's not casting player to the actionref or aref property ... Still fiddling Link to comment Share on other sites More sharing options...
icecreamassassin Posted March 19, 2017 Author Share Posted March 19, 2017 So I got copies compiled after debugging a few things. The aRef property wasn't casting properly because as far as I could tell it was only running as part of the armory routine and not being defined in the active state, so I added another cast for it and it seems to work. Had to rename a few properties that were named differently in functions, etc, but it all seems to work fine. I tested using a Legacy only load up (SkyUi, USLEEP and Legacy) and used my test cell lever to add about 80% of all the displays to my inventory, went to the station and ran the prep station and timed it. The original was 3:08 the new version was 2:55, so a slight improvement. Assuming the corrections I made didn't limit some element of the new script, it doesn't seem to be a decidedly big variance. However when I ran a full load out with almost all of the supported mods and my normal mod list, then new system came in at about 4:18 and the old one at 5:50 so it does save over 1:30 which is awesome! So, ReDragon if you wouldn't mind elaborating on how Game.GetPlayer() is a better method than a set property for this process especially since it is called several times in the script, I'd appreciate that. Otherwise I think we have a winner here. Just need to delve in and try to understand WHY it works so much more quickly lol. Here are the two scripts after edit if you wouldn't mind verifying that I didn't muck anything up: DBM_PrepStationScript2 Scriptname DBM_PrepStationScript2 extends DBM_PrepStationScript2Extender ; ObjectReference{rewritten by ReDragon 2017, original by iceCreamAssassin}; https://forums.nexusmods.com/index.php?/topic/5458177-optimizing-a-monster-script/; Purpose: "This script basically checks to see if references on various fomlists are enabled and; if not checks if a player has an item on a matching list index and then goes about 'displaying the item'."; Issue: ".. there are so many lists and items on these lists that the while loop setup; really slows things down and it can take up to 3 minutes to run the whole thing."; ------------------------------------------------------------------------------------- Quest PROPERTY DBM_GuidebookHandler auto Message PROPERTY SortMsg auto GlobalVariable PROPERTY DBM_SortWait auto ;Actor PROPERTY PlayerRef auto ; DO NOT USE !!! ;FormList ITEMLIST ;FormList DISPLAYLIST ;ObjectReference O ;Form f ;Weapon M ;Armor N ;Int Index ;Int Index2 Bool bArmoryDone ; added by ReDragon; -- FUNCTION --;------------------------------------------------------------------------------FUNCTION ArmorySort(Actor aRef, FormList DisplayList, FormList ItemList = None);------------------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer(); Note: "ItemList == DisplayList" form fm objectReference oRef objectReference asRef = ArmorySafe ItemList = DisplayListfloat f = 0 ; (0) init variablesint i = DisplayList.GetSize()WHILE (i > 0) i = i - 1;;; oRef = DisplayList.GetAt(i) as ObjectReference;;; IF (oRef) && oRef.IsDisabled() fm = ItemList.GetAt(i) ; missing in original !!! IF (!fm) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (asRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) form fmBase = oRef.GetBaseObject() ; store the baseobject IF (fmBase as Weapon) || (fmBase as Armor) aRef.RemoveItem(fm, 1, TRUE, asRef) f = f + 1 oRef.Enable() ENDIF ENDIF;;; ENDIFENDWHILE myF_UpdateGlobal(f)ENDFUNCTION; -- EVENTs -- "Busy" + "ready";=========================================================state busy;=========EVENT OnActivate(ObjectReference actionRef)IF (actionRef == Game.GetPlayer() as ObjectReference)ELSE RETURN ; - STOP - not the playerENDIF;--------------------- Debug.MessageBox("Please wait.. until sorting operation is completed!")ENDEVENTEVENT OnUpdateGameTime() ArmorySafe.BlockActivation(TRUE); -------------------------- Utility.Wait(0.1) actor aRef = Game.GetPlayer() ArmorySort(aRef, DBM_ArmoryIron);;; ArmorySort(aRef, DBM_Armory.GetAt(0)) ; see parent script "DBM_PrepStationScript2Extender.psc" for optimization ArmorySort(aRef, DBM_ArmorySteel);;; ArmorySort(aRef, DBM_Armory.GetAt(1)) ArmorySort(aRef, DBM_ArmoryNordic) ArmorySort(aRef, DBM_ArmoryElven) ArmorySort(aRef, DBM_ArmoryGlass) ArmorySort(aRef, DBM_ArmoryOrcish) ArmorySort(aRef, DBM_ArmoryDwarven) ArmorySort(aRef, DBM_ArmoryEbony) ArmorySort(aRef, DBM_ArmoryDaedric) ArmorySort(aRef, DBM_ArmoryDragon) ArmorySort(aRef, DBM_ArmoryFalmer) ArmorySort(aRef, DBM_ArmoryForsworn) ArmorySort(aRef, DBM_ArmoryBlades) ArmorySort(aRef, DBM_ArmoryAncientNord) ArmorySort(aRef, DBM_ArmoryDawnguard) ; DLC1 required ArmorySort(aRef, DBM_ArmoryStalhrim) ; DLC2 required; -------------------------- ArmorySafe.BlockActivation(False) bArmoryDone = TRUE Debug.Notification("Armory sorting done!") ; ***ENDEVENT;=======endState;=========================================================auto state ready;===============EVENT OnActivate(ObjectReference actionRef)IF (actionRef == Game.GetPlayer() as ObjectReference)ELSE RETURN ; - STOP - not the playerENDIF;---------------------IF DBM_SortWait.GetValue() == 1 Debug.MessageBox("You must wait for the current sorting operation to complete before removing displays") RETURN ; - STOP - I am busy while sorting!ENDIF;---------------------IF (SortMsg.Show() == 1) RETURN ; - STOP - cancel, no sortingENDIF;===================== if SortBtn == 0 ; Sort all display items gotostate("busy") ; ### STATE ### DBM_SortWait.SetValue(1) actor aRef = Game.GetPlayer() Debug.Notification("All items being displayed, this will take a while.."); ##################### bArmoryDone = False RegisterForSingleUpdateGameTime(0.0) ; armory sorting not sequential, let it run parallel with another thread; ######################################; ****************************************************************;;; SortGroup(Actor aRef, FormList DisplayList, FormList ItemList); ****************************************************************; JEWELRY SORTING SortJewelry(Aref, DBM_JewelryUnique, DBM_JewelryUnique, JCREF, JewelryDisplays); MAIN MUSEUM SortGroup(Aref, DisplayActivators, DisplayItems); UPPER GALLERY SortGroup(Aref, UpperDisplays, UpperItems) Debug.Notification("Still sorting displays") ; ***; ------------------; DAEDRIC GALLERY SortGroup(aRef, DBM_DaedricDisplays, DBM_DaedricItems); HALL OF LOST EMPIRES SortGroup(aRef, DBM_HOLEDisplays, DBM_HOLEItems); HALL OF SECRETS SortGroup(aRef, DBM_HOSDisplays, DBM_HOSItems); HALL OF ODDITIES SortGroup(aRef, OddityDisplays, OddityItems) Debug.Notification("Still sorting displays.") ; ***; ------------------; LIBRARY SORTING SortBooks(aRef, DBM_BCSDisplays, DBM_BCSItems); ####################################### see event OnUpdateGameTime();; ARMORY; ArmorySafe.BlockActivation(TRUE);; ArmorySort(aRef, DBM_ArmoryIron); ArmorySort(aRef, DBM_ArmorySteel); ArmorySort(aRef, DBM_ArmoryNordic); ArmorySort(aRef, DBM_ArmoryElven); ArmorySort(aRef, DBM_ArmoryGlass); ArmorySort(aRef, DBM_ArmoryOrcish); ArmorySort(aRef, DBM_ArmoryDwarven); ArmorySort(aRef, DBM_ArmoryStalhrim) ; DLC2 required; ArmorySort(aRef, DBM_ArmoryEbony); ArmorySort(aRef, DBM_ArmoryDaedric); ArmorySort(aRef, DBM_ArmoryDragon); ArmorySort(aRef, DBM_ArmoryDawnguard) ; DLC1 required; ArmorySort(aRef, DBM_ArmoryFalmer); ArmorySort(aRef, DBM_ArmoryForsworn); ArmorySort(aRef, DBM_ArmoryBlades); ArmorySort(aRef, DBM_ArmoryAncientNord);; ArmorySafe.BlockActivation(False);; end of ARMORY; ##############################################; GEMSTONE DISPLAYS SortGroup(aRef, GemstoneDisplays, Gemstonelist); SHELL DISPLAYS SortGroup(aRef, ShellDisplays, ShellList) Debug.Notification("Still sorting displays..") ; ***; ------------------; ***************************************************************************;;; myF_SortByMOD(String s, FormList DisplayList, FormList ItemList, Int n=0); ***************************************************************************; n = 0 --> SortGroup(); n = 1 --> SortJewelry(); n = 2 --> SortJewelry2(); n = 3 --> SortScales(); n = 4 --> SortBooks(); ElementalDragons myF_SortByMOD("Elemental_Dragons.esp", DBM_EDDisplays, DBM_EDItems, 3) ; // SortScales(); AMULETS OF SKYRIM SORTING myF_SortByMOD("SL01AmuletsSkyrim.esp", DBM_AOSCaseList, DBM_AOSCaseList, 2) ; // SortJewelry2(); SUT COLLECTION myF_SortByMOD("SkyrimsUniqueTreasures.esp", DBM_UTDisplays, DBM_UTItems) ; // SortGroup() 0 by Default; TROPHY HEADS myF_SortByMOD("BGTrophyHeads.esp", DBM_HeadsDisplays, DBM_HeadsItems); JAR COLLECTION myF_SortByMOD("BadGremlinsJarHunt.esp", DBM_JarDisplays, DBM_JarItems) Debug.Notification("Still sorting displays...") ; ***; ------------------; AETHERIUM COLLECTION myF_SortByMOD("AetheriumSwordsnArmor.esp", DBM_AetherealDisplays, DBM_AetherealItems); MORE INTERESTING LOOT myF_SortByMOD("More Interesting Loot for Skyrim.esp", DBM_MILDisplays, DBM_MILItems); CAPTURED FAIRIES myF_SortByMOD("BGTheCapturedFairies.esp", DBM_FairyDisplays, DBM_FairyItems); MAD MASKER myF_SortByMOD("TheMadMasker.esp", DBM_MadMaskerDisplays, DBM_MadMaskerItems); FISH DISPLAYS myF_SortByMOD("BGSomethingFishy.esp", DBM_FishDisplays, DBM_FishItems); HELGEN myF_SortByMOD("Helgen Reborn.esp", DBM_HelgenDisplays, DBM_HelgenItems) Debug.Notification("Still sorting displays....") ; ***; ------------------; GrayCowl myF_SortByMOD("Gray Fox Cowl.esm", DBM_GrayCowlDisplays, DBM_GrayCowlItems) ; ESM-file; WYRMSTOOTH myF_SortByMOD("Wyrmstooth.esp", DBM_WyrmstoothDisplays, DBM_WyrmstoothItems); FALSKAAR myF_SortByMOD("Falskaar.esm", DBM_FalskaarDisplays, DBM_FalskaarItems) ; ESM-file; WHEELS OF LULL myF_SortByMOD("WheelsOfLull.esp", DBM_LullDisplaysList, DBM_LullItems); MOON AND STAR myF_SortByMOD("Moonandstar_MAS.esp", DBM_MASDisplays, DBM_MASItems); IWIA myF_SortByMOD("Immersive Weapons.esp", DBM_IWIADisplays, DBM_IWIAItems) myF_SortByMOD("Hothtrooper44_ArmorCompilation.esp", DBM_IWIADisplays, DBM_IWIAItems) Debug.Notification("Still sorting displays.....") ; ***; ------------------; KA displays myF_SortByMOD("Konahrik_Accoutrements.esp", DBM_KADisplays, DBM_KAItems); AOB Displays myF_SortByMOD("ArtifactsOfBoethiah.esp", DBM_AOBDisplays, DBM_AOBItems); Oblivion artifacts Displays myF_SortByMOD("escutcheonredwave.esp", DBM_OAPDisplays, DBM_OAPItems); Skyrim Underground myF_SortByMOD("akskyrimunderground.esp", DBM_SUGDisplays, DBM_SUGItems); Royal Armory myF_SortByMOD("PrvtIRoyalArmory.esp", DBM_RADisplays, DBM_RAItems) ; SortGroup();---------------------------------------------------------------------- IF ( !bArmoryDone ) ; (bArmoryDone == False) Debug.Notification("Sorting of displays done.. waiting for armory") ; *** ENDIF WHILE (!bArmoryDone) Utility.Wait(0.25) ; We are waiting for armory!! ENDWHILE; ---------------------- Debug.Messagebox("Done! All items displayed.") ; *** END *** DBM_GuidebookHandler.SetStage(10) ; update quest stages IF DBM_Utils.GetSharingEnabled() SendModEvent("DBM_Message", "DoFullScan") ENDIF DBM_SortWait.SetValue(0) gotoState("ready") ; ### STATE ###ENDEVENT;=======endState DBM_PrepStationScript2Extender Scriptname DBM_PrepStationScript2Extender extends ObjectReference{written by ReDragon 2017, parent of "DBM_PrepStationScript2"}; contains outsourced Functions and Properties; https://forums.nexusmods.com/index.php?/topic/5458177-optimizing-a-monster-script/ GlobalVariable PROPERTY DBM_DisplayMAX auto; Do you need all three scripts here, not only one for the object? (ReDragon); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~; answer: ? DBM_JewelryDisplayScript PROPERTY ScaleDisplays auto DBM_JewelryDisplayScript PROPERTY JewelryDisplays auto DBM_JewelryDisplayScript PROPERTY JewelryDisplays2 auto; How many objects have that script attached? (ReDragon); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~; answer: ? ObjectReference PROPERTY DisplaySafe auto ; SortGroup() ObjectReference PROPERTY DisplaySafe2 auto ; SortBooks() ObjectReference PROPERTY ArmorySafe auto ; ArmorySort() ObjectReference PROPERTY jcRef auto ; SortJewelry() ObjectReference PROPERTY jc2REF auto ; SortJewelry2() ObjectReference PROPERTY scREF auto ; SortScales(); -- FUNCTIONs -- 2 + 2 + 4 = 8;---------------------------------------------------------------------------------FUNCTION myF_SortByMOD(String s, FormList DisplayList, FormList ItemList, Int n=0) ; helper;---------------------------------------------------------------------------------; s = "ModName.esp"; n = 0 --> SortGroup(); n = 1 --> SortJewelry(); n = 2 --> SortJewelry2(); n = 3 --> SortScales(); n = 4 --> SortBooks()IF (Game.GetModByName(s) == 255) ; SKSE required;; Debug.Trace(self+" Mod: " +s+ " not found!") RETURN ; - STOP - mod not foundENDIF;--------------------- IF (n == 0) SortGroup(Game.GetPlayer(), DisplayList, ItemList) ELSEIF (n == 1) SortJewelry(Game.GetPlayer(), DisplayList, ItemList, jcREF, JewelryDisplays) ELSEIF (n == 2) SortJewelry2(Game.GetPlayer(), DisplayList, ItemList, JC2REF, JewelryDisplays2) ELSEIF (n == 3) SortScales(Game.GetPlayer(), DisplayList, ItemList, SCREF, ScaleDisplays) ELSEIF (n == 4) SortBooks(Game.GetPlayer(), DisplayList, ItemList) ENDIF ENDFUNCTION;---------------------------------FUNCTION myF_UpdateGlobal(Float f) ; helper;--------------------------------- f = f + DBM_DisplayMax.GetValue() DBM_DisplayMax.SetValue(f) ; set globalVarENDFUNCTION;----------------------------------------------------------------------FUNCTION SortGroup(Actor aRef, FormList DisplayList, FormList ItemList);----------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer() form fm objectReference oRef objectReference dsRef = DisplaySafefloat f = 0 ; (0) init variablesint i = DisplayList.GetSize()WHILE (i > 0) i = i - 1 oRef = DisplayList.GetAt(i) as ObjectReference ; (1) get the object Ref IF (oRef) && oRef.IsDisabled() ; (2) is it valid and currently disabled fm = ItemList.GetAt(i) ; (3) get the item now IF (!fm) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (dsRef.GetItemCount(fm) > 0) ; do nothing // SKSE: "Game.IsObjectFavorited(fm)" ; http://www.creationkit.com/index.php?title=IsObjectFavorited_-_Game ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, dsRef) ; (4) object is disabled, move it to DisplaySafe f = f + 1 oRef.Enable() ; (5) enable it ENDIF ENDIFENDWHILE myF_UpdateGlobal(f) ; (6) update globalVarENDFUNCTION;----------------------------------------------------------------------FUNCTION SortBooks(Actor aRef, FormList DisplayList, FormList ItemList);----------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer() form fm objectReference oRef objectReference ds2Ref = DisplaySafe2float f = 0 ; (0) init variablesint i = DisplayList.GetSize()WHILE (i > 0) i = i - 1 oRef = DisplayList.GetAt(i) as ObjectReference IF (oRef) && oRef.IsDisabled() fm = ItemList.GetAt(i) IF (!fm) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (ds2Ref.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, ds2Ref) f = f + 1 oRef.Enable() ENDIF ENDIFENDWHILE myF_UpdateGlobal(f)ENDFUNCTION;-------------------------------------------------------------------FUNCTION Sort_SubList(Actor aRef, Form fmL, ObjectReference caseRef) ; helper for the next three functions;-------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer(); "caseRef" is property ScaleCase, JewelryCase or JewelryCase2;;; formList Sublist = fmL as FormList form fmint i = (fmL as FormList).GetSize()WHILE (i > 0) i = i - 1 fm = (fmL as FormList).GetAt(i) as Armor IF fm as Armor IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (caseRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, caseRef) ENDIF ENDIFENDWHILEENDFUNCTION;---------------------------------------------------------------------------------------------------------------------------FUNCTION SortScales(Actor aRef, FormList DisplayList, FormList ItemList, ObjectReference scRef, DBM_JewelryDisplayScript ps);---------------------------------------------------------------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer(); "scRef" is property ScaleCase; "ps" is property ScaleDisplays form fm;;; objectReference oRefint i = ItemList.GetSize()WHILE (i > 0) i = i - 1;;; oRef = DisplayList.GetAt(i) as Objectreference ; missing in original !!!;;; IF (oRef) && oRef.IsDisabled() ; missing in original !!! fm = ItemList.GetAt(i) as Armor IF fm as Armor IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (scRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, scRef) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, scRef) ENDIF;;; ENDIFENDWHILE; ScaleDisplays ps.ResetDisplay() ; How much time consume these both functions? ps.UpdateDisplay()ENDFUNCTION;----------------------------------------------------------------------------------------------------------------------------FUNCTION SortJewelry(Actor aRef, FormList DisplayList, FormList ItemList, ObjectReference jcRef, DBM_JewelryDisplayScript ps);----------------------------------------------------------------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer(); "scRef" is property JewelryCase; "ps" is property JewelryDisplays form fm;;; objectReference oRefint i = ItemList.GetSize()WHILE (i > 0) i = i - 1;;; oRef = DisplayList.GetAt(i) as Objectreference ; missing in original !!!;;; IF (oRef) && oRef.IsDisabled() ; missing in original !!! fm = ItemList.GetAt(i) as Armor IF fm as Armor IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (jcRef.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, jcRef) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, jcRef) ENDIF;;; ENDIFENDWHILE; JewelryDisplays ps.ResetDisplay() ps.UpdateDisplay()ENDFUNCTION;------------------------------------------------------------------------------------------------------------------------------FUNCTION SortJewelry2(Actor aRef, FormList DisplayList, FormList ItemList, ObjectReference jc2Ref, DBM_JewelryDisplayScript ps);------------------------------------------------------------------------------------------------------------------------------; "aRef" should be actionRef, which is Game.GetPlayer(); "scRef" is property JewelryCase2; "ps" is property JewelryDisplays2 form fm;;; objectReference oRefint i = ItemList.GetSize()WHILE (i > 0) i = i - 1;;; oRef = DisplayList.GetAt(i) as Objectreference ; missing in original !!!;;; IF (oRef) && oRef.IsDisabled() ; missing in original !!! fm = ItemList.GetAt(i) as Armor IF fm as Armor IF Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) || (jcREF.GetItemCount(fm) > 0) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, jc2Ref) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, jc2Ref) ENDIF;;; ENDIFENDWHILE; JewelryDisplays2 ps.ResetDisplay() ps.UpdateDisplay()ENDFUNCTION;###################################################################;### FormLists ###;#################FormList Property DBM_ExcludeList AutoFormList Property DisplayActivators AutoFormList Property DisplayItems AutoFormList Property DBM_DaedricDisplays AutoFormList Property DBM_DaedricItems AutoFormList Property OddityDisplays AutoFormList Property OddityItems AutoFormList Property DBM_HOLEDisplays AutoFormList Property DBM_HOLEItems AutoFormList Property DBM_HOSDisplays AutoFormList Property DBM_HOSItems AutoFormList Property DBM_BCSDisplays AutoFormList Property DBM_BCSItems AutoFormList Property DBM_UTDisplays AutoFormList Property DBM_UTItems AutoFormList Property DBM_KADisplays AutoFormList Property DBM_KAItems AutoFormList Property DBM_JARDisplays AutoFormList Property DBM_JARItems AutoFormList Property DBM_AetherealDisplays AutoFormList Property DBM_AetherealItems AutoFormList Property DBM_MILDisplays AutoFormList Property DBM_MILItems AutoFormList Property DBM_FairyDisplays AutoFormList Property DBM_FairyItems AutoFormList Property DBM_MadMaskerDisplays AutoFormList Property DBM_MadMaskerItems AutoFormList Property DBM_HelgenDisplays AutoFormList Property DBM_HelgenItems AutoFormList Property DBM_GrayCowlDisplays AutoFormList Property DBM_GrayCowlItems AutoFormList Property DBM_WyrmstoothDisplays AutoFormList Property DBM_WyrmstoothItems AutoFormList Property DBM_FalskaarDisplays AutoFormList Property DBM_FalskaarItems AutoFormList Property DBM_LullDisplaysList AutoFormList Property DBM_LullItems AutoFormList Property DBM_HeadsDisplays AutoFormList Property DBM_HeadsItems AutoFormList Property UpperDisplays AutoFormList Property UpperItems AutoFormList Property GemstoneDisplays AutoFormList Property GemstoneList AutoFormList Property ShellDisplays AutoFormList Property ShellList AutoFormList Property DBM_FishDisplays AutoFormList Property DBM_FishItems AutoFormList Property DBM_IWIADisplays AutoFormList Property DBM_IWIAItems AutoFormList Property DBM_JewelryUnique AutoFormList Property DBM_MASItems AutoFormList Property DBM_MASDisplays AutoFormList Property DBM_AOBItems AutoFormList Property DBM_AOBDisplays AutoFormList Property DBM_OAPItems AutoFormList Property DBM_OAPDisplays AutoFormList Property DBM_SUGItems AutoFormList Property DBM_SUGDisplays AutoFormList Property DBM_RAItems AutoFormList Property DBM_RADisplays AutoFormList Property DBM_EDItems AutoFormList Property DBM_EDDisplays AutoFormList Property DBM_AOSCaseList Auto;-------------------------------------------------;;; FormList PROPERTY DBM_Armory auto ; Try to use 1 armory formlist instead of 16!; DBM_Armory.GetAt(0) = DBM_ArmoryIron; DBM_Armory.GetAt(1) = DBM_ArmorySteel; ...; DBM_Armory.GetAt(13)= DBM_ArmoryAncientNordFormList Property DBM_ArmoryIron Auto ; 16xFormList Property DBM_ArmorySteel AutoFormList Property DBM_ArmoryNordic AutoFormList Property DBM_ArmoryElven AutoFormList Property DBM_ArmoryGlass AutoFormList Property DBM_ArmoryOrcish AutoFormList Property DBM_ArmoryDwarven AutoFormList Property DBM_ArmoryEbony AutoFormList Property DBM_ArmoryDaedric AutoFormList Property DBM_ArmoryDragon AutoFormList Property DBM_ArmoryFalmer AutoFormList Property DBM_ArmoryBlades AutoFormList Property DBM_ArmoryForsworn AutoFormList Property DBM_ArmoryAncientNord AutoFormList Property DBM_ArmoryDawnguard Auto ; DLC1FormList Property DBM_ArmoryStalhrim Auto ; DLC2 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 19, 2017 Share Posted March 19, 2017 (edited) You got the scripts running. Fine.I edited the child script in my first posting, have a look into! Do not do that! fm = ItemList.GetAt(i) as ArmorThat is enough.. fm = ItemList.GetAt(i)Next function seems to be a bit clumpsy: ;------------------------------------------------------------------- FUNCTION Sort_SubList(Actor aRef, Form fmL, ObjectReference caseRef) ; helper for the next three functions ;------------------------------------------------------------------- ; "aRef" is Game.GetPlayer() ; "caseRef" is property ScaleCase, JewelryCase or JewelryCase2 int i = (fmL as FormList).GetSize() ; Sublist = fmL as FormList WHILE (i > 0) i = i - 1 ;;; fm = (fmL as FormList).GetAt(i) as Armor form fm = (fmL as FormList).GetAt(i) IF (fm as Armor) IF (caseRef.GetItemCount(fm) > 0) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, caseRef) ENDIF ENDIF ENDWHILE ENDFUNCTION I am not sure, do you really understand the difference of (script variables and properties) and (function variables). ObjectReference PROPERTY jcREF auto ; SortJewelry() ObjectReference PROPERTY jc2REF auto ; SortJewelry2() ObjectReference PROPERTY scREF auto ; SortScales() ;---------------------------------------------------------------------------------------------------- FUNCTION SortScales(Actor aRef, FormList DisplayList, FormList ItemList, DBM_JewelryDisplayScript ps) ;---------------------------------------------------------------------------------------------------- ; "aRef" should be actionRef, which is Game.GetPlayer() ; property "scRef" was property "ScaleCase" in original script version ; "ps" is property ScaleDisplays int i = ItemList.GetSize() WHILE (i > 0) i = i - 1 form fm = ItemList.GetAt(i) IF (fm as Armor) IF (scRef.GetItemCount(fm) > 0) || Game.IsObjectFavorited(fm) || DBM_ExcludeList.HasForm(fm) ; do nothing // SKSE required ELSEIF (aRef.GetItemCount(fm) > 0) && !aRef.IsEquipped(fm) aRef.RemoveItem(fm, 1, TRUE, scRef) ENDIF ELSEIF (fm as FormList) Sort_SubList(aRef, fm, scRef) ENDIF ENDWHILE ; ScaleDisplays ps.ResetDisplay() ; How much time consume these external functions? ps.UpdateDisplay() ENDFUNCTION Edited March 21, 2017 by ReDragon2013 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 19, 2017 Share Posted March 19, 2017 (edited) Unfortunately, imho you don't really understand the use of actionRef.. EVENT OnActivate(ObjectReference actionRef) IF (actionRef == Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - not the player ENDIF ;--------------------- IF DBM_SortWait.GetValue() == 1 Debug.MessageBox("You must wait for the current sorting operation to complete before removing displays") RETURN ; - STOP - I am busy while sorting! ENDIF ;--------------------- IF (SortMsg.Show() == 1) RETURN ; - STOP - cancel, no sorting ENDIF ;===================== if SortBtn == 0 ; Sort all display items gotostate("busy") ; ### STATE ### DBM_SortWait.SetValue(1) Debug.Notification("All items being displayed, this will take a while..") ;;; actor aRef = Game.GetPlayer() ; FOR UNDERSTANDING: (actionRef as Actor) is already Game.GetPlayer() ; ... some code here ; JEWELRY SORTING SortJewelry(actionRef as Actor, DBM_JewelryUnique, DBM_JewelryUnique, JCREF, JewelryDisplays) Edited March 21, 2017 by ReDragon2013 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 19, 2017 Share Posted March 19, 2017 (edited) You wrote: "Just need to delve in and try to understand WHY it works so much more quickly lol." If you are really interested in better script performance, you have to redesign the script, next is one of that. Bool[] PROPERTY a auto Hidden ; Do not fill in CK! ;----------------------- FUNCTION myF_Test4Mods() ;----------------------- a = new Bool[23] string[] s = new String[23] ; same size as hidden script property "a" s[0] = "SL01AmuletsSkyrim.esp" ; AMULETS OF SKYRIM SORTING s[1] = "Elemental_Dragons.esp" ; ElementalDragons s[2] = "SkyrimsUniqueTreasures.esp" ; SUT COLLECTION s[3] = "BGTrophyHeads.esp" ; TROPHY HEADS s[4] = "BadGremlinsJarHunt.esp" ; JAR COLLECTION s[5] = "AetheriumSwordsnArmor.esp" ; AETHERIUM COLLECTION s[6] = "More Interesting Loot for Skyrim.esp" ; MORE INTERESTING LOOT s[7] = "BGTheCapturedFairies.esp" ; CAPTURED FAIRIES s[8] = "TheMadMasker.esp" ; MAD MASKER s[9] = "BGSomethingFishy.esp" ; FISH DISPLAYS s[10]= "Helgen Reborn.esp" ; HELGEN REBORN s[11]= "Gray Fox Cowl.esm" ; GrayCowl s[12]= "Wyrmstooth.esp" ; WYRMSTOOTH s[13]= "Falskaar.esm" ; FALSKAAR s[14]= "WheelsOfLull.esp" ; WHEELS OF LULL s[15]= "Moonandstar_MAS.esp" ; MOON AND STAR s[16]= "Konahrik_Accoutrements.esp" ; KA displays s[17]= "ArtifactsOfBoethiah.esp" ; AOB Displays s[18]= "escutcheonredwave.esp" ; Oblivion artifacts Displays s[19]= "akskyrimunderground.esp" ; Skyrim Underground s[20]= "PrvtIRoyalArmory.esp" ; Royal Armory s[21]= "Immersive Weapons.esp" ; IWIA s[22]= "Hothtrooper44_ArmorCompilation.esp" ; IWIA int iMax = a.Length int i = 0 WHILE (i < iMax) ; returns value 255, mod not found ; returns value 0, if SKSE is not installed int n = Game.GetModByName(s[i]) a[i] = (n > 0) && (n < 255) ; SKSE required i = i + 1 ENDWHILE ENDFUNCTION Edited March 21, 2017 by ReDragon2013 Link to comment Share on other sites More sharing options...
icecreamassassin Posted March 22, 2017 Author Share Posted March 22, 2017 first, yes I do understand the difference between script properties and function properties, though I may not implement function properties well (hence my request for help in making things more efficient) and in this case I probably tried casting the ActionRef into a script property rather than fixing the application in the function, but that was simply because your original did not work and would not define what ActionRef was properly. I'll check out your edited version of the child script and see if it works. Link to comment Share on other sites More sharing options...
Recommended Posts