Jump to content

script help: choose an item to spawn depending on the value of an integer


Recommended Posts

Hi.

 

Me and scripts again!

 

Here's what I'm trying to do, plus the script.

 

Basically, I want certain items to spawn when the player enters a cell. I then want the script to check if any of these items are already present. If they are, the script does nothing. If there are none, the script chooses how many to spawn and which objects to spawn.

 

The objects spawned are spider sacs (containers). There is a choice of containers to give the player ingredients, a poison or the container is empty.

 

There is also a chance that nothing will spawn when the player enters the cell.

 

Here's the script: it compiles up to the line If SacsToplace = 1, then throws the error 'No viable alternative at input 'SacstoPlace'.

 

I've defined the integer, assigned a value to it, so why won't the script compile?

 

The Script:

 

Scriptname MBWHspiderSacscript extends ObjectReference

 

Import Utility

 

GlobalVariable Property MBWHspiderSacCount auto

ObjectReference Property SacSpawn01marker auto

ObjectReference Property SacSpawn02marker auto

Container Property MBWHchestSpiderEmpty auto

Container Property MBWHchestSpiderInsects auto

Container Property MBWHchestSpiderPoisonedMeat auto

 

Event onCellAttach()

 

Float CurrentSacCount=MBWHspiderSacCount.getvalue()

 

If CurrentSacCount>0

GoToState("DoNothing")

EndIf

 

;place 0,1 or 2 sacs as long as there are none there already

 

Int SacsToPlaceRandom = RandomInt()

Int SacsToPlace = 0

 

If SacsToPlaceRandom<80

GoToState("DoNothing")

ElseIf SacsToPlaceRandom<90

SacsToPlace+=1

Else

SacsToPlace+=2

EndIf

 

;Choose sac types

 

Int Sac01choiceRandom = RandomInt()

Int Sac02choiceRandom = RandomInt()

Container Sac01choice

Container Sac02choice

 

If Sac01choiceRandom<50

Sac01Choice = MBWHchestSpiderEmpty

elseIf Sac01choiceRandom<75

Sac01Choice = MBWHchestSpiderInsects

 

Else

Sac01Choice = MBWHchestSpiderPoisonedMeat

EndIf

 

If Sac02choiceRandom<80

Sac02Choice = MBWHchestSpiderEmpty

elseIf Sac02choiceRandom<90

Sac02Choice = MBWHchestSpiderInsects

 

Else

Sac02Choice = MBWHchestSpiderPoisonedMeat

EndIf

 

If SacsToPlace=1

SacSpawn01marker.PlaceAtMe(Sac01Choice)

ElseIf SacsToPlace=2

SacSpawn01marker.PlaceAtMe(Sac01Choice)

SacSpawn02marker.PlaceAtMe(Sac02Choice)

Else

;

Endif

 

EndEvent

 

State DoNothing

;

EndState

 

edit: The line to 'import utility' is redundant and will be removed: I added it when I thought I might need to call it, but subsequently didn't.

 

Any help is very much appreciated.

Link to comment
Share on other sites

Thank you for that...

 

... so a schoolboy error on my part! I looked at it for ages and must have just had a mental blank! I was convinced I'd not specified one of the variables/properties correctly... doh! I can now have a spider pet that leaves little presents every now and then. I just need to write a short script to disable and delete the sacs when harvested, or else they'll only appear once. I'll attach that to the sacs themselves.

 

 

I've noted your comment about the length of the post for future use, too. I knew how to use spoiler text but didn't know 'code' part. Very useful. Thanks for the advice.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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