BurnTheBooks Posted January 7, 2015 Share Posted January 7, 2015 Hello, I was messing with some scripts for my small mod. The thing I need to do is to spawn actors from the list at certain conditions at random. Actors are unique and essential so I can use them as followers. The thing I got stuck on is, that sometimes, the same actor is randomly picked twice (it does not happen often, as the list is 30 actors long) but I would still very much like to avoid it at all. The question is, is there a way to check with papyrus if certain actorbase is already spawned in game? or is there a better way to prevent this duplicate spawning? Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 7, 2015 Share Posted January 7, 2015 Make the actor Unique. http://puu.sh/ecY3p/92a0e0da2c.png Link: http://www.creationkit.com/Category:Actor Link to comment Share on other sites More sharing options...
BurnTheBooks Posted January 8, 2015 Author Share Posted January 8, 2015 Yep, already have them as unique. The script doesn't care though :) since it is selecting actors at random. It spawns the actor even if it is flagged as unique, the game then counts them both as the same entity and for example if you make the first occurance as follower, both are now behaving as followers. I am trying to prevent the spawn in the papyrus script by some condition which will first look for the actor/actorbase in game and after that pass or fail actor placement itself. Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 8, 2015 Share Posted January 8, 2015 (edited) Then make a variable for each actor that changes to 1 when they are summoned, and to 0 when they dissapear. If that variable is bigger than 1 then add a condition so that actor won't be summoned unless the variable is 0. Your script will be a lot bigger but it will work. OR you could check if the Actor you have summoned already exists, and set that as a condition instead of a random variable. Edited January 8, 2015 by Kerberus14 Link to comment Share on other sites More sharing options...
BurnTheBooks Posted January 8, 2015 Author Share Posted January 8, 2015 (edited) Check if the actor already exists would be nice, I just cant find a function to check exactly that :D. I believe it would be better to check if actor I want to place exists than and then decide instead od declaring new value for each actor in the list. I only found this:http://www.creationkit.com/GetDeadCount_-_ActorBase which is not an option here. EDIT: I do not understand why I can count dead actors, with no simmilar function to count the living ones :D Edited January 8, 2015 by BurnTheBooks Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 8, 2015 Share Posted January 8, 2015 Maybe you could check if the Actor is Unique then.Bool IsUnique() Since ticking that box does nothing(but I figure they are tagged as Unique, which would make the above work), you could make it do something in Papyrus. Link to comment Share on other sites More sharing options...
BurnTheBooks Posted January 8, 2015 Author Share Posted January 8, 2015 One posibility could be: make them non essential in creation kit, and while selecting them from the list, make the actorbase essential with ActorBase script SetEssential(Bool abEssential). while spawning I could then check used actor base if it is essential or not. Does this sound reasonable? :D I am not sure if only that one instance mentioned would be essential or all other instances of that actorbase would be essential (which I am hoping for). Link to comment Share on other sites More sharing options...
Kerberus14 Posted January 8, 2015 Share Posted January 8, 2015 You could try and see if it works instead of asking if it doesn't work.Although if you made them Unique in Creation Kit you could check if they are tagged as Unique as I've said, pretty much doing the same thing, except you'd be adding some extra lines. Link to comment Share on other sites More sharing options...
BurnTheBooks Posted January 8, 2015 Author Share Posted January 8, 2015 Well, the thing is, papyrus can spawn actor flagged as unique multiple times. And I can't know for sure if the actor I am spawning is an actor used in game already or a new one from the list since it is picked at random. as for the method mentioned, I will test it tomorrow morning. The essential flag can be changed for specific actorbase by papyrus, so it could in essence work as the variables you mentioned before. Link to comment Share on other sites More sharing options...
smashly Posted January 8, 2015 Share Posted January 8, 2015 (edited) If your after to just spawn your own unique actors and want to make just own unique actors are only spawned once.Then you have no option but to track them yourself.Spawning only once unless the spawned actor dies and you can allow them to be spawned. Here's a crude nock up example of random spawning your own unique actors from your list only once: Scriptname SpawnRandomNPCFromList extends Quest ;Assign this to Your list of your own personal actors to use. FormList Property MyNPCList Auto ;Assign this to an empty Tracking list that filled as you spawn your unique actors. FormList Property MyNPCTrackList Auto ;Just registering a key so I can test spawning. Event OnInit() RegisterForKey(51) ; Comma Key EndEvent ;Catching the key to spawn the actor Event OnKeyDown(Int KeyCode) If !Utility.IsInMenuMode() If KeyCode == 51 ; Comma Key SpawnNPC() EndIf EndIf EndEvent ;spawn random based on what npcs from your unique list are not in use. Function SpawnNPC() Int idx = MyNPCList.GetSize() ; Return if Tracking list is same size as NPC list If idx == MyNPCTrackList.GetSize() Debug.Notification("All NPC's are in use.") Return EndIf ;Store Available Indexes here (Doesn't need to be 128, but you can't initiate an array with a variable eg: idx). Int[] iAvailable = New Int[128] Int iCnt = -1 ;Fill an array of available indexes that are not in use While idx idx -= 1 If !MyNPCTrackList.HasForm(MyNPCList.GetAt(idx)) iCnt += 1 iAvailable[iCnt] = idx EndIf EndWhile ;We have the array populated with only what NPC's indexes that aren't used, select a random number between 0 and iCnt, spawn the npc and add it to the track list. If (iCnt > -1) MyNPCTrackList.AddForm(Game.GetPlayer().PlaceActorAtMe(MyNPCList.GetAt(iAvailable[Utility.RandomInt(0, iCnt)]) As ActorBase).GetBaseObject() As Form) Debug.Notification("Actors Left: " + iCnt) EndIf EndFunctionI did compile the code and created a test plugin with an empty quest, attached the script to the quest, assigned the 2 Formlists once attached and it works for me.Obviously you would apply the code to your own needs, but this gave me a random spawn each press of the button until there where no npcs left to choose If you would like the actors to be reused if they die then attach something like this to each actor in your list. Scriptname ClearMySpawn extends Actor ;Assign this to your track list. FormList Property MyNPCTrackList Auto Event OnDeath(Actor akKiller) MyNPCTrackList.RemoveAddedForm(Self.GetBaseObject() As Form) Self.DeleteWhenAble() EndEventWhat would help in future would be if you posted a snippet of your code your using.This way people wouldn't have to assume or guess what your attaching your script to and could probably give pointers as to where to change your code to suite. Edited January 9, 2015 by smashly Link to comment Share on other sites More sharing options...
Recommended Posts