Jump to content

Scripting Advice for Player Base


Deleted2746547User

Recommended Posts

Working on a couple of different scripts to do different things but this one in particular I need to figure out now:

1. Trying to figure the best way at this: I have a mod that allows you to build a base and assign guards/clothing, etc. Whenever you build/construct a new structure, items are pulled from a "Base Storage".

What I'm trying to do, is that when guards run out of ammo - it is also pulled from one location. That way, you don't have to run to each and every guard when they run out of ammo.

Link to comment
Share on other sites

You could attach a script like below to the guards.

Maybe another blocktype like OnCombatStart is a better choice as GameMode runs every frame, but it's really just for demonstration.

 

Note that it uses NVSE functions. Doing it without NVSE would require a lot of hard coding if you want the script to be dynamic and work with all weapons/ammo.

ScriptName GuardRefillAmmoScript
ref rActor
ref rAmmo

Begin GameMode
    set rList to rActor.GetWeaponAmmo
    set rAmmo to ListGetNthForm rList 0
    If rActor.GetItemCount rAmmo == 0
        rActor.AddItem rAmmo 30
        BaseStorageREF.RemoveItem rAmmo 30
    EndIf
End
Link to comment
Share on other sites

 

You could attach a script like below to the guards.

 

Maybe another blocktype like OnCombatStart is a better choice as GameMode runs every frame, but it's really just for demonstration.

 

Note that it uses NVSE functions. Doing it without NVSE would require a lot of hard coding if you want the script to be dynamic and work with all weapons/ammo.

ScriptName GuardRefillAmmoScript
ref rActor
ref rAmmo

Begin GameMode
    set rList to rActor.GetWeaponAmmo
    set rAmmo to ListGetNthForm rList 0
    If rActor.GetItemCount rAmmo == 0
        rActor.AddItem rAmmo 30
        BaseStorageREF.RemoveItem rAmmo 30
    EndIf
End

That's pretty awesome. Thank you. Question.. how would you include a message if an NPC tried to pull ammo and there wasn't any. As a way of reminding you to put more in.

 

THANK YOU AGAIN btw.. my coding skills are pretty limited and I'm trying to do a lot with this mod. I really appreciate the help.

Link to comment
Share on other sites

You could do something like this, but it has the potential to become spammy if you have more than a few guards. Alternatively you could attach a similar script to the container itself, or have a quest script running which checks the container every few seconds.

ScriptName GuardRefillAmmoScript
ref rActor
ref rAmmo
ref rSelf
short iCount

Begin GameMode
    set rList to rActor.GetWeaponAmmo
    set rAmmo to ListGetNthForm rList 0
    set rSelf to GetSelf
    If rActor.GetItemCount rAmmo == 0

        ; storage has run out of ammo, show warning
        If BaseStorageREF.GetItemCount rAmmo == 0
            MessageEx "%n has run out of ammo." rSelf

        ; NPC has taken last ammo from storage, show warning
        ElseIf BaseStorageREF.GetItemCount rAmmo < 30
            MessageEx "%n has taken the last ammo." rSelf
            Set iCount to BaseStorageREF.GetItemCount rAmmo
            rActor.AddItem rAmmo iCount
            BaseStorageREF.RemoveItem rAmmo iCount

        ; storage is sufficiently full
	Else
            rActor.AddItem rAmmo 30
            BaseStorageREF.RemoveItem rAmmo 30
	EndIf
    EndIf
End
Link to comment
Share on other sites

 

You could attach a script like below to the guards.

 

Maybe another blocktype like OnCombatStart is a better choice as GameMode runs every frame, but it's really just for demonstration.

 

Note that it uses NVSE functions. Doing it without NVSE would require a lot of hard coding if you want the script to be dynamic and work with all weapons/ammo.

ScriptName GuardRefillAmmoScript
ref rActor
ref rAmmo

Begin GameMode
    set rList to rActor.GetWeaponAmmo
    set rAmmo to ListGetNthForm rList 0
    If rActor.GetItemCount rAmmo == 0
        rActor.AddItem rAmmo 30
        BaseStorageREF.RemoveItem rAmmo 30
    EndIf
End

I think you're right about it probably getting spammy. Would this version be the better option do you think?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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