blazeda59 Posted June 18, 2016 Share Posted June 18, 2016 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 More sharing options...
KaelVirum Posted June 18, 2016 Share Posted June 18, 2016 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 More sharing options...
blazeda59 Posted June 18, 2016 Author Share Posted June 18, 2016 Thanks but I don't think that will work since the scripts I need to attach are a workshop object script and the other script is sending a OnDeath event. So they need to be on the actor to work. Link to comment Share on other sites More sharing options...
ousnius Posted June 18, 2016 Share Posted June 18, 2016 if NPCSpawner01 == IsEnabled()Are you sure this isn't supposed to be this? if NPCSpawner01.IsEnabled() Link to comment Share on other sites More sharing options...
blazeda59 Posted June 18, 2016 Author Share Posted June 18, 2016 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: Link to comment Share on other sites More sharing options...
ousnius Posted June 18, 2016 Share Posted June 18, 2016 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()orObjectReference == Bool Proof:http://www.creationkit.com/fallout4/index.php?title=IsEnabled_-_ObjectReference Link to comment Share on other sites More sharing options...
blazeda59 Posted June 18, 2016 Author Share Posted June 18, 2016 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: Link to comment Share on other sites More sharing options...
Engager Posted June 19, 2016 Share Posted June 19, 2016 (edited) 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 June 19, 2016 by Engager Link to comment Share on other sites More sharing options...
blazeda59 Posted June 19, 2016 Author Share Posted June 19, 2016 It's ok I figured it out I don't need to spawn from a FormList now. I can setup a LeveledList and use that as a template on the NPC instead. Now I can attach all the scripts that I need. Link to comment Share on other sites More sharing options...
Engager Posted June 19, 2016 Share Posted June 19, 2016 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 More sharing options...
Recommended Posts