Jump to content

Repairing multiple items by script?


JustChill

Recommended Posts

Hey there,

 

I would like to make a repair script for specific items (listed in a FormList) getting fully repaired.

 

 

scn RepairSCRIPT

float Button
Short ListIndexCount 
Short vListItemCounts
Ref vListItem
array_var vInventoryItems


begin OnActivate player
    if <SomeConditions>
        ShowMessage MsgRepairItemsUSE
    endif
end


BEGIN GameMode
    set Button to GetButtonPressed
    set ListIndexCount to 0
    if (Button == 0)
        Label 1
            Set vListItem to ListGetNthForm FlRepairableFormList ListIndexCount
            Set vListItemCounts to Player.GetItemCount vListItem
            If vListItemCounts > 0
                let vInventoryItems := Player.GetInvRefsForItem vListItem
                ForEach vListItem <- vInventoryItems
                    if vListItem.GetItemRefCurrentHealth != vListItem.GetBaseHealth
                        Set Button to vListItem.GetBaseHealth
                        vListItem.SetItemRefCurrentHealth Button
                    endif
                Loop
            endif
            Set ListIndexCount to ListIndexCount + 1
            if ListIndexCount < ListGetCount FlRepairableFormList
                Goto 1
            endif
END

 

 

 

I wonder if this may work.

Currently not being able to test it as being not at home.

 

I would be very pleased for some guidance of how to check every sinlge item for needing to be repaired. :smile:

 

Thank you,

Just Chill

Link to comment
Share on other sites

I don't know anything about scripts, but I do know that what you are trying to do is possible. The FO3 mod "mesme" has this feature.

 

One of the abilities of the revived companion is to repair one or all items in your inventory.

 

I'm sure if you check the mod, you will find what you need. https://www.nexusmods.com/fallout3/mods/10922

Link to comment
Share on other sites

Hey,

it seems that mod simply adds "repair menus" to those NPCs.

That's actually pretty easy, I rather want to repair items via script not by the ShowRepairMenu function.

 

I've seen a few mods which used the SetWeaponHealthPerc function. Yet that function requires the weapon to be equipped, which I don't want to do.

My goal is to repair one item (and all it stacks if duplicates are present), that's just in the inventory of the player.

Link to comment
Share on other sites

This seems mostly correct, but you need something that references an array variable for each entry, as on the third line here.

                let vInventoryItems := Player.GetInvRefsForItem vListItem
                ForEach aEntry <- vInventoryItems
                    let vListItem := aEntry["value"]
                    if vListItem.GetItemRefCurrentHealth != vListItem.GetBaseHealth
                        Set Button to vListItem.GetBaseHealth
                        vListItem.SetItemRefCurrentHealth Button
                    endif
                Loop

I was going to look at the rest of it, but no time right now, so I hope that's all it needed. Have you tested yet?

Link to comment
Share on other sites

Still not at home, but I am looking forward to test it. :smile:

 

I hoped that I don't need 2 array variables for the comparison, as it was told that one reference variable for the item and one array variable for the container are enough.

https://geckwiki.com/index.php/Foreach

First example.

 

 

In addition:

Hm, that example might have been misleading.

Probably works when the "Container" is actually a real container but no array variable. XD

Gotta have a look into soon. :)

 

Thanks for the guidance so far.

Link to comment
Share on other sites

Hey, just tried it out.

 

Works pretty fine, except of not repairing weapons to 100%, which are modded (by weapon mods) to have more condition.

I guess I'll figure that one out either.

Gonna refire those burnt brain cells right now... oO

Link to comment
Share on other sites

Glad you got it. I forgot about that use of ForEach loops, which is a little less familiar to me, but I only ever see it done with two references, not arrays. You seem to know what you're doing, but if you need help with the weapon mod stuff, I'll be back later.

 

Also, use Let instead of Set everywhere you can, as it will print errors in the console and is faster to type the more complex operations, like incrementing.

Link to comment
Share on other sites

Much appreciated, thanks. :)

 

I just banned all Set usages in my scripts.

Maybe if I get back to it, I'll LETify my other mods too. ^^

 

My instructor actually never explained that to me.

The usage of operators like +=, -=, *=, /= makes it way easier as you mentioned. :D

Link to comment
Share on other sites

  • Recently Browsing   0 members

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