Jump to content

Using array or formlist for random spawnpoint


gerg357

Recommended Posts

I can make a spawn point in ck but im having a hard time generating a random one from a list dunno if i need an array or form list i tried a form list using this code but this wont compile

 

int s = spawnpoints.GetSize() - 1
s = utility.RandomInt(0, S)

spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,1)

 

im guessing it has to do with the spawnpoints.GetAt(s) part..

 

Any help on how to do this?

Link to comment
Share on other sites

Post the full script, with it's properties and everything and the compile error it gives

If that's you full script you are missing half the script, check this tutorial: http://www.cipscis.com/skyrim/tutorials/beginners.aspx

And here you find all events and functions: http://www.creationkit.com/index.php?title=Category:Papyrus

Link to comment
Share on other sites

Scriptname TownCheckScript extends ObjectReference
ActorBase Property EncBandit01Melee1HNordM Auto
ActorBase Property WEDL05Thug Auto
ActorBase Property EncVampire01BretonF Auto
ObjectReference Property SpawnPoint1 Auto
Message Property checkfail Auto
Message Property bandits1 Auto
Message Property bandits2 Auto
Message Property bandits3 Auto
Message Property nobandits Auto

Message Property thugs1 Auto
Message Property thugs2 Auto
Message Property thugs3 Auto
Message Property nothugs Auto
FormList Property spawnpoints Auto
Message Property vampires1 Auto
Message Property vampires2 Auto
Message Property vampires3 Auto
Message Property novampires Auto
float CheckTime ; the only status variable needed


Event OnActivate(ObjectReference akActionRef)

if akActionRef != Game.GetPlayer() ; do not let other NPCs trigger this
return
endif

if CheckTime == 0.0 ; starting a shift
CheckTime = 2.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hours

int s = spawnpoints.GetSize() - 1
s = utility.RandomInt(0, S)

int random = Utility.RandomInt(0, 6) ; Generates a random number between 0 and 2

If random == 0
int random1 = Utility.RandomInt(0, 6) ; Generates a random number between 0 and 2
If random1 == 0
spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,1)
bandits1.Show()
ElseIf random1 == 1
bandits2.Show()
spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,2)
spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,2)
ElseIf random1 == 3
bandits3.Show()
spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,3)
spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,3)
spawnpoints.GetAt(s).PlaceActorAtMe(EncBandit01Melee1HNordM,3)
Else
nobandits.Show()
EndIf


ElseIf random == 1
int random2 = Utility.RandomInt(0, 6) ; Generates a random number between 0 and 2
If random2 == 0
spawnpoints.GetAt(s).PlaceActorAtMe(WEDL05Thug,1)
thugs1.Show()
ElseIf random2 == 1
thugs2.Show()
spawnpoints.GetAt(s).PlaceActorAtMe(WEDL05Thug,2)
spawnpoints.GetAt(s).PlaceActorAtMe(WEDL05Thug,2)
ElseIf random2 == 3
thugs3.Show()
spawnpoints.GetAt(s).PlaceActorAtMe(WEDL05Thug,3)
spawnpoints.GetAt(s).PlaceActorAtMe(WEDL05Thug,3)
spawnpoints.GetAt(s).PlaceActorAtMe(WEDL05Thug,3)
Else
nothugs.Show()
EndIf

ElseIf random == 3
int random3 = Utility.RandomInt(0, 6) ; Generates a random number between 0 and 2
If random3 == 0
spawnpoints.GetAt(s).PlaceActorAtMe(EncVampire01BretonF,1)
vampires1.Show()
ElseIf random3 == 1
vampires2.Show()
spawnpoints.GetAt(s).PlaceActorAtMe(EncVampire01BretonF,2)
spawnpoints.GetAt(s).PlaceActorAtMe(EncVampire01BretonF,2)
ElseIf random3 == 3
vampires3.Show()
spawnpoints.GetAt(s).PlaceActorAtMe(EncVampire01BretonF,3)
spawnpoints.GetAt(s).PlaceActorAtMe(EncVampire01BretonF,3)
spawnpoints.GetAt(s).PlaceActorAtMe(EncVampire01BretonF,3)
Else
novampires.Show()
EndIf

Else
nobandits.Show()
EndIf

elseif Utility.GetCurrentGameTime() * 24.0 >= CheckTime ; have worked long enough
CheckTime = 0.0 ; reset for next time



else ; not done yet! The message can show how many hours are left
checkfail.Show()
endif

endEvent

Link to comment
Share on other sites

When you get something from a formlist it comes as a base form. You need to cast it to something if you want to use functions that are not on the form script.

(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,1)
Link to comment
Share on other sites

If you look at the top line of each script you will see something like:

Scriptname ObjectReference extends Form Hidden

That bit where it says "extends" indicates that this type of object also has access to all of the functions in the type of script it extends. So an objectreference has access to all of the functions in the form script. The same is not true in the other direction. Forms do not have access to the functions in the objectreference script. When you use GetAt() to access an entry on a formlist, it is automatically returned as a form. You have to tell Papyrus that this form is actually an objectreference (and therefore ought to have access to objectreference functions) by "casting" it using the word "as" like in the example.

Link to comment
Share on other sites

" int random = Utility.RandomInt(0, 6) ; Generates a random number between 0 and 2 "

no it generates a random Int between 0 and 6, not 0 and 2

 

Scriptname TownCheckScript extends ObjectReference

ActorBase Property EncBandit01Melee1HNordM Auto
ActorBase Property WEDL05Thug Auto
ActorBase Property EncVampire01BretonF Auto
ObjectReference Property SpawnPoint1 Auto
Message Property checkfail Auto
Message Property bandits1 Auto
Message Property bandits2 Auto
Message Property bandits3 Auto
Message Property nobandits Auto

Message Property thugs1 Auto
Message Property thugs2 Auto
Message Property thugs3 Auto
Message Property nothugs Auto
FormList Property spawnpoints Auto
Message Property vampires1 Auto
Message Property vampires2 Auto
Message Property vampires3 Auto
Message Property novampires Auto
float CheckTime ; the only status variable needed


Event OnActivate(ObjectReference akActionRef)

if akActionRef == Game.GetPlayer() ; Only player can trigger
if CheckTime == 0.0 ; starting a shift
CheckTime = 2.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hours
int s = spawnpoints.GetSize() - 1
s = utility.RandomInt(0, S)
int random = Utility.RandomInt(0, 2) ; Generates a random number between 0 and 2
If random == 0
int random1 = Utility.RandomInt(0, 2) ; Generates a random number between 0 and 2
If random1 == 0
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,1)
bandits1.Show()
ElseIf random1 == 1
bandits2.Show()
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,2)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,2)

ElseIf random1 == 2
bandits3.Show()
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,3)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,3)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncBandit01Melee1HNordM,3)
Else
nobandits.Show()
EndIf
ElseIf random == 1
int random2 = Utility.RandomInt(0, 2) ; Generates a random number between 0 and 2
If random2 == 0
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(WEDL05Thug,1)
thugs1.Show()
ElseIf random2 == 1
thugs2.Show()
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(WEDL05Thug,2)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(WEDL05Thug,2)
ElseIf random2 == 2
thugs3.Show()
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(WEDL05Thug,3)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(WEDL05Thug,3)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(WEDL05Thug,3)
Else
nothugs.Show()
EndIf
ElseIf random == 3
int random3 = Utility.RandomInt(0, 2) ; Generates a random number between 0 and 2
If random3 == 0
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncVampire01BretonF,1)
vampires1.Show()
ElseIf random3 == 1
vampires2.Show()
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncVampire01BretonF,2)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncVampire01BretonF,2)
ElseIf random3 == 2
vampires3.Show()
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncVampire01BretonF,3)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncVampire01BretonF,3)
(spawnpoints.GetAt(s) as ObjectReference).PlaceActorAtMe(EncVampire01BretonF,3)
Else
novampires.Show()
EndIf

Else
nobandits.Show()
EndIf
elseif Utility.GetCurrentGameTime() * 24.0 >= CheckTime ; have worked long enough
CheckTime = 0.0 ; reset for next time
else ; not done yet! The message can show how many hours are left
checkfail.Show()
endif
EndIf
endEvent

Link to comment
Share on other sites

  • Recently Browsing   0 members

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