Jump to content

[LE] Trouble with Script for spawning random creature


Recommended Posts

I have a formlist of Encounter actors, from the object list not references in the game.

I have the index number and a marker.

But I cannot get it to complie.

 

FormList Property MyList Auto
ActorBase Property ChosenBase Auto
ObjectReference Property ChosenRef Auto
iIndex = Utility.RandomInt(0,ListSize)
;ChosenBase = MyList.GetAt(iIndex)
;ChosenRef = MyMarker.PlaceAtMe(ChosenBase) as ObjectReference
It's that first commented out line that just doesn't work.
I could do something similar by putting a bunch of references in a holding cell and using those for my formlist and moving the references in and out of that location, but that shouldn't be needed.
Any idea of what I'm doing wrong? I'm not a scripter, it's all just trial and error and googling.
Link to comment
Share on other sites

Here is a script that might help you. You will want to put this on a Quest, but you can easily modify the code to put it on a switch or button. Please note I haven't compiled this (don't feel like opening up the CK, though I really should get a compiler setup going on Notepad++) and there may be errors / bugs. If you have any questions about how or why it works, or if there is a bug, just let me know.

Scriptname SpawnRandomActorFromFormlist extends Quest

;/
	Copyright 2020 Reneer
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	For the full LGPL license, see http://www.gnu.org/licenses/gpl.html
/;

FormList Property MyList Auto
ActorBase Property ChosenBase Auto
ObjectReference Property ChosenRef Auto
ObjectReference Property MyMarker Auto
Actor Property PlayerRef Auto

Event OnInit()

	SpawnRandomActorFromFormlist()

endEvent

Function SpawnRandomActorFromFormlist()

	if (PlayerRef == none)
		PlayerRef = Game.GetPlayer()
	endif

	if (MyList != none)
		ChosenBase = (MyList.GetAt(Utility.RandomInt(0, MyList.GetSize())) As ActorBase)
		if (ChosenBase != none)
			if (MyMarker != none)
				ChosenRef = MyMarker.PlaceActorAtMe(ChosenBase)
			else
				ChosenRef = PlayerRef.PlaceActorAtMe(ChosenBase)			
			endif
		endif
	endif
	
endFunction
Link to comment
Share on other sites

I finally got something that compiles.

When the activator is pressed the first creature from my list gets placed.

Problem is while a new index number gets generated the first creature doesn't get removed and replaced by the next choice.

How does the summon spell get rid of the first creature when another is summoned?

Do I need setCriticalStage?

I can't find anything on Google about getting rid of created references.

 

Actor Property PlayerRef Auto
FormList Property MyList Auto
ObjectReference Property ChosenRef Auto
ObjectReference Property CageMarker Auto
Int Property iIndex auto
Int Property ListSize Auto
Event OnInit()
ListSize = MyList.GetSize() - 1
iIndex = 0
ChosenRef = MyList.GetAt(iIndex) as ObjectReference
ChosenRef.Disable()
ChosenRef.MoveTo(CageMarker)
ChosenRef.Enable(True)
EndEvent
Event OnActivate(ObjectReference akObjectRef)
If akObjectRef == PlayerRef
ChosenRef.Disable(True)
ChosenRef.Delete()
Utility.Wait(2.0)
iIndex = Utility.RandomInt(0,ListSize)
debug.messagebox(iIndex)
ChosenRef = MyList.GetAt(iIndex) as ObjectReference
ChosenRef.Disable()
ChosenRef.MoveTo(CageMarker)
ChosenRef.Enable(True)
EndIf
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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