Jump to content

Problems with calling a LeveledActor from a script


Recommended Posts

I'm working on improving my Wave Spawner (and Spawn Grenade, since it probably has the same problem). User M1stLynx pointed out that they spawn multiple copies of the same guy whenever the device triggers. I've tried separating out the spawns into individual rolls like so, and the same thing happens. It always picks the first actor in the LeveledActor list. For reference, this is what my properties look like.

Function SpawnRandom(Int MenuChoice, Int SpawnChoice, Int SpawnNum)

	Int Count = 1
	While Count <= SpawnNum
		If MenuChoice == 0
			ToSpawn = AnimalWave[SpawnChoice]
		ElseIf MenuChoice == 1
			ToSpawn = RobotWave[SpawnChoice]
		ElseIf MenuChoice == 2
			ToSpawn = EnemyWave[SpawnChoice]
		ElseIf MenuChoice == 3
			ToSpawn = GangWave[SpawnChoice]
		ElseIf MenuChoice == 4
			ToSpawn = MonsterWave[SpawnChoice]
		EndIf
		PlaceAtMe(ToSpawn, 1)
		Count += 1
	EndWhile

EndFunction

For example, if I choose Raider off the menu, I get EncRaider01Template every time. Bear in mind, I tested this with a level 100 character.

 

Do scripts simply not know how to handle leveled actors, or am I doing something wrong with either the script or the properties? Full script under spoiler below.

 

 

Scriptname _gkx_wavespawnerscript extends ObjectReference

Group Waves
	LeveledActor[] Property AnimalWave Auto
	LeveledActor[] Property RobotWave Auto
	LeveledActor[] Property EnemyWave Auto
	LeveledActor[] Property GangWave Auto
	LeveledActor[] Property MonsterWave Auto
EndGroup

Group Messages
	Message Property MainMenu Auto
	Message Property AnimalMenu Auto
	Message Property RobotMenu Auto
	Message Property EnemyMenu Auto
	Message Property GangMenu Auto
	Message Property MonsterMenu Auto
	Message Property CountMenu Auto
	Message Property CountMessage Auto
	Message Property DelayMenu Auto
	Message Property DelayMessage Auto
EndGroup

Group NumArrays
	Int[] Property DelayArray Auto
	Int[] Property CountArray Auto
EndGroup

LeveledActor ToSpawn
Int NumToSpawn
Int DelaySpawn
Int ListChoice
Int MainChoice
Int WaveChoice
Bool Spawning
Bool Working
Bool IncrWave
Bool RelativeDelay

Function SpawnRandom(Int MenuChoice, Int SpawnChoice, Int SpawnNum)

	Int Count = 1
	While Count <= SpawnNum
		If MenuChoice == 0
			ToSpawn = AnimalWave[SpawnChoice]
		ElseIf MenuChoice == 1
			ToSpawn = RobotWave[SpawnChoice]
		ElseIf MenuChoice == 2
			ToSpawn = EnemyWave[SpawnChoice]
		ElseIf MenuChoice == 3
			ToSpawn = GangWave[SpawnChoice]
		ElseIf MenuChoice == 4
			ToSpawn = MonsterWave[SpawnChoice]
		EndIf
		PlaceAtMe(ToSpawn, 1)
		Count += 1
	EndWhile

EndFunction

Function StartSpawning()

	Int Increment = 1
	Int RelDelay = 5
	While Spawning && IsPowered()
		If IncrWave
			NumToSpawn = Increment
			Increment += 1
		EndIf
		If RelativeDelay
			DelaySpawn = RelDelay
			RelDelay += 5
		EndIf
		SpawnRandom(MainChoice, WaveChoice, NumToSpawn)
		Utility.Wait(DelaySpawn)
	EndWhile
	Return

EndFunction
		

Event OnPowerOn(ObjectReference akGenerator)

	IncrWave = False
	RelativeDelay = False
	Working = True
	MainChoice = MainMenu.Show()
	If MainChoice == 0
		WaveChoice = AnimalMenu.Show()
		If WaveChoice == 8
			Return
		EndIf
	ElseIf MainChoice == 1
		WaveChoice = RobotMenu.Show()
		If WaveChoice == 4
			Return
		EndIf
	ElseIf MainChoice == 2
		WaveChoice = EnemyMenu.Show()
		If WaveChoice == 5
			Return
		EndIf
	ElseIf MainChoice == 3
		WaveChoice = GangMenu.Show()
		If WaveChoice == 5
			Return
		EndIf
	ElseIf MainChoice == 4 
		WaveChoice = MonsterMenu.Show()
		If WaveChoice == 5
			Return
		EndIf
	ElseIf MainChoice == 5
		Return
	EndIf
	Int CountChoice = CountMenu.Show()
	If CountChoice == 0
		IncrWave = True
		CountMessage.Show()
	ElseIf CountChoice == 6
		Return
	Else
		NumToSpawn = CountArray[CountChoice]
	EndIf
	Int DelayChoice = DelayMenu.Show()
	If DelayChoice == 0
		RelativeDelay = True
		DelayMessage.Show()
	Elseif DelayChoice == 5
		Return
	Else
		DelaySpawn = DelayArray[DelayChoice]
	EndIf
	Spawning = True
	StartSpawning()

EndEvent

Event OnPowerOff()

	Spawning = False

EndEvent

 

 

 

Link to comment
Share on other sites

All the NPC spawning my mods do is always based on random indexing of lvlNPC FormLists rather than the intermediate LCharNPC level lists. You need to change PlaceAtMe() to PlaceactorAtMe() as well

 

For a quick test create a formlist drag in some lvlNPCs and stick this in your while:

FormList Property pNPCList Auto Const Mandatory 

Int iIndex = Utility.RandomInt(0, (pNPCList.GetSize() - 1) )
ActorBase ToSpawn = ( pNPCList.GetAt(iIndex) as ActorBase)
ObjectReference akActorRef = MarkerToSpawnAt.PlaceActorAtMe(ToSpawn)

Disclaimer: extensive sampling suggests that the seeding used for Utility.Random in papyrus is not that random, I always add a synthetic layer (While iIndex == iLastIndex) to avoid using the last value.

Edited by SKK50
Link to comment
Share on other sites

  • Recently Browsing   0 members

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