Jump to content

Item swapping in a world space via script?


Spivey

Recommended Posts

I'm entirely too spoiled by NVSE. My first thought was to use a ref-walk that ran when the player changed cells.

 

scn CigaretteReplacerScript

ref currentitem
short numitems
ref currentcell
ref oldcell

begin gamemode

set currentcell to player.getparentcell
if(currentcell != oldcell)
	set numitems to getnumrefs 31 1 0
	if(numitems > 0)
		set currentitem to getfirstref 31 1 0
		label 10
		if(currentitem)
			if(currentitem == CigaretteCarton)
				currentitem.disable
				currentitem.placeatme ReplacementCarton
				currentitem.markfordelete
			elseif(currentitem == CigarettePack)
				currentitem.disable
				currentitem.placeatme ReplacementPack
				currentitem.markfordelete
			endif
			set currentitem to Pencil01
			set currentitem to getnextref
			set numitems to numitems - 1
			if(numitems > 0)
				goto 10
			endif
			set oldcell to currentcell
		endif
	endif
endif

end ; gamemode

 

You can put that on either a running quest or a token in the player's inventory. I used PlaceAtMe after Disable in an attempt avoid those wacky Havok hijinks where and object ends up inside the collision box of another and one of them goes flying; whether that's necessary is untested.

 

The upside of doing it externally is that it avoids other mods potentially overriding your changes to the vanilla packs and cartons and removing an object script on them. The downside is that it requires NVSE, which may or may not be an issue for you.

Edited by luthienanarion
Link to comment
Share on other sites

You ARE entirely too spoiled by NVSE. I would hate you for it, but I can't because I know that all it really is is jealousy. I really should get me myself some NVSE, but...

 

Well, I have entirely too much dependency hell in the 'real world'. I don't need to be inflicting it on myself in my gaming world too. :)

Link to comment
Share on other sites

I use it mostly for ref-walks like the script above, list functions that are actually useful, and pointing ref variables to things in other mods without requiring them as masters. Horribly useful.

 

If you can do something without it, you're probably better off not requiring users to install it; it's just humorous that I didn't even consider an alternative when I read your first post.

Link to comment
Share on other sites

I'm still trying to figure out what on earth people do with lists that they find the NVSE ListOps functions so useful. Are they using them as substitutes for one-dimensional arrays or is there something cool that can be done with Form Lists that I just don't know about?
Link to comment
Share on other sites

I use it mostly for ref-walks like the script above, list functions that are actually useful, and pointing ref variables to things in other mods without requiring them as masters. Horribly useful.

 

So totally true. I hardly ever think of a script without using an NVSE function in it.

 

 

I'm still trying to figure out what on earth people do with lists that they find the NVSE ListOps functions so useful. Are they using them as substitutes for one-dimensional arrays or is there something cool that can be done with Form Lists that I just don't know about?

 

In part yes, though a proper script can actually use them as multi-dimensional arrays (lists can contain lists, etc etc and so on :biggrin: ). Yes it can get confusing if you don't know what you're doing.

 

For a reference of what list functions can be used for, look at my mod Ammo Vending Machine. It makes use of list functions and the NVSE MessageBoxEX. The list functions walk the ammo list of the current weapon (also an NVSE function to get that information) to create a message box with that info. The MessageBoxEX function produces a message box, but takes optional format specifiers that can do things such as take the name of an object and fill it into the buttons.

 

Project Nevada makes heavy use of lists, to do things such as determine what helmets get overlays, what lock you're trying to bust open with Explosive Entry. I could go on, but that's just getting crazy. Suffice to say that the list functions from NVSE allow for some very cool mods to be possible.

 

 

As far as your case, I too would have considered the refwalk that luthienanarion mentioned. It comes down to resource usage really. A quest script is running all the time, but it's just one script that can be paused or given a longer delay between times it runs. An object script will run every frame that the object is loaded no matter what. And a persistent object will run its script all the time, no matter where you are. Just like a quest, but without as much control.

 

So, while the ref walk uses more resources in the processing stage, it might have less impact overall. However, if you're replacing all instances of the original cigarette items, then your script would only run for a few frames while it processed them all. Then it would be done until you entered a cell with more. So that's probably the way to go.

 

If you're interested, I tackled this problem in Nuka-Cola Enhanced mod. It does a cell search and dynamic replacement on Nuka-Cola bottles. I'm actually a bit ashamed to say I didn't even think of running an object script :sweat: . I just skipped straight to the more complex NVSE method. However, my reasoning was that if the player does NOT take all of the Nuka-Cola one time, re-entering could give it the chance to replace again. Doing that over and over until all cola was turned into a more special variant.

 

Anyway, my 2¢ worth.

Link to comment
Share on other sites

I'm still trying to figure out what on earth people do with lists that they find the NVSE ListOps functions so useful. Are they using them as substitutes for one-dimensional arrays or is there something cool that can be done with Form Lists that I just don't know about?

 

The key feature of my child headgear mods and CotW expansions is headgear and armor swapping out for child-fitted versions. Instead of using a script that iterates through all of the swappable items (which would be a huge script, since it handles ALL of the vanilla and DLC items) in IF/ELSEIF/ELSEIF fashion, I use a form list that contains swappable adult-sized items and another list for the child variants at the same list index. When a child character equips an item that can be swapped the script finds the index of the item in one list and grabs the replacement from the other list at the same index. NVSE is required determine if a base form is in a list (since IsInList only seems to work with references), find the index of an item in the list, and to get an item from a specific index in a list. I work with form lists quite a bit, and people still surprise me with ways to use them from time to time.

 

If you're interested, I tackled this problem in Nuka-Cola Enhanced mod. It does a cell search and dynamic replacement on Nuka-Cola bottles. I'm actually a bit ashamed to say I didn't even think of running an object script :sweat: . I just skipped straight to the more complex NVSE method. However, my reasoning was that if the player does NOT take all of the Nuka-Cola one time, re-entering could give it the chance to replace again. Doing that over and over until all cola was turned into a more special variant.

 

Good to know that someone (especially Gribble) has pioneered this method and that it works. I didn't test this at all. :rolleyes:

I might have to do something similar with Sugar Bombs to get around PN's Rebalance ESP overriding my edits to them.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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