Jump to content

Spawing a random actor from a list?


blazeda59

Recommended Posts

Hi I'm trying to setup a script that will spawn a random actor from a FormList I've setup. I can get it to spawn randomly if I use a LeveledList but I need to be able to attach scripts to the npcs and for some reason you can't use actors with scripts in LeveledLists. I've tried using a random int but when I load the game nothing will spawn when I activate the script.

 

Here's what I have. I'm hoping someone knows how to do this thanks.

Scriptname RandomSpawnScript extends ObjectReference


FormList Property NPC Auto Const
Furniture Property NPCSpawner01 Auto Const
Keyword Property SpawnLinkKeyword Auto Const
ObjectReference Property SpawnerMoveMarker Auto Const

Event OnLoad()

        ObjectReference NPCSpawnerRef = Self

	Actor RandomGuyRef
	RandomGuyRef = NPC.getat(Utility.RandomInt(0,NPC.GetSize() -1)) as Actor

	if NPCSpawner01 == IsEnabled()
	        Self.PlaceAtMe(RandomGuyRef)
		NPCSpawnerRef.MoveTo(SpawnerMoveMarker)
		NPCSpawnerRef.AddKeyword(SpawnLinkKeyword)
		RandomGuyRef.SetLinkedRef(NPCSpawnerRef, SpawnLinkKeyword)
	endif

EndEvent
 
Link to comment
Share on other sites

I'm not fluent in script, as of yet, I dabbled in it during Skyrim but didn't get very far, but have you tried placing an item in their inventory and attaching the script you want to that so that it affects them the same way as if it were attached to them? I know that it's possible for a script attached to an item to influence the actions of the npc that holds the item but I'm not sure if it would be a workaround for your issue. It's just a thought but I hope it helps.

Link to comment
Share on other sites

No IsEnabled() is an event not a function. Your thinking of NPCSpawner01.Enable(). The if statement is checking to see if the spawner is enabled not actually enable it. :smile:

 

No, IsEnabled() is a function that returns a Bool. You have to call it on an object reference of NPCSpawner01 like I did.

 

The way you are calling it, it is merely doing this, which doesn't work:

NPCSpawner01 = self.IsEnabled()

or

ObjectReference == Bool

 

Proof:

http://www.creationkit.com/fallout4/index.php?title=IsEnabled_-_ObjectReference

Link to comment
Share on other sites

No its ok I believe you..Sorry I'm the mixed up one I was thinking of OnEnable. Its just the way you stated your comment it sounded more like a question. Well I've change it around but the npc still wont spawn :wallbash:

 

Sure they won't since with script like that.

Scriptname RandomSpawnScript extends ObjectReference

FormList Property NPC Auto Const
Keyword Property LinkKeyword Auto Const
ObjectReference Property MoveMarker Auto Const
ObjectRererence Property LinkFurniture Auto Const

Event OnLoad()

  Actor akRandomGuy = NPC.getat(Utility.RandomInt(0,NPC.GetSize() -1)) as Actor
  ObjectReference NewGuy = (Self as ObjectReference).PlaceAtMe(akRandomGuy) as ObjectReference
  NewGuy.MoveTo(MoveMarker)
  NewGuy.SetLinkedRef(LinkFurniture, LinkKeyword)

EndEvent
Edited by Engager
Link to comment
Share on other sites

Correction:

Scriptname RandomSpawnScript extends ObjectReference

FormList Property NPC Auto Const
Keyword Property LinkKeyword Auto Const
ObjectReference Property MoveMarker Auto Const
ObjectRererence Property LinkFurniture Auto Const

ObjectReference NewGuy

Event OnLoad()

  Actor akRandomGuy = NPC.getat(Utility.RandomInt(0,NPC.GetSize() -1)) as Actor
  NewGuy = (Self as ObjectReference).PlaceAtMe(akRandomGuy) as ObjectReference
  NewGuy.MoveTo(MoveMarker)
  NewGuy.SetLinkedRef(LinkFurniture, LinkKeyword)
  RegisterForRemoteEvent(NewGuy, "OnUnload")

EndEvent

Event ObjectReference.OnUnload(akSender as ObjectReference)
  if (akSender == NewGuy)
    NewGuy.DisableNoWait(false)
    NewGuy.Delete()
    NewGuy = None
  EndIf
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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