Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Best way to perform NPC item swaps?


Running4Cover
 Share

Recommended Posts

Okay, so I'm working on a mod that will add different items to its NPC's based on which mods are currently active. My plan is to do something like this; create new armor/weapon FormID's referencing the resources from supported mods then use a script and OBSE to check if the mod is active and if so add these armor/weapons to specific NPC's. Anyway, I am paranoid that in doing this I am going to create something that will bog down the users CPU, and figured it would be best to put my questions past the experts here at the Enclave :yes: Anyway, these are the different thoughts I had for implementing a script to do what I just described, but I don't know which would be best performance-wise and wouldn't create problems:

1) I originally had hoped to make a quest script that would run every time the game loaded and would check for supported mods and add/remove armor based on its findings. I didn't see a way to make something that always ran on startup but didn't keep running in the background, but as I am new to Oblivion Scripting, I could easily have missed this information.

2) After this, I thought perhaps a one time script would be okay, then I would just create an activator somewhere that would run pretty much the same script upon activation. I believe this would work, but with both this idea and the first I feel that if the mod expands much I could wind up with a single huge script that will try to compile all at one time and I don't know for sure, but would assume that could cause issues?

3) So from here I thought maybe just giving all the NPC's who would be changing gear their own scripts to determine if what armor they should have, something like this;


scn ACGGuardScript1


ref self


short onetime


Begin GameMode


if( onetime != 1 )

     set self to GetSelf

     set onetime to 1

endif


if( isModLoaded "ExampleArmorMod.esp" )

     if( self.GetEquipped DefaultCuirass )

          self.RemoveItemNS DefaultCuirass

     endif

     if( self.Equipped DefaultLongsword )

          self.RemoveItemNS DefaultLongsword

     endif

     if( !self.GetEquipped NewCuirass )

          self.AddItemNS NewCuirass 1

     endif

     if( !self.GetEquipped NewLongsword )

          self.AddItemNS NewLongsword 1

     endif

else

     if( self.GetEquipped NewCuirass )

          self.RemoveItemNS NewCuirass

     endif

     if( self.Equipped NewLongsword )

          self.RemoveItemNS NewLongsword

     endif

     if( !self.GetEquipped DefaultCuirass )

          self.AddItemNS DefaultCuirass 1

     endif

     if( !self.GetEquipped DefaultLongsword )

          self.AddItemNS DefaultLongsword 1

     endif

endif


End

(forgive me if I made any syntax errors or anything; as I said this is a new language for me)

Anyway, I like the idea of this, but it seems like there could be a lot of scripts running all at the same time around the areas my mod added, and that that could cause problems. Again though, this is why I'm posting here rather than trying to build it into my game :yes:

4) It has occured to me that it may be possible to build a script into the items in such a way that on load if DefaultCuirass exists it will check for the examplearmor.esp, and if it returns true then it will swap with NewCuirass, and any NewCuirasses in the game world will check for the esp and if it returns false will replace themselves with DefaultCuirass.

Also, seperately, would it be beneficial in any/all of these cases to use the ModModelPath function as opposed to Add&RemoveItem functions? I assume it is personal preference on my part whether, as to whether I want to force both suits to have the same stats and if so then maintain item damage between transitions.

So anyway, any advice someone would be willing to impart to me would be much appreciated, and I thank you for your time!

CC

Link to comment
Share on other sites

scripting is just logic flow. you have a couple errors there, syntax aside.

In this block, for instance:


if( isModLoaded "ExampleArmorMod.esp" )
if( self.GetEquipped DefaultCuirass )
self.RemoveItemNS DefaultCuirass
endif
if( self.Equipped DefaultLongsword )
self.RemoveItemNS DefaultLongsword
endif
if( !self.GetEquipped NewCuirass )
self.AddItemNS NewCuirass 1
endif
if( !self.GetEquipped NewLongsword )
self.AddItemNS NewLongsword 1
endif
endif[/code] The second two if loops wouldn't work, as the conditions would no longer be true, as you removed the items earlier. What you would want to do is something like:
[code]if( isModLoaded "ExampleArmorMod.esp" )
if( self.GetEquipped DefaultCuirass )
self.RemoveItemNS DefaultCuirass
self.AddItemNS NewCuirass 1
endif
if( self.Equipped DefaultLongsword )
self.RemoveItemNS DefaultLongsword
self.AddItemNS NewLongsword 1
endif
endif

and you may even want to force equip them in those if statements as well.

Link to comment
Share on other sites

scripting is just logic flow. you have a couple errors there, syntax aside.

In this block, for instance:


if( isModLoaded "ExampleArmorMod.esp" )

     if( self.GetEquipped DefaultCuirass )

          self.RemoveItemNS DefaultCuirass

     endif

     if( self.Equipped DefaultLongsword )

          self.RemoveItemNS DefaultLongsword

     endif

     if( !self.GetEquipped NewCuirass )

          self.AddItemNS NewCuirass 1

     endif

     if( !self.GetEquipped NewLongsword )

          self.AddItemNS NewLongsword 1

     endif

endif
The second two if loops wouldn't work, as the conditions would no longer be true, as you removed the items earlier. What you would want to do is something like:
if( isModLoaded "ExampleArmorMod.esp" )

     if( self.GetEquipped DefaultCuirass )

          self.RemoveItemNS DefaultCuirass

          self.AddItemNS NewCuirass 1

     endif

     if( self.Equipped DefaultLongsword )

          self.RemoveItemNS DefaultLongsword

          self.AddItemNS NewLongsword 1

     endif

endif

     

and you may even want to force equip them in those if statements as well.

Ah, I hadn't thought of the force equip; thank you!

How is it the second loops wouldn't work though? I agree that your method is better, but in my example it checks if if you have the first item equipeed, and if so removes it, then checks if you DON'T have the second equipped and adds it. I thought this made sense in that there may be a circumstance (like a poorly built vendor) where the NPC could have a 3rd item equipped that wasn't considered? Either way, thank you for taking the time to help me out!

Anyway, I just realized that that method could cause problems if the player character wound up obtaining the new armor, so I'm assuming the best method for this would be to script the items in such a way that they run an OnLoad block and use the ModModel and ModIcon functions? Does the OnLoad block effect items in the player inventory? Thanks again!

CC

Link to comment
Share on other sites

Ah, I hadn't thought of the force equip; thank you!

How is it the second loops wouldn't work though? I agree that your method is better, but in my example it checks if if you have the first item equipeed, and if so removes it, then checks if you DON'T have the second equipped and adds it. I thought this made sense in that there may be a circumstance (like a poorly built vendor) where the NPC could have a 3rd item equipped that wasn't considered? Either way, thank you for taking the time to help me out!

Anyway, I just realized that that method could cause problems if the player character wound up obtaining the new armor, so I'm assuming the best method for this would be to script the items in such a way that they run an OnLoad block and use the ModModel and ModIcon functions? Does the OnLoad block effect items in the player inventory? Thanks again!

CC

Oops. you are correct. :thumbup: Teach me to read a bit more carefully. :yes: Guess I am more tired than I thought.

Something to keep in mind though, is you should probably just check to see if the character in questions has one, not necessarily has it equipped. The way it is written in your example, if the character wasn't currently wearing it, the script would give them another one.

GetGameLoaded in an object script that is in the players inventory does indeed work. I use it myself. :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...