Jump to content

Need Some help spawning npcs.


Gruffys

Recommended Posts

I'm looking for someone to help in point me in the right direction in regards to spawning an actor via a spell.

 

In essence I am trying to make a conjuration spell which when added to a chicken's ability list will cause them to summon a chick. I've copied the original summon familiar conjuration spell and adjusted the variables but have not been able to get my chicken to cast/use the ability. It would be great if possible to have this spell fire off randomly to create a little variety too.

 

Does anyone know if its possible to do something like this? Would it be cleaner to use a script to achieve the result?

Link to comment
Share on other sites


On your chicken's "Actor's Property" add this script, or in the "Reference Property Window" in the script tab.

* Don't add it to the vanilla actor but create your own actor.

ActorBase Property MyChick Auto
{The Chick / the actor to choose from the SCRIPT'S PROPERTY DROP DOWN MENU}

Float Property fHours01 = 72.0 Auto
{The random 01 hours value in game to fire the spawn a Chick, Default = 72h > 3 days}

Float Property fHours02 = 144.0 Auto
{The random 02 hours value in game to fire the spawn a Chick, Default = 144h > 6 days}

Float Property fHours03 = 216.0 Auto
{The random 03 hours value in game to fire the spawn a Chick, Default = 216h > 9 days}

Bool Property IsRunning = False Auto Hidden


AUTO STATE SEQ01
EVENT OnLoad()
If ( IsRunning == False )
IsRunning = True
RandomChick()
GoToState("SEQ02")
EndIf
ENDEVENT
ENDSTATE


STATE SEQ02
EVENT OnDying(Actor akKiller)
UnregisterForUpdateGameTime()
Self.SetCriticalStage(3)
GoToState("SEQ03")
ENDEVENT
ENDSTATE


STATE SEQ03
EVENT OnCellDetach()
Self.SetCriticalStage(4)
ENDEVENT
ENDSTATE


EVENT OnUpdateGameTime()
If ( Self.IsDead() == False )
Self.PlaceActorAtMe(MyChick)
RandomChick()
EndIf
ENDEVENT


FUNCTION RandomChick()
Int RC = Utility.RandomInt(0, 2)
If ( RC == 0 )
RegisterForSingleUpdateGameTime(fHours01)
ElseIf ( RC == 1 )
RegisterForSingleUpdateGameTime(fHours02)
ElseIf ( RC == 2 )
RegisterForSingleUpdateGameTime(fHours03)
EndIf
ENDFUNCTION





* Add your "Random Hours Values" to fit your needs, i just added some random values like 3, 6 and 9 days.


* In the chicken script's property you need to assign the "Chick" in the "ActorBase" part of the script.


EDIT: I forgot about an important issue so i change the script and set up, if you had already read the post, read it again.



NOTE: If a 'Save' is loaded while the player is in the same cell with the chicken the script will not fire, but it will once the cell gets unloaded and you enter that cell again.


* This is just one way to do it.



Have a happy modding.

Edited by maxarturo
Link to comment
Share on other sites

Wonderful thank you so much for the help Maxarturo, Ill get to testing this right away! Its so useful to have a script to pick apart and learn from too :smile:. I'll update you on my progress as I think I will be adding this script to a few actors to dynamically spawn in baby variant's.

 

 

Hmm so I have added the script in and assigned my chick (EncChick) to both of the my chick parts but unfortunately it fails to compile and I get the following errors:

 

Starting 1 compile threads for 1 files...
Compiling "skytestChickSpawn"...
D:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\skytestChickSpawn.psc(6,15): cannot initialize a float to 72
D:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\skytestChickSpawn.psc(9,15): cannot initialize a float to 144
D:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\skytestChickSpawn.psc(12,15): cannot initialize a float to 216
D:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\skytestChickSpawn.psc(30,0): function ondying cannot be defined in state seq02 without also being defined in the empty state
D:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\skytestChickSpawn.psc(37,13): IsDead is not a function or does not exist
D:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Scripts\Source\temp\skytestChickSpawn.psc(37,22): cannot compare a none to a bool (cast missing or types unrelated)
No output generated for skytestChickSpawn, compilation failed.
Batch compile of 1 files finished. 0 succeeded, 1 failed.

 

I can see that the timing parts at the top are causing the float errors but I'm not at all proficient at scripting so sadly I'm not sure how to go about fixing those lines.

Edited by Gruffys
Link to comment
Share on other sites

This is a simple script and on my end the script compiles just fine and it's working as it supposed to, do not edit or add your stuff to the script if you don't know what you are doing.


"I have added the script in and assigned my chick (EncChick) to both of the my chick parts"

Just COPY > PASTE the script and don't change anything to it, ONLY change its values from the script's PROPERTIES.


* The script must extend ACTOR.


* The script is added to the actor and not to some 'Magic Effect'.


Make a new post if you need some help, editing the same post does not send a notification message.

Edited by maxarturo
Link to comment
Share on other sites

Fantastic! it was * The script must extend ACTOR. that was causing the issue as I had left it with the default extend data. Thank you so much for all your help and patience maxarturo!

Btw Is there anyway to test to make sure the script is working? I've been testing my chicken in qasmoke and even after waiting for a few days I wasn't able to get a chick to spawn, is this because I am using the wait to pass the time or is it simply to do with the save function stopping the script from firing like you said previously?

 

Update: Ok so I have my chicks spawning now, I had to adjust my "Random Hours Values" a little.

 

One last question though, what does the "Random Hours Values" reference? I'm assuming that for every Float Property fHours a chick will spawn up to a max of 3 and should one get killed the script will generate another chick based on the lowest fHours value? Is this right or will the script only spawn 3 chicks and none after if some are killed?

Edited by Gruffys
Link to comment
Share on other sites

The:

Float Property fHours01 = 72.0 Auto

Float Property fHours02 = 144.0 Auto

Float Property fHours03 = 216.0 Auto

Are the days in > "In-Game Hours" that the "Function" to spawn 1 chick will "Randomly Choose One From the Three Values" to spawn ONE CHICK.


When the chicken dies the script will no longer run, no chick will be spawn.

If the dead chicken it's still spawning chicks then this has to be with the fact that you are using a 'Save File' that has seen the mod, to be more precise: the script is baked into your save file and if any changes were made to it will make the script to malfunction on your existing 'Save File'.

Edited by maxarturo
Link to comment
Share on other sites

Ah ok thank you for the clarification. I presume I should set the Float Property fHours fairly high then seeing as there is no function to stop chicks from spawning once a certain number has already appeared. I wouldn't want to be the man who started the chicken apocalypse :D

 

Am I correct in thinking that the script wont fire if the player is out of the cell that the chicken is in? Or could I come back to farm cell after 40 days and find a bunch a chicks spawned?

Edited by Gruffys
Link to comment
Share on other sites

Yeah.... chicken apocalypse !!!
Here is the same script with the added 'Fail Safes' and restrictions, read the descriptions in the script, and again change the values ONLY from the Script's Properties.

 

 

ActorBase Property MyChick Auto
{The Chick / the actor to choose from the SCRIPT'S PROPERTY DROP DOWN MENU}
 
Int Property MyChickMaximum = 3 Auto
{The maximum amount of Chicks that is allow to be spawn, Default = 3 Chicks}
 
Float Property fHours01 = 72.0 Auto
{The random 01 hours value in game to fire the spawn a Chick, Default = 72h > 3 days}
 
Float Property fHours02 = 144.0 Auto
{The random 02 hours value in game to fire the spawn a Chick, Default = 144h > 6 days}
 
Float Property fHours03 = 216.0 Auto
{The random 03 hours value in game to fire the spawn a Chick, Default = 216h > 9 days}
 
Bool Property IsRunning = False Auto Hidden
 
Int ChickCount
 
 
AUTO STATE SEQ01
EVENT OnLoad()
   If ( IsRunning == False )
        IsRunning = True
        RandomChick()
        GoToState("SEQ02")
EndIf
ENDEVENT
ENDSTATE
 
 
STATE SEQ02
EVENT OnDying(Actor akKiller)
        UnregisterForUpdateGameTime()
        Self.SetCriticalStage(3)
        GoToState("SEQ03")
ENDEVENT
ENDSTATE
 
 
STATE SEQ03
EVENT OnCellDetach()
        Self.SetCriticalStage(4)
ENDEVENT
ENDSTATE
 
 
EVENT OnUpdateGameTime()
   If ( Self.IsDead() == False )
      If ( ChickCount <= MyChickMaximum )
           Self.PlaceActorAtMe(MyChick)
        If ( ChickCount >= MyChickMaximum )
             Return
      Else
             RandomChick()
     EndIf
   EndIf
EndIf
ENDEVENT

 
 
FUNCTION RandomChick()
    ChickCount = ChickCount + 1
    Int RC = Utility.RandomInt(0, 2)
    If ( RC == 0 )
         RegisterForSingleUpdateGameTime(fHours01)
ElseIf ( RC == 1 )
         RegisterForSingleUpdateGameTime(fHours02)
ElseIf ( RC == 2 )
         RegisterForSingleUpdateGameTime(fHours03)
 EndIf
ENDFUNCTION

Have a happy modding.
Edited by maxarturo
Link to comment
Share on other sites

Lol I guess we have avoided the apocalypse for now then. Yeah I've done some preliminary testing on my chickens and I am super pleased with how this is working. Thanks again for all the hand holding, like I said I haven't dabbled with scripts before because as you stated they get baked into saves. If I am going to add one in it needs to be perfect as I don't want to break peoples games :D

Link to comment
Share on other sites

  • Recently Browsing   0 members

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