Sign in to follow this  
Followers 0

[OB] Scripting with worldspaces help

Newbie warning: this is only my second scripted spell.

Overview: I want to create a cheater spell that harvests all the mushrooms and lotus seeds in the Imperial City in one swipe.

Of course, the IC consists of seven worldspaces, which each consist of several dozen cells.

I could go through by hand and make a very large ArrayVar of every cell that contains a flora, and try to loop through them all that way.

But I would really prefer to loop over the seven worldspaces, and find all their children cells, and loop over those in turn in a subloop.

(I can do the technical part of building the spell and giving it to the player just fine.)

Attempted so far:

When I try to access, for example, the ICMarketDistrict worldspace with .GetNumChildRefs, I get a compiler error that ICMarketDistrict is not an ObjectID.

If I try to do it by taking a child cell (ICMarketDistrict01) and calling .GetParentCell to get an ObjectID, the CS crashes when I compile.

Is there a simple way to enumerate the cells within a worldspace in a script? (If so, am I close to getting it right?)

Can I call SetHarvested on a flora that's not "in memory" -- ie. in the current cell?



Share this post

Link to post
Share on other sites

OK, I figured it out well enough to suit my purposes. The magic function that makes it all work in my case is the OBSE function GetFirstRefInCell, using its parameter for also accessing the surrounding cells. Since the IC worldspaces are smallish, a single call to GetFirstRefInCell (for flora) will access every single cell in the worldspace that has anything in it, without accessing anything beyond that. So I only needed to access 6 cells ... rather than 6 worldspaces ... to get Refs for all the flora objects I needed.

Which of course means that I didn't need to enumerate the children of the worldspace itself. I looked into that, too, and it looks like I'd need to write a dll plugin and compile it with all the OBSE stuff to get that to work. So it's a good thing I don't need to do that, because OBSE isn't compiling very well right now on my recent MSVC.

One funny thing was that I couldn't access the cells in the ICPalace using the script. When the script started parsing, if I had any ICPalaceXX cells in the script, the script would immediately stop executing.


scriptName ICmushrooms
ref nextCcell
ref nextFlora
short nextCell
short hp_flys
short hp_lotus
short hp_gcup
short hp_sblue
short other
short season
begin ScriptEffectStart

	; figure out which season it is, based on the month
	if GameMonth > 2
		set season to (GameMonth - 3) / 4
		set season to 3
	Label 10
	if nextCell == 0
		set nextCcell to ICMarketDistrict04
	elseif nextCell == 1
		set nextCcell to ICArena06
	elseif nextCell == 2
		set nextCcell to ICArboretum01
	elseif nextCell == 3
		set nextCcell to ICTalosPlazaDistrict03
	elseif nextCell == 4
		set nextCcell to ICElvenGardensDistrict03
		set nextCcell to ICTempleDistrict02

	set nextFlora to GetFirstRefInCell nextCcell 31 2		; loop through all flora in each worldspace
	Label 20
	set other to 0
	if ( nextFlora ) ; continue until all refs are processed
		if nextFlora.IsHarvested == 0
			if nextFlora.GetIngredient == FlyAmanitaCap
				set hp_flys to nextFlora.GetIngredientChance season
			elseif nextFlora.GetIngredient == SacredLotusSeeds
				set hp_lotus to nextFlora.GetIngredientChance season
			elseif nextFlora.GetIngredient == GreenStainCupCap
				set hp_gcup to nextFlora.GetIngredientChance season
			elseif nextFlora.GetIngredient == SteelBlueEntolomaCap
				set hp_sblue to nextFlora.GetIngredientChance season
				set other to 1		; nirnroot
			if other == 0
				nextFlora.SetHarvested 1
		set nextFlora to getNextRef
		Goto 20

	set nextCell to nextCell + 1
	if nextCell < 6
		goto 10
	; in the IC, there are 199 fly amanitas, 63 sacred lotus, 11 green stain cups, and 27 entelomas
	; -- add the correct number of each to the player
	set hp_flys to (199 * hp_flys) / 100
	playerRef.addItem FlyAmanitaCap hp_flys
	set hp_lotus to (63 * hp_lotus) / 100
	playerRef.addItem SacredLotusSeeds hp_lotus
	set hp_gcup to (11 * hp_gcup) / 100
	playerRef.addItem GreenStainCupCap hp_gcup
	set hp_sblue to (27 * hp_sblue) / 100
	playerRef.addItem SteelBlueEntolomaCap hp_sblue





Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0