Jump to content

How long stay variables with inventory references valid?


JustChill

Recommended Posts

Hey there,

 

I am working on a script that repairs specific damaged items in the players inventory.

 

I use 4 arrays and a Form List which has the allowed items to be repaired.

 

Here some pseudo code (i don't have the full code available currently):

Let arReplaceRef := Ar_Construct "array"
Let arRepairRef := Ar_Construct "array"
 
While sListIndex < ListGetCount FLRepairableItems
Let rListItem := ListGetNthForm FLRepairableItems sListIndex
Let arInventoryRefs := Player.GetInvRefsForItem (variable which contains the current base item from the Form List)
ForEach arCheckItem <- arInventoryRefs
Let rListItem := arCheckItem["value"]
 
--> if the item rListItem has a lower condition than the BaseCondition + WeaponMods that change the condition, it will be added to one of two custom arrays.
--> As seen in the next segment, I either check which kind of item is rListItem, to append it for the specific custom array.
 
if rListItem := "is a replaceable item"
Ar_Append arReplaceRef, rListItem
elseif rList := "is a repairable item"
Ar_Append arRepairRef, rListItem
endif
Loop
Let sListIndex += 1
Loop

I fill my custom arrays with the items to be repaired in the OnActivate block.

 

A few frames later, I will use these arrays again, but I am always told that the array contain NULL references, even though it clearly contains entries (I checked it with Ar_Size).

 

So I am wondering if the refs get invalid after a few frames. :O

 

If so, I simply have to repeat the same code in the OnActivate block to gather the IDs in the GameMode block then.

I use it in OnActivate just to give the user some messagebox regarding the solution of the filling of the arrays.

Yet, I hoped I could continue using the IDs in these arrays, even after a few frames.

 

Kindest regards,

Just Chill

Link to comment
Share on other sites

Case closed, just found a way to verify it myself. :smile:

 

Test 1 screenshot

 

The first 2 boxing gloves get verified directly after they are put into the respective custom array. Index 0 and 1.

The second 2 boxing gloves get verified in the game mode, before the message box is called. Index 0 and 1.

 

 

Test 2 screenshot

 

The 2 <no name>s (invalid references) got verified directly after the message box is closed by player choice and these are the issue. Index 0 and 1 again.

10 is the solution of Ar_Size on the custom array, so it still has items in it, but the references aren't valid anymore.

 

Guess I have to redo the reference gathering then. :/

Link to comment
Share on other sites

Oh... Just realized I've spoke about that function already once. XD

https://forums.nexusmods.com/index.php?/topic/6745852-repairing-multiple-items-by-script/page-4

 

Even though I am now happy with my final solution. :D

 

 

scn GSFarmWashmachineSCRIPT

short sListIndex
float Button
short sCleanerCount
short sMenuPoint
short bDisplay
ref rListItem
array_var arItemRefs
array_var arItemCheck

Begin OnActivate
    if IsActionRef Player
        if sMenuPoint == 0
            if GetStage GSFarmLightQuest < 100
                ShowMessage GSFarmWashmachineNoPower
            elseif GetStage GSFarmWaterQuest < 100
                ShowMessage GSFarmWashmachineNoWater
            elseif player.getitemcount boxdetergent + player.getitemcount abraxocleaner > 0
                  Let sCleanerCount := player.getitemcount boxdetergent + player.getitemcount abraxocleaner
                if sCleanerCount > 15
                    Let sCleanerCount := 15
                endif
                Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Construct "array"
                Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Construct "array"
                While sListIndex < ListGetCount GSfarmClthListDirtyWashable
                    Let rListItem := ListGetNthForm GSfarmClthListDirtyWashable sListIndex
                    if Player.GetItemCount rListItem > 0
                        Let arItemRefs := Player.GetInvRefsForItem rListItem
                        ForEach arItemCheck <- arItemRefs
                            Let rListItem := arItemCheck["value"]
                            if rListItem.GetType == 40
                                if rListItem.GetWeaponItemModEffect 1 == 10
                                    if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button := rListItem.GetWeaponItemModValue1 1
                                        Let Button += rListItem.GetWeaponItemModValue2 1
                                    endif
                                endif
                                if rListItem.GetWeaponItemModEffect 2 == 10
                                    if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button += rListItem.GetWeaponItemModValue1 2
                                        Let Button += rListItem.GetWeaponItemModValue2 2
                                    endif
                                endif
                                if rListItem.GetWeaponItemModEffect 3 == 10
                                    if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button += rListItem.GetWeaponItemModValue1 3
                                        Let Button += rListItem.GetWeaponItemModValue2 3
                                    endif    ;=> Weapon Mod Flags quite tricky. 1 = Weapon Mod 1 installed; 2 = Weapon Mod 2 installed; 4 = Weapon Mod 3 installed.
                                endif    ;=> If Weapon Mod 1 and 2 are installed it's 3. If Weapon Mod 1 and 3 are installed it's 5. If Weapon Mod 2 and 3 are installed it's 6. All Weapon Mods installed is 7.
                                Let Button += rListItem.GetBaseHealth
                                If rListItem.GetItemRefCurrentHealth < Button
                                    if rListItem.IsEquipped == 0
                                        Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rListItem
                                    else
                                        if bDisplay == 0
                                            Let bDisplay := 1
                                        endif
                                    endif
                                endif
                            else
                                if rListItem.GetItemRefCurrentHealth < rListItem.GetBaseHealth
                                    if rListItem == OutfitPrewarCasualwear2Dirty || rListItem == OutfitPrewarCasualwearDirty || rListItem == OutfitPrewarSpringDirty || rListItem == OutfitPrewarSpring2Dirty || rListItem == HatPartyDestroyed
                                        if rListItem.IsEquipped == 0
                                            Ar_Append GSFarmPatchQuest.GSFarmReplaRefs, rListItem
                                        else
                                            if bDisplay == 0
                                                Let bDisplay := 1
                                            endif
                                        endif
                                    else
                                        if rListItem.IsEquipped == 0
                                            Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rListItem
                                        else
                                            if bDisplay == 0
                                                Let bDisplay := 1
                                            endif
                                        endif
                                    endif
                                endif
                            endif
                            Let Button := (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) + (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
                            if Button == 15
                                Break
                            elseif Button == sCleanerCount
                                Break
                            endif
                        Loop
                    endif
                    if Button == 15
                        Let sListIndex := ListGetCount GSfarmClthListDirtyWashable
                        Let Button := 0
                        Let sMenuPoint := 1
                    elseif Button == sCleanerCount
                        Let sListIndex := ListGetCount GSfarmClthListDirtyWashable
                        Let Button := 0
                        Let sMenuPoint := 1
                    elseif (sListindex + 1) == ListGetCount GSfarmClthListDirtyWashable
                        Let sListIndex := ListGetCount GSfarmClthListDirtyWashable
                        Let Button := 0
                        Let sMenuPoint := 1
                    else
                        Let sListIndex += 1
                        Let Button := 0
                    endif
                Loop
            else
                ShowMessage GSFarmWashmachineNoCleaner
            endif
        endif
    endif
END


Begin GameMode
    if sMenuPoint == 1
        if eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) > 0
            MessageboxEx "%{As you cannot jump into the machine as a whole, every equipped washable item will be ignored.%r%r%}There are some items in your inventory that can also be 'washed into better condition'.%rWhich means they will be replaced with cleaner counterparts.%rDo you simply want to wash all items to repair them or do you want to wash and clean them, so they will be replaced by better versions of themselves?%r(Max. 15 at once.)|Wash.|Wash and Clean.|Nothing." bDisplay
            Let sMenuPoint := 2
        elseif eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) > 0
            MessageboxEx "%{As you cannot jump into the machine as a whole, every equipped washable item will be ignored.%r%r%}Do you want to wash all dirty clothes of your inventory?%r(Max. 15 at once.)|Yes.|No." bDisplay
            Let sMenuPoint := 3
        else
            if bDisplay == 0
                MessageEx "No washable items available or all washable items are in best condition."
            else
                MessageEx "The only washable items are equipped."
            endif
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
    elseif sMenuPoint == 2
        Let Button := GetButtonPressed
        if Button == 0
            Let sListIndex := 0
            Let sMenuPoint := 4
        elseif Button == 1
            Call GSFarmGenerateReplairRefs
            Let sListIndex := 0
            Let sMenuPoint := 5
        elseif Button == 2
            Let Button := 0
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
    elseif sMenuPoint == 3
        Let Button := GetButtonPressed
        if Button == 0
            Let sListIndex := 0
            Let sMenuPoint := 5
        elseif Button == 1
            Let Button := 0
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
    elseif sMenuPoint == 4
        Call GSFarmGenerateReplairRefs
        if eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) > 0
            While sListIndex < (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
                Let rListItem := GSFarmPatchQuest.GSFarmWashRefs[sListIndex]
                Ar_Append GSFarmPatchQuest.GSFarmReplaRefs, rListItem
                Let sListIndex += 1
            Loop
        endif
        Let sListIndex := 0
        While sListindex < (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs)
            Let rListItem := GSFarmPatchQuest.GSFarmReplaRefs[sListindex]
            if rListItem.GetBaseObject == OutfitPrewarCasualwear2Dirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarCasualwear2 1 1
            elseif rListItem.GetBaseObject == OutfitPrewarCasualwearDirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarCasualwear 1 1
            elseif rListItem.GetBaseObject == OutfitPrewarSpringDirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarSpring 1 1
            elseif rListItem.GetBaseObject == OutfitPrewarSpring2Dirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarSpring2 1 1
            elseif rListItem.GetBaseObject == HatPartyDestroyed
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem HatParty 1 1
            else
                if rListItem.GetType == 40
                    if rListItem.GetWeaponItemModEffect 1 == 10
                        if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                            Let Button := rListItem.GetWeaponItemModValue1 1
                            Let Button += rListItem.GetWeaponItemModValue2 1
                        endif
                    endif
                    if rListItem.GetWeaponItemModEffect 2 == 10
                        if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                            Let Button += rListItem.GetWeaponItemModValue1 2
                            Let Button += rListItem.GetWeaponItemModValue2 2
                        endif
                    endif
                    if rListItem.GetWeaponItemModEffect 3 == 10
                        if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                            Let Button += rListItem.GetWeaponItemModValue1 3
                            Let Button += rListItem.GetWeaponItemModValue2 3
                        endif
                    endif
                    Let Button += rListItem.GetBaseHealth
                    rListItem.SetCurrentHealth Button                      ;=> At the point this was written, "SetItemRefCurrentHealth" did only go to the base health,
                    rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes ;=> but not over like with weapons using an item mod for better health.
                else                                                              ;=> "SetCurrentHealth" will go over that amount, if calculated correctly.
                    Let Button := rListItem.GetBaseHealth
                    rListItem.SetCurrentHealth Button
                    rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes
                endif
            endif
            Let sListIndex += 1
        Loop
        Let sListIndex := 0
        Let Button := 0
        Let bDisplay := 0
        Let rListItem := 0
        Let sMenuPoint := 6
        Let arItemRefs := Ar_Null
        Let arItemCheck := Ar_Null
        Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
    elseif sMenuPoint == 5
        Call GSFarmGenerateReplairRefs
        if eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) > 0
            While sListIndex < (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs)
                Let rListItem := GSFarmPatchQuest.GSFarmReplaRefs[sListIndex]
                Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rListItem
                Let sListIndex += 1
            Loop
        endif
        Let sListIndex := 0
        While sListindex < (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
            Let rListItem := GSFarmPatchQuest.GSFarmWashRefs[sListIndex]
            if rListItem.GetType == 40
                if rListItem.GetWeaponItemModEffect 1 == 10
                    if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                        Let Button := rListItem.GetWeaponItemModValue1 1
                        Let Button += rListItem.GetWeaponItemModValue2 1
                    endif
                endif
                if rListItem.GetWeaponItemModEffect 2 == 10
                    if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                        Let Button += rListItem.GetWeaponItemModValue1 2
                        Let Button += rListItem.GetWeaponItemModValue2 2
                    endif
                endif
                if rListItem.GetWeaponItemModEffect 3 == 10
                    if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                        Let Button += rListItem.GetWeaponItemModValue1 3
                        Let Button += rListItem.GetWeaponItemModValue2 3
                    endif
                endif
                Let Button += rListItem.GetBaseHealth
                rListItem.SetCurrentHealth Button
                rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes
            else
                Let Button := rListItem.GetBaseHealth
                rListItem.SetCurrentHealth Button
                rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes
            endif
            Let sListIndex += 1
        Loop
        Let sListIndex := 0
        Let Button := 0
        Let bDisplay := 0
        Let rListItem := 0
        Let sMenuPoint := 6
        Let arItemRefs := Ar_Null
        Let arItemCheck := Ar_Null
        Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
    elseif sMenuPoint == 6
        if eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) > 0
            if eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) < sCleanerCount
                Let sCleanerCount := Ar_Size GSFarmPatchQuest.GSFarmWashRefs
            endif
            Let sMenuPoint := Ar_Size GSFarmPatchQuest.GSFarmWashRefs
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
        elseif eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) > 0
            if eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) < sCleanerCount
                Let sCleanerCount := Ar_Size GSFarmPatchQuest.GSFarmReplaRefs
            endif
            Let sMenuPoint := Ar_Size GSFarmPatchQuest.GSFarmReplaRefs
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
        if Player.GetItemCount BoxDetergent > 0
            Let Button := Rand 0, sCleanerCount
            Let Button := ceil Button
            if Button > Player.GetItemCount BoxDetergent
                Let Button := Player.GetItemCount BoxDetergent
                Player.RemoveItem BoxDetergent Button 1
                Let sCleanerCount -= Button
            else
                Player.RemoveItem BoxDetergent Button 1
                Let sCleanerCount -= Button
            endif
            if Player.GetItemCount AbraxoCleaner > 0
                if sCleanerCount > 0
                    Let Button := Rand 0, sCleanerCount
                    Let Button := ceil Button
                    if Button > Player.GetItemCount AbraxoCleaner
                        Let Button := Player.GetItemCount AbraxoCleaner
                        Player.RemoveItem AbraxoCleaner Button 1
                        Let sCleanerCount -= Button
                    else
                        Player.RemoveItem AbraxoCleaner Button 1
                        Let sCleanerCount -= Button
                    endif                    
                endif
            endif
            if sCleanerCount > 0
                if sCleanerCount > Player.GetItemCount BoxDetergent
                    Let Button := Player.GetItemCount BoxDetergent
                    Player.RemoveItem BoxDetergent Button 1
                    Let sCleanerCount -= Button
                    if sCleanerCount > 0
                        Player.RemoveItem AbraxoCleaner sCleanerCount 1
                    endif
                else
                    Player.RemoveItem BoxDetergent sCleanerCount 1                    
                endif
            endif
        elseif Player.GetItemCount AbraxoCleaner > 0
            Player.RemoveItem AbraxoCleaner sCleanerCount 1
        endif
        PlaySound GSFarmhouseWashmachineWASHING 1
        showmessage GSFarmWashmachineWASH sMenuPoint
        Let sMenuPoint := 0
        Let sCleanerCount := 0
    endif
End

 

 

Even though I dislike the UDF to gather inventory references of the very same items as when activating the washing machine. :/

 

[spoiler]Scn GSFarmGenerateReplairRefs
;=> This is stupidly necessary, as inventory references appear to give away a valid result in a (here array) variable, for only one frame in game mode.
short arIndex            ;=> So we have to generate this inventory references again to actually process them finally, instead of determining which kind of
short sWashPowder    ;=> message +box the player sees. oO
float sCounter

ref rItemInList

array_var arInvItemRefs
array_var arCheckItem

Begin Function{}
      Let sWashPowder := player.getitemcount boxdetergent + player.getitemcount abraxocleaner
    if sWashPowder > 15
        Let sWashPowder := 15
    endif
    Let arIndex := 0
    Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Construct "array"
    Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Construct "array"
    While arIndex < ListGetCount GSfarmClthListDirtyWashable
        Let rItemInList := ListGetNthForm GSfarmClthListDirtyWashable arIndex
        if Player.GetItemCount rItemInList > 0
            Let arInvItemRefs := Player.GetInvRefsForItem rItemInList
            ForEach arCheckItem <- arInvItemRefs
                Let rItemInList := arCheckItem["value"]
                if rItemInList.GetType == 40
                    if rItemInList.GetWeaponItemModEffect 1 == 10
                        if rItemInList.GetWeaponRefModFlags == 1 || rItemInList.GetWeaponRefModFlags == 3  || rItemInList.GetWeaponRefModFlags == 5 || rItemInList.GetWeaponRefModFlags == 7
                            Let sCounter := rItemInList.GetWeaponItemModValue1 1
                            Let sCounter += rItemInList.GetWeaponItemModValue2 1
                        endif
                    endif
                    if rItemInList.GetWeaponItemModEffect 2 == 10
                        if rItemInList.GetWeaponRefModFlags == 2 || rItemInList.GetWeaponRefModFlags == 3 || rItemInList.GetWeaponRefModFlags == 6 || rItemInList.GetWeaponRefModFlags == 7
                            Let sCounter += rItemInList.GetWeaponItemModValue1 2
                            Let sCounter += rItemInList.GetWeaponItemModValue2 2
                        endif
                    endif
                    if rItemInList.GetWeaponItemModEffect 3 == 10
                        if rItemInList.GetWeaponRefModFlags == 4 || rItemInList.GetWeaponRefModFlags == 5 || rItemInList.GetWeaponRefModFlags == 6 || rItemInList.GetWeaponRefModFlags == 7
                            Let sCounter += rItemInList.GetWeaponItemModValue1 3
                            Let sCounter += rItemInList.GetWeaponItemModValue2 3
                        endif    ;=> Weapon Mod Flags quite tricky. 1 = Weapon Mod 1 installed; 2 = Weapon Mod 2 installed; 4 = Weapon Mod 3 installed.
                    endif    ;=> If Weapon Mod 1 and 2 are installed it's 3. If Weapon Mod 1 and 3 are installed it's 5. If Weapon Mod 2 and 3 are installed it's 6. All Weapon Mods installed is 7.
                    Let sCounter += rItemInList.GetBaseHealth
                    If rItemInList.GetItemRefCurrentHealth < sCounter
                        if rItemInList.IsEquipped == 0
                            Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rItemInList
                        endif
                    endif
                else
                    if rItemInList.GetItemRefCurrentHealth < rItemInList.GetBaseHealth
                        if rItemInList == OutfitPrewarCasualwear2Dirty || rItemInList == OutfitPrewarCasualwearDirty || rItemInList == OutfitPrewarSpringDirty || rItemInList == OutfitPrewarSpring2Dirty || rItemInList == HatPartyDestroyed
                            if rItemInList.IsEquipped == 0
                                Ar_Append GSFarmPatchQuest.GSFarmReplaRefs, rItemInList
                            endif
                        else
                            if rItemInList.IsEquipped == 0
                                Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rItemInList
                            endif
                        endif
                    endif
                endif
                Let sCounter := (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) + (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
                if sCounter == 15
                    Break
                elseif sCounter == sWashPowder
                    Break
                endif
            Loop
        endif
        if sCounter == 15
            Let arIndex := ListGetCount GSfarmClthListDirtyWashable
            Let sCounter := 0
            Let sWashPowder := 0
            Let arInvItemRefs := Ar_Null
            Let arCheckItem := Ar_Null
        elseif sCounter == sWashPowder
            Let arIndex := ListGetCount GSfarmClthListDirtyWashable
            Let sCounter := 0
            Let sWashPowder := 0
            Let arInvItemRefs := Ar_Null
            Let arCheckItem := Ar_Null
        elseif (arIndex + 1) == ListGetCount GSfarmClthListDirtyWashable
            Let arIndex := ListGetCount GSfarmClthListDirtyWashable
            Let sCounter := 0
            Let sWashPowder := 0
            Let arInvItemRefs := Ar_Null
            Let arCheckItem := Ar_Null
        else
            Let arIndex += 1
            Let sCounter := 0
        endif
    Loop
End

 

Yet, it just works. :psyduck:

Link to comment
Share on other sites

Oh wow, I somehow completely broke the post above.
Cannot edit or quote it. oO




Trying again....

.................................





Oh... Just realized I've spoke about that function already once. XD
https://forums.nexus...y-script/page-4

Even though I am now happy with my final solution. :D

 

scn GSFarmWashmachineSCRIPT

short sListIndex
float Button
short sCleanerCount
short sMenuPoint
short bDisplay
ref rListItem
array_var arItemRefs
array_var arItemCheck

Begin OnActivate
    if IsActionRef Player
        if sMenuPoint == 0
            if GetStage GSFarmLightQuest < 100
                ShowMessage GSFarmWashmachineNoPower
            elseif GetStage GSFarmWaterQuest < 100
                ShowMessage GSFarmWashmachineNoWater
            elseif player.getitemcount boxdetergent + player.getitemcount abraxocleaner > 0
                  Let sCleanerCount := player.getitemcount boxdetergent + player.getitemcount abraxocleaner
                if sCleanerCount > 15
                    Let sCleanerCount := 15
                endif
                Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Construct "array"
                Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Construct "array"
                While sListIndex < ListGetCount GSfarmClthListDirtyWashable
                    Let rListItem := ListGetNthForm GSfarmClthListDirtyWashable sListIndex
                    if Player.GetItemCount rListItem > 0
                        Let arItemRefs := Player.GetInvRefsForItem rListItem
                        ForEach arItemCheck <- arItemRefs
                            Let rListItem := arItemCheck["value"]
                            if rListItem.GetType == 40
                                if rListItem.GetWeaponItemModEffect 1 == 10
                                    if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button := rListItem.GetWeaponItemModValue1 1
                                        Let Button += rListItem.GetWeaponItemModValue2 1
                                    endif
                                endif
                                if rListItem.GetWeaponItemModEffect 2 == 10
                                    if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button += rListItem.GetWeaponItemModValue1 2
                                        Let Button += rListItem.GetWeaponItemModValue2 2
                                    endif
                                endif
                                if rListItem.GetWeaponItemModEffect 3 == 10
                                    if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button += rListItem.GetWeaponItemModValue1 3
                                        Let Button += rListItem.GetWeaponItemModValue2 3
                                    endif    ;=> Weapon Mod Flags quite tricky. 1 = Weapon Mod 1 installed; 2 = Weapon Mod 2 installed; 4 = Weapon Mod 3 installed.
                                endif    ;=> If Weapon Mod 1 and 2 are installed it's 3. If Weapon Mod 1 and 3 are installed it's 5. If Weapon Mod 2 and 3 are installed it's 6. All Weapon Mods installed is 7.'
                                Let Button += rListItem.GetBaseHealth
                                If rListItem.GetItemRefCurrentHealth < Button
                                    if rListItem.IsEquipped == 0
                                        Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rListItem
                                    else
                                        if bDisplay == 0
                                            Let bDisplay := 1
                                        endif
                                    endif
                                endif
                            else
                                if rListItem.GetItemRefCurrentHealth < rListItem.GetBaseHealth
                                    if rListItem == OutfitPrewarCasualwear2Dirty || rListItem == OutfitPrewarCasualwearDirty || rListItem == OutfitPrewarSpringDirty || rListItem == OutfitPrewarSpring2Dirty || rListItem == HatPartyDestroyed
                                        if rListItem.IsEquipped == 0
                                            Ar_Append GSFarmPatchQuest.GSFarmReplaRefs, rListItem
                                        else
                                            if bDisplay == 0
                                                Let bDisplay := 1
                                            endif
                                        endif
                                    else
                                        if rListItem.IsEquipped == 0
                                            Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rListItem
                                        else
                                            if bDisplay == 0
                                                Let bDisplay := 1
                                            endif
                                        endif
                                    endif
                                endif
                            endif
                            Let Button := (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) + (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
                            if Button == 15
                                Break
                            elseif Button == sCleanerCount
                                Break
                            endif
                        Loop
                    endif
                    if Button == 15
                        Let sListIndex := ListGetCount GSfarmClthListDirtyWashable
                        Let Button := 0
                        Let sMenuPoint := 1
                    elseif Button == sCleanerCount
                        Let sListIndex := ListGetCount GSfarmClthListDirtyWashable
                        Let Button := 0
                        Let sMenuPoint := 1
                    elseif (sListindex + 1) == ListGetCount GSfarmClthListDirtyWashable
                        Let sListIndex := ListGetCount GSfarmClthListDirtyWashable
                        Let Button := 0
                        Let sMenuPoint := 1
                    else
                        Let sListIndex += 1
                        Let Button := 0
                    endif
                Loop
            else
                ShowMessage GSFarmWashmachineNoCleaner
            endif
        endif
    endif
END


Begin GameMode
    if sMenuPoint == 1
        if eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) > 0
            MessageboxEx "%{As you cannot jump into the machine as a whole, every equipped washable item will be ignored.%r%r%}There are some items in your inventory that can also be 'washed into better condition'.%rWhich means they will be replaced with cleaner counterparts.%rDo you simply want to wash all items to repair them or do you want to wash and clean them, so they will be replaced by better versions of themselves?%r(Max. 15 at once.)|Wash.|Wash and Clean.|Nothing." bDisplay
            Let sMenuPoint := 2
        elseif eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) > 0
            MessageboxEx "%{As you cannot jump into the machine as a whole, every equipped washable item will be ignored.%r%r%}Do you want to wash all dirty clothes of your inventory?%r(Max. 15 at once.)|Yes.|No." bDisplay
            Let sMenuPoint := 3
        else
            if bDisplay == 0
                MessageEx "No washable items available or all washable items are in best condition."
            else
                MessageEx "The only washable items are equipped."
            endif
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
    elseif sMenuPoint == 2
        Let Button := GetButtonPressed
        if Button == 0
            Let sListIndex := 0
            Let sMenuPoint := 4
        elseif Button == 1
            Call GSFarmGenerateReplairRefs
            Let sListIndex := 0
            Let sMenuPoint := 5
        elseif Button == 2
            Let Button := 0
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
    elseif sMenuPoint == 3
        Let Button := GetButtonPressed
        if Button == 0
            Let sListIndex := 0
            Let sMenuPoint := 5
        elseif Button == 1
            Let Button := 0
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
    elseif sMenuPoint == 4
        Call GSFarmGenerateReplairRefs
        if eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) > 0
            While sListIndex < (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
                Let rListItem := GSFarmPatchQuest.GSFarmWashRefs[sListIndex]
                Ar_Append GSFarmPatchQuest.GSFarmReplaRefs, rListItem
                Let sListIndex += 1
            Loop
        endif
        Let sListIndex := 0
        While sListindex < (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs)
            Let rListItem := GSFarmPatchQuest.GSFarmReplaRefs[sListindex]
            if rListItem.GetBaseObject == OutfitPrewarCasualwear2Dirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarCasualwear2 1 1
            elseif rListItem.GetBaseObject == OutfitPrewarCasualwearDirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarCasualwear 1 1
            elseif rListItem.GetBaseObject == OutfitPrewarSpringDirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarSpring 1 1
            elseif rListItem.GetBaseObject == OutfitPrewarSpring2Dirty
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem OutfitPrewarSpring2 1 1
            elseif rListItem.GetBaseObject == HatPartyDestroyed
                rListItem.RemoveMeIRAlt 1
                GSfarmWashedClothes.AddItem HatParty 1 1
            else
                if rListItem.GetType == 40
                    if rListItem.GetWeaponItemModEffect 1 == 10
                        if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                            Let Button := rListItem.GetWeaponItemModValue1 1
                            Let Button += rListItem.GetWeaponItemModValue2 1
                        endif
                    endif
                    if rListItem.GetWeaponItemModEffect 2 == 10
                        if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                            Let Button += rListItem.GetWeaponItemModValue1 2
                            Let Button += rListItem.GetWeaponItemModValue2 2
                        endif
                    endif
                    if rListItem.GetWeaponItemModEffect 3 == 10
                        if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                            Let Button += rListItem.GetWeaponItemModValue1 3
                            Let Button += rListItem.GetWeaponItemModValue2 3
                        endif
                    endif
                    Let Button += rListItem.GetBaseHealth
                    rListItem.SetCurrentHealth Button                      ;=> At the point this was written, "SetItemRefCurrentHealth" did only go to the base health,
                    rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes ;=> but not over like with weapons using an item mod for better health.
                else                                                              ;=> "SetCurrentHealth" will go over that amount, if calculated correctly.
                    Let Button := rListItem.GetBaseHealth
                    rListItem.SetCurrentHealth Button
                    rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes
                endif
            endif
            Let sListIndex += 1
        Loop
        Let sListIndex := 0
        Let Button := 0
        Let bDisplay := 0
        Let rListItem := 0
        Let sMenuPoint := 6
        Let arItemRefs := Ar_Null
        Let arItemCheck := Ar_Null
        Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
    elseif sMenuPoint == 5
        Call GSFarmGenerateReplairRefs
        if eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) > 0
            While sListIndex < (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs)
                Let rListItem := GSFarmPatchQuest.GSFarmReplaRefs[sListIndex]
                Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rListItem
                Let sListIndex += 1
            Loop
        endif
        Let sListIndex := 0
        While sListindex < (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
            Let rListItem := GSFarmPatchQuest.GSFarmWashRefs[sListIndex]
            if rListItem.GetType == 40
                if rListItem.GetWeaponItemModEffect 1 == 10
                    if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                        Let Button := rListItem.GetWeaponItemModValue1 1
                        Let Button += rListItem.GetWeaponItemModValue2 1
                    endif
                endif
                if rListItem.GetWeaponItemModEffect 2 == 10
                    if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                        Let Button += rListItem.GetWeaponItemModValue1 2
                        Let Button += rListItem.GetWeaponItemModValue2 2
                    endif
                endif
                if rListItem.GetWeaponItemModEffect 3 == 10
                    if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                        Let Button += rListItem.GetWeaponItemModValue1 3
                        Let Button += rListItem.GetWeaponItemModValue2 3
                    endif
                endif
                Let Button += rListItem.GetBaseHealth
                rListItem.SetCurrentHealth Button
                rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes
            else
                Let Button := rListItem.GetBaseHealth
                rListItem.SetCurrentHealth Button
                rListItem.RemoveMeIRAlt 1 0 GSfarmWashedClothes
            endif
            Let sListIndex += 1
        Loop
        Let sListIndex := 0
        Let Button := 0
        Let bDisplay := 0
        Let rListItem := 0
        Let sMenuPoint := 6
        Let arItemRefs := Ar_Null
        Let arItemCheck := Ar_Null
        Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
    elseif sMenuPoint == 6
        if eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) > 0
            if eval (Ar_Size GSFarmPatchQuest.GSFarmWashRefs) < sCleanerCount
                Let sCleanerCount := Ar_Size GSFarmPatchQuest.GSFarmWashRefs
            endif
            Let sMenuPoint := Ar_Size GSFarmPatchQuest.GSFarmWashRefs
            Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Null
        elseif eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) > 0
            if eval (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) < sCleanerCount
                Let sCleanerCount := Ar_Size GSFarmPatchQuest.GSFarmReplaRefs
            endif
            Let sMenuPoint := Ar_Size GSFarmPatchQuest.GSFarmReplaRefs
            Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Null
        endif
        if Player.GetItemCount BoxDetergent > 0
            Let Button := Rand 0, sCleanerCount
            Let Button := ceil Button
            if Button > Player.GetItemCount BoxDetergent
                Let Button := Player.GetItemCount BoxDetergent
                Player.RemoveItem BoxDetergent Button 1
                Let sCleanerCount -= Button
            else
                Player.RemoveItem BoxDetergent Button 1
                Let sCleanerCount -= Button
            endif
            if Player.GetItemCount AbraxoCleaner > 0
                if sCleanerCount > 0
                    Let Button := Rand 0, sCleanerCount
                    Let Button := ceil Button
                    if Button > Player.GetItemCount AbraxoCleaner
                        Let Button := Player.GetItemCount AbraxoCleaner
                        Player.RemoveItem AbraxoCleaner Button 1
                        Let sCleanerCount -= Button
                    else
                        Player.RemoveItem AbraxoCleaner Button 1
                        Let sCleanerCount -= Button
                    endif                    
                endif
            endif
            if sCleanerCount > 0
                if sCleanerCount > Player.GetItemCount BoxDetergent
                    Let Button := Player.GetItemCount BoxDetergent
                    Player.RemoveItem BoxDetergent Button 1
                    Let sCleanerCount -= Button
                    if sCleanerCount > 0
                        Player.RemoveItem AbraxoCleaner sCleanerCount 1
                    endif
                else
                    Player.RemoveItem BoxDetergent sCleanerCount 1                    
                endif
            endif
        elseif Player.GetItemCount AbraxoCleaner > 0
            Player.RemoveItem AbraxoCleaner sCleanerCount 1
        endif
        PlaySound GSFarmhouseWashmachineWASHING 1
        showmessage GSFarmWashmachineWASH sMenuPoint
        Let sMenuPoint := 0
        Let sCleanerCount := 0
    endif
End





Even though I dislike the UDF to gather inventory references of the very same items as when activating the washing machine. :/

Scn GSFarmGenerateReplairRefs
;=> This is stupidly necessary, as inventory references appear to give away a valid result in a (here array) variable, for only one frame in game mode.
short arIndex            ;=> So we have to generate this inventory references again to actually process them finally, instead of determining which kind of
short sWashPowder    ;=> message +box the player sees. oO
float sCounter

ref rItemInList

array_var arInvItemRefs
array_var arCheckItem

Begin Function{}
      Let sWashPowder := player.getitemcount boxdetergent + player.getitemcount abraxocleaner
    if sWashPowder > 15
        Let sWashPowder := 15
    endif
    Let arIndex := 0
    Let GSFarmPatchQuest.GSFarmReplaRefs := Ar_Construct "array"
    Let GSFarmPatchQuest.GSFarmWashRefs := Ar_Construct "array"
    While arIndex < ListGetCount GSfarmClthListDirtyWashable
        Let rItemInList := ListGetNthForm GSfarmClthListDirtyWashable arIndex
        if Player.GetItemCount rItemInList > 0
            Let arInvItemRefs := Player.GetInvRefsForItem rItemInList
            ForEach arCheckItem <- arInvItemRefs
                Let rItemInList := arCheckItem["value"]
                if rItemInList.GetType == 40
                    if rItemInList.GetWeaponItemModEffect 1 == 10
                        if rItemInList.GetWeaponRefModFlags == 1 || rItemInList.GetWeaponRefModFlags == 3  || rItemInList.GetWeaponRefModFlags == 5 || rItemInList.GetWeaponRefModFlags == 7
                            Let sCounter := rItemInList.GetWeaponItemModValue1 1
                            Let sCounter += rItemInList.GetWeaponItemModValue2 1
                        endif
                    endif
                    if rItemInList.GetWeaponItemModEffect 2 == 10
                        if rItemInList.GetWeaponRefModFlags == 2 || rItemInList.GetWeaponRefModFlags == 3 || rItemInList.GetWeaponRefModFlags == 6 || rItemInList.GetWeaponRefModFlags == 7
                            Let sCounter += rItemInList.GetWeaponItemModValue1 2
                            Let sCounter += rItemInList.GetWeaponItemModValue2 2
                        endif
                    endif
                    if rItemInList.GetWeaponItemModEffect 3 == 10
                        if rItemInList.GetWeaponRefModFlags == 4 || rItemInList.GetWeaponRefModFlags == 5 || rItemInList.GetWeaponRefModFlags == 6 || rItemInList.GetWeaponRefModFlags == 7
                            Let sCounter += rItemInList.GetWeaponItemModValue1 3
                            Let sCounter += rItemInList.GetWeaponItemModValue2 3
                        endif    ;=> Weapon Mod Flags quite tricky. 1 = Weapon Mod 1 installed; 2 = Weapon Mod 2 installed; 4 = Weapon Mod 3 installed.
                    endif    ;=> If Weapon Mod 1 and 2 are installed it's 3. If Weapon Mod 1 and 3 are installed it's 5. If Weapon Mod 2 and 3 are installed it's 6. All Weapon Mods installed is 7.'
                    Let sCounter += rItemInList.GetBaseHealth
                    If rItemInList.GetItemRefCurrentHealth < sCounter
                        if rItemInList.IsEquipped == 0
                            Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rItemInList
                        endif
                    endif
                else
                    if rItemInList.GetItemRefCurrentHealth < rItemInList.GetBaseHealth
                        if rItemInList == OutfitPrewarCasualwear2Dirty || rItemInList == OutfitPrewarCasualwearDirty || rItemInList == OutfitPrewarSpringDirty || rItemInList == OutfitPrewarSpring2Dirty || rItemInList == HatPartyDestroyed
                            if rItemInList.IsEquipped == 0
                                Ar_Append GSFarmPatchQuest.GSFarmReplaRefs, rItemInList
                            endif
                        else
                            if rItemInList.IsEquipped == 0
                                Ar_Append GSFarmPatchQuest.GSFarmWashRefs, rItemInList
                            endif
                        endif
                    endif
                endif
                Let sCounter := (Ar_Size GSFarmPatchQuest.GSFarmReplaRefs) + (Ar_Size GSFarmPatchQuest.GSFarmWashRefs)
                if sCounter == 15
                    Break
                elseif sCounter == sWashPowder
                    Break
                endif
            Loop
        endif
        if sCounter == 15
            Let arIndex := ListGetCount GSfarmClthListDirtyWashable
            Let sCounter := 0
            Let sWashPowder := 0
            Let arInvItemRefs := Ar_Null
            Let arCheckItem := Ar_Null
        elseif sCounter == sWashPowder
            Let arIndex := ListGetCount GSfarmClthListDirtyWashable
            Let sCounter := 0
            Let sWashPowder := 0
            Let arInvItemRefs := Ar_Null
            Let arCheckItem := Ar_Null
        elseif (arIndex + 1) == ListGetCount GSfarmClthListDirtyWashable
            Let arIndex := ListGetCount GSfarmClthListDirtyWashable
            Let sCounter := 0
            Let sWashPowder := 0
            Let arInvItemRefs := Ar_Null
            Let arCheckItem := Ar_Null
        else
            Let arIndex += 1
            Let sCounter := 0
        endif
    Loop
End



Yet, it just works. :psyduck:












Ok this one looks better, even though I still have issues with. oO

I would be happy if a mod can delete the previous post. Something broke there. :/
Psyduck it's you!

Link to comment
Share on other sites

Just realized that "GetInvRefsForItem" doesn't handle stacked items, but only adds one reference into my arrays, when there is an item stack (e.g. 9mm Pistol (3)).

When this reference is processed the game freezes. :AWKWARD:

 

Gotta try to tinker around finding some fix. oO

Link to comment
Share on other sites

I've fixed it.

 

I've either redone a whole lot of the script and was able to get rid of the two extra arrays and the whole UDF.

Instead, I simply use a hidden container (located inside the washmachine XD) where all washable items get moved into.

If the player washes them, they get into the big barrel on the washine machine in repaired condition.

Otherwise they are moved back into the player's inventory.

 

Thanks to Jazz is Paris' JIP LN NVSE function RemoveMeIRAlt, I was able to deal with stacks easily by using GetRefCount onto the stack reference and then just removing exactly the necessary amount from the stack.

I either tried out the SetItemRefCurrentHealth as previously I had issues with weapons that use weapon mods for increasing the condition.

Appears that one is way more stable than SetCurrentHealth and finally works either with condition over 100% (as by the mods).

 

 

 

scn GSFarmWashmachineSCRIPT

short sListIndex
float Button
short sCleanerCount
short sWashCount
short sMenuPoint
short bDisplay
ref rListItem
array_var arItemRefs
array_var arItemCheck

Begin OnActivate
    if IsActionRef Player
        if sMenuPoint == 0
            if GetStage GSFarmLightQuest < 100
                ShowMessage GSFarmWashmachineNoPower
            elseif GetStage GSFarmWaterQuest < 100
                ShowMessage GSFarmWashmachineNoWater
            elseif player.getitemcount boxdetergent + player.getitemcount abraxocleaner > 0
                  Let sCleanerCount := player.getitemcount boxdetergent + player.getitemcount abraxocleaner
                if sCleanerCount > 15
                    Let sCleanerCount := 15
                endif
                While sListIndex < ListGetCount GSfarmClthListDirtyWashable
                    Let rListItem := ListGetNthForm GSfarmClthListDirtyWashable sListIndex
                    if Player.GetItemCount rListItem > 0
                        Let arItemRefs := Player.GetInvRefsForItem rListItem
                        ForEach arItemCheck <- arItemRefs
                            Let rListItem := arItemCheck["value"]
                            if rListItem.GetType == 40
                                if rListItem.GetWeaponItemModEffect 1 == 10
                                    if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button := rListItem.GetWeaponItemModValue1 1
                                        Let Button += rListItem.GetWeaponItemModValue2 1
                                    endif
                                endif
                                if rListItem.GetWeaponItemModEffect 2 == 10
                                    if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button += rListItem.GetWeaponItemModValue1 2
                                        Let Button += rListItem.GetWeaponItemModValue2 2
                                    endif
                                endif
                                if rListItem.GetWeaponItemModEffect 3 == 10
                                    if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                                        Let Button += rListItem.GetWeaponItemModValue1 3
                                        Let Button += rListItem.GetWeaponItemModValue2 3
                                    endif    ;=> Weapon Mod Flags quite tricky. 1 = Weapon Mod 1 installed; 2 = Weapon Mod 2 installed; 4 = Weapon Mod 3 installed.
                                endif    ;=> If Weapon Mod 1 and 2 are installed it's 3. If Weapon Mod 1 and 3 are installed it's 5. If Weapon Mod 2 and 3 are installed it's 6. All Weapon Mods installed is 7.'
                                Let Button += rListItem.GetBaseHealth
                                If rListItem.GetItemRefCurrentHealth < Button
                                    if rListItem.IsEquipped == 0
                                        Let Button := rListItem.GetRefCount
                                        if Button > (sCleanerCount - sWashCount)
                                            Let Button := sCleanerCount - sWashCount
                                        endif
                                        Let sWashCount += Button
                                        rListItem.RemoveMeIRAlt Button 0 GSFarmWashedClothes
                                        if sMenuPoint == 0
                                            Let sMenuPoint := 1
                                        endif
                                    else
                                        if bDisplay == 0
                                            Let bDisplay := 1
                                        elseif bDisplay == 1
                                            Let bDisplay := 2
                                        endif
                                    endif
                                endif
                            else
                                if rListItem.GetItemRefCurrentHealth < rListItem.GetBaseHealth
                                    if rListItem.IsEquipped == 0
                                        Let Button := rListItem.GetRefCount
                                        if Button > (sCleanerCount - sWashCount)
                                            Let Button := sCleanerCount - sWashCount
                                        endif
                                        Let sWashCount += Button
                                        rListItem.RemoveMeIRAlt Button 0 GSFarmWashedClothes
                                        if sMenuPoint != 2
                                            if rListItem.GetBaseObject == OutfitPrewarCasualwear2Dirty
                                                Let sMenuPoint := 2
                                            elseif rListItem.GetBaseObject == OutfitPrewarCasualwearDirty
                                                Let sMenuPoint := 2
                                            elseif rListItem.GetBaseObject == OutfitPrewarSpringDirty
                                                Let sMenuPoint := 2
                                            elseif rListItem.GetBaseObject == OutfitPrewarSpring2Dirty
                                                Let sMenuPoint := 2
                                            elseif rListItem.GetBaseObject == HatPartyDestroyed
                                                Let sMenuPoint := 2
                                            endif
                                        endif
                                    else
                                        if bDisplay == 0
                                            Let bDisplay := 1
                                        elseif bDisplay == 1
                                            Let bDisplay := 2
                                        endif
                                    endif
                                endif
                            endif
                            Let Button := 0
                            if sWashCount == 15
                                Break
                            elseif sWashCount == sCleanerCount
                                Break
                            endif
                        Loop
                    endif
                    if sWashCount == 15
                        Break
                    elseif sWashCount == sCleanerCount
                        Break
                    else
                        Let sListIndex += 1
                    endif
                Loop
                if GSFarmWashedClothes.GetContainerInventoryCount == 0
                    if bDisplay == 0
                        MessageEx "No washable items available or all washable items are in best condition."
                    elseif bDisplay == 1
                        MessageEx "The only washable item is equipped."
                    elseif bDisplay == 2
                        MessageEx "The only washable items are equipped."    
                    endif
                    Let bDisplay := 0
                    Let sListIndex := 0
                    Let rListItem := 0
                    Let sCleanerCount := 0
                    Let sWashCount := 0
                    Let sMenuPoint := 0
                    Let arItemRefs := Ar_Null
                    Let arItemCheck := Ar_Null
                endif
            else
                ShowMessage GSFarmWashmachineNoCleaner
            endif
        endif
    endif
END



Begin GameMode
    if sMenuPoint == 1
        MessageboxEx "%{As you cannot jump into the machine as a whole, every equipped washable item will be ignored.%r%r%}Do you want to wash all dirty clothes of your inventory?%r(Max. 15 at once.)|Yes.|No." bDisplay
        Let sMenuPoint := 11
    elseif sMenuPoint == 2
        MessageboxEx "%{As you cannot jump into the machine as a whole, every equipped washable item will be ignored.%r%r%}There are some items in your inventory that can also be 'washed into better condition'.%rWhich means they will be replaced with cleaner counterparts.%rDo you simply want to wash all items to repair them or do you want to wash and clean them, so they will be replaced by better versions of themselves?%r(Max. 15 at once.)|Wash.|Wash and Clean.|Nothing." bDisplay
        Let sMenuPoint := 22
    elseif sMenuPoint == 11
        Let Button := GetButtonPressed
        if Button == 0
            Let Button := 0
            Let sMenuPoint := 12
        elseif Button == 1
            Let Button := 0
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sWashCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            GSFarmWashedClothes.RemoveAllItems Player 1 1
        endif
    elseif sMenuPoint == 22
        Let Button := GetButtonPressed
        if Button == 0
            Let Button := 0
            Let sMenuPoint := 23
        elseif Button == 1
            Let Button := 0
            Let sMenuPoint := 12
        elseif Button == 2
            Let Button := 0
            Let bDisplay := 0
            Let sListIndex := 0
            Let rListItem := 0
            Let sCleanerCount := 0
            Let sWashCount := 0
            Let sMenuPoint := 0
            Let arItemRefs := Ar_Null
            Let arItemCheck := Ar_Null
            GSFarmWashedClothes.RemoveAllItems Player 1 1
        endif
    elseif sMenuPoint == 12
        Let arItemRefs := GSfarmWashedClothes.GetAllItemRefs
        ForEach arItemCheck <- arItemRefs
            Let rListItem := arItemCheck["value"]
            if rListItem.GetType == 40
                if rListItem.GetWeaponItemModEffect 1 == 10
                    if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                        Let Button := rListItem.GetWeaponItemModValue1 1
                        Let Button += rListItem.GetWeaponItemModValue2 1
                    endif
                endif
                if rListItem.GetWeaponItemModEffect 2 == 10
                    if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                        Let Button += rListItem.GetWeaponItemModValue1 2
                        Let Button += rListItem.GetWeaponItemModValue2 2
                    endif
                endif
                if rListItem.GetWeaponItemModEffect 3 == 10
                    if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                        Let Button += rListItem.GetWeaponItemModValue1 3
                        Let Button += rListItem.GetWeaponItemModValue2 3
                    endif
                endif
                Let Button += rListItem.GetBaseHealth
                rListItem.SetItemRefCurrentHealth Button              
            else
                Let Button := rListItem.GetBaseHealth
                rListItem.SetItemRefCurrentHealth Button
            endif
        Loop
        Let sMenuPoint := 6
    elseif sMenuPoint == 23
        Let arItemRefs := GSfarmWashedClothes.GetAllItemRefs
        ForEach arItemCheck <- arItemRefs
            Let rListItem := arItemCheck["value"]
            if rListItem.GetBaseObject == OutfitPrewarCasualwear2Dirty
                Let Button := rListItem.GetRefCount
                rListItem.RemoveMeIRAlt Button
                GSfarmWashedClothes.AddItem OutfitPrewarCasualwear2 Button 1
            elseif rListItem.GetBaseObject == OutfitPrewarCasualwearDirty
                Let Button := rListItem.GetRefCount
                rListItem.RemoveMeIRAlt Button
                GSfarmWashedClothes.AddItem OutfitPrewarCasualwear Button 1
            elseif rListItem.GetBaseObject == OutfitPrewarSpringDirty
                Let Button := rListItem.GetRefCount
                rListItem.RemoveMeIRAlt Button
                GSfarmWashedClothes.AddItem OutfitPrewarSpring Button 1
            elseif rListItem.GetBaseObject == OutfitPrewarSpring2Dirty
                Let Button := rListItem.GetRefCount
                rListItem.RemoveMeIRAlt Button
                GSfarmWashedClothes.AddItem OutfitPrewarSpring2 Button 1
            elseif rListItem.GetBaseObject == HatPartyDestroyed
                Let Button := rListItem.GetRefCount
                rListItem.RemoveMeIRAlt Button
                GSfarmWashedClothes.AddItem HatParty Button 1
            else
                if rListItem.GetType == 40
                    if rListItem.GetWeaponItemModEffect 1 == 10
                        if rListItem.GetWeaponRefModFlags == 1 || rListItem.GetWeaponRefModFlags == 3  || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 7
                            Let Button := rListItem.GetWeaponItemModValue1 1
                            Let Button += rListItem.GetWeaponItemModValue2 1
                        endif
                    endif
                    if rListItem.GetWeaponItemModEffect 2 == 10
                        if rListItem.GetWeaponRefModFlags == 2 || rListItem.GetWeaponRefModFlags == 3 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                            Let Button += rListItem.GetWeaponItemModValue1 2
                            Let Button += rListItem.GetWeaponItemModValue2 2
                        endif
                    endif
                    if rListItem.GetWeaponItemModEffect 3 == 10
                        if rListItem.GetWeaponRefModFlags == 4 || rListItem.GetWeaponRefModFlags == 5 || rListItem.GetWeaponRefModFlags == 6 || rListItem.GetWeaponRefModFlags == 7
                            Let Button += rListItem.GetWeaponItemModValue1 3
                            Let Button += rListItem.GetWeaponItemModValue2 3
                        endif
                    endif
                    Let Button += rListItem.GetBaseHealth
                    rListItem.SetItemRefCurrentHealth Button
                else
                    Let Button := rListItem.GetBaseHealth
                    rListItem.SetItemRefCurrentHealth Button
                endif
            endif
        Loop
        Let sMenuPoint := 6
    elseif sMenuPoint == 6
        if sWashCount < sCleanerCount
            Let sCleanerCount := sWashCount
        endif
        if Player.GetItemCount BoxDetergent > 0
            Let Button := Rand 0, sCleanerCount
            Let Button := ceil Button
            if Button > Player.GetItemCount BoxDetergent
                Let Button := Player.GetItemCount BoxDetergent
                Player.RemoveItem BoxDetergent Button 1
                Let sCleanerCount -= Button
            else
                Player.RemoveItem BoxDetergent Button 1
                Let sCleanerCount -= Button
            endif
            if Player.GetItemCount AbraxoCleaner > 0
                if sCleanerCount > 0
                    Let Button := Rand 0, sCleanerCount
                    Let Button := ceil Button
                    if Button > Player.GetItemCount AbraxoCleaner
                        Let Button := Player.GetItemCount AbraxoCleaner
                        Player.RemoveItem AbraxoCleaner Button 1
                        Let sCleanerCount -= Button
                    else
                        Player.RemoveItem AbraxoCleaner Button 1
                        Let sCleanerCount -= Button
                    endif                    
                endif
            endif
            if sCleanerCount > 0
                if sCleanerCount > Player.GetItemCount BoxDetergent
                    Let Button := Player.GetItemCount BoxDetergent
                    Player.RemoveItem BoxDetergent Button 1
                    Let sCleanerCount -= Button
                    if sCleanerCount > 0
                        Player.RemoveItem AbraxoCleaner sCleanerCount 1
                    endif
                else
                    Player.RemoveItem BoxDetergent sCleanerCount 1                    
                endif
            endif
        elseif Player.GetItemCount AbraxoCleaner > 0
            Player.RemoveItem AbraxoCleaner sCleanerCount 1
        endif
        PlaySound GSFarmhouseWashmachineWASHING 1
        showmessage GSFarmWashmachineWASH sWashCount
        GSFarmWashedClothes.RemoveAllItems GSFarmWashStorage
        Let sMenuPoint := 0
        Let sListIndex := 0
        Let Button := 0
        Let sWashCount := 0
        Let bDisplay := 0
        Let rListItem := 0
        Let arItemRefs := Ar_Null
        Let arItemCheck := Ar_Null
    endif
End

Link to comment
Share on other sites

I've enhanced the code posted above a bit.

Just don't want to post more "uneditable" posts with (spoiler) and (code) BB functions.

 

It just works exactly as I think AltDunmer imagined it.

 

https://www.youtube.com/watch?v=GxXL1qrbUvU

 

 

Have yet no plans to release that mod as there is still much to do and I am not that much into "working" at home. :tongue:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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