maxarturo Posted February 3, 2021 Share Posted February 3, 2021 (edited) Check again the last script posted, i added one more check function as a 'Fail Safe', basically to not call for one more 'Register' after all chicks has been spawned, just a minor script optimization. Edited February 5, 2021 by maxarturo Link to comment Share on other sites More sharing options...
Gruffys Posted February 6, 2021 Author Share Posted February 6, 2021 (edited) I tried my hand at creating a script myself from learning from the one you gave me and although it woks I may have inadvertently caused that chicken apocalypse we spoke of earlier :Dhttp://www.nexusmods.com/skyrimspecialedition/images/97131I wanted one that could spawn a child animal immediately, so this is what I came up with: scriptName BabyAnimalSpawner extends ActiveMagicEffectInt property SpawnAmount = 1 autoInt property SpawnChance =1 autoactorbase property Child autoInt WeightFloat ChanceInt MaxAmountfunction OnEffectStart(Actor Target, Actor Caster)if Target != noneif Target.isDisabled() == falseMaxAmount = SpawnAmountChance = SpawnChanceWeight = utility.RandomInt(1, MaxAmount)if utility.RandomFloat(0.000000, 100.000) <= Chancewhile WeightWeight -= 1Target.PlaceActorAtMe(Child)endWhileendIfendIfendIfendFunction If anyone can suggest any improvements or see any problems with it please let me know as this is my first script and I'm not sure how heavy or awkward this script might be. I plan to add this to base race records like the wolfrace ect. Edited February 6, 2021 by Gruffys Link to comment Share on other sites More sharing options...
maxarturo Posted February 7, 2021 Share Posted February 7, 2021 1) Explain in simple words and in order (A, B, C, ....) what you mean by: "I wanted one that could spawn a child animal immediately" 2) Why are you using "OnEffectStart()" ?. 3) Why are you using "RandomInt()" alongside with a non stop "While" loop ?. I'm really trying to understand what exactly you have in your mind (especially #3), but i can't.... Link to comment Share on other sites More sharing options...
Evangela Posted February 7, 2021 Share Posted February 7, 2021 (edited) Sigh... nevermind. Edited February 7, 2021 by Rasikko Link to comment Share on other sites More sharing options...
Gruffys Posted February 7, 2021 Author Share Posted February 7, 2021 (edited) 1) Explain in simple words and in order (A, B, C, ....) what you mean by:"I wanted one that could spawn a child animal immediately" 2) Why are you using "OnEffectStart()" ?. 3) Why are you using "RandomInt()" alongside with a non stop "While" loop ?. I'm really trying to understand what exactly you have in your mind (especially #3), but i can't.... So the idea is that because I can not add a script to any actor that is in a leveled list I would need to attach the script to a magic effect that is then attached to a spell and I can use that spell on any actor. I set the spell as an ability and whenever its used it runs our script. From looking at other scripts that use this method I assumed that I would need to use the "OnEffectStart()" line in order to get the script to run when the ability is used. I used the "RandomInt()" so that the script picks a random number between 1 and whatever I set the Int Maxamout to. The "While" loop is supposed to keep the script running until it exceeds Int weight (which is set to -1) so that I get anywhere between 1 and maxamount. The issue I am having though is that like you probably already noticed I'm having a problem stopping the script from running once it has spawned a set number of actors. I hope this better explains what I'm trying to do and again thanks for your help. Edited February 7, 2021 by Gruffys Link to comment Share on other sites More sharing options...
Gruffys Posted February 7, 2021 Author Share Posted February 7, 2021 Sigh... nevermind. Thanks for the help Rasikko I wasn't able to to try your suggestion before you edited the post though :( Link to comment Share on other sites More sharing options...
maxarturo Posted February 7, 2021 Share Posted February 7, 2021 (edited) "So the idea is that because I can not add a script to any actor that is in a leveled list..." If you can add a spell to the actor then you can add a script, i can't understand your logic here. BY " Explain in simple words and in order (A, B, C, ....) what you mean by:" I meant: i want to do this. A) My dog goes outside. B) My dog takes a piss. C) Etc...... This way i can understand your idea and what needs to be done. I'll not get into explaining a bunch of issues like using a "while loop" and i will address you with the most important issue of all. Using a "Scripted Ability" will fire every time the script executes. When the player enters a cell that the "carrying scripted ability actor" is in that "Ability" will execute, and when the player leaves that cell the "Ability" will stop and so on.... Each time the "Ability" executes it uses the "Magic Effect" from the beginning, this means that: - You can't get rid of it. - In order to ensure that it will never fire again once it has done its job you will need to use a "Global Variable". - If this "Ability" is used on a bunch of actors then you will need to create a bunch of "Global Variables". There are a lot of stuff to still write but i'm gonna stop here because i have a terrible headache.... I think you want to avoid setting up each actor the appropriate way and just do it the easy way the easy stuff, like setting up one "Ability" and then "Drag and Drop" that to your actors. Edited February 7, 2021 by maxarturo Link to comment Share on other sites More sharing options...
Gruffys Posted February 7, 2021 Author Share Posted February 7, 2021 (edited) Hi max so I'll try to explain a bit better A)You load into a cellB)There is a wolf in the cellC)The wolf has a baby wolf with it Currently because of the fHours function you would need to stand by the wold and wait a set number of hours for the script to have a chance to fire. I did try setting all of the fHours floats to 0 and testing to see if an actor spawned right away but it didn't work.*Ignore this I've just tested it again and it does work if I set fhours to 0. "So the idea is that because I can not add a script to any actor that is in a leveled list...""If you can add a spell to the actor then you can add a script, i can't understand your logic here."I have tried to add the script to some of the actors in my lists but the script box and its buttons are greyed out. I did some research (why-cant-i-add-papyrus-script-to-these-actor-templates) on why this is before I posted and was told that actors that are in level lists can not have scripts attached to them. Have a look at EncWolf in the actor list as an example and you will see what I mean. I do want to do this the appropriate way and I'm happy to set up my actors and yes I didn't have much success with the script I made, it did spawn my actors but like you said I wasn't able to control the amount or stop them from spawning. Sorry this has given you a headache :sad: Edited February 7, 2021 by Gruffys Link to comment Share on other sites More sharing options...
maxarturo Posted February 7, 2021 Share Posted February 7, 2021 (edited) My headache wasn't caused by you, i woke up with it and i have it for the last 2 days, i suffer from migraines So, you want to edit/modify/ to apply this to ALL actors placed in the world. Actors that use a 'Template Actor' will use anything that is added to that 'Actor Base'. Using a "While Loop" for something like this is dangerous, it can easily cause 'Lag' and even CTD. Imagine if you have a mod that adds to the 'Encounter Zones' packs of wolfs, like you run into 10 wolfs and all those wolf are running a "While Loop". The safest way to do this using a 'Scripted Ability' and add a 'Chance' to it, is to: Actor SelfREF EVENT OnEffectStart(Actor akTarget, Actor akCaster) SelfREF = akTarget Int RWolf = Utility.RandomRandomInt(0, 100) If ( RWolf == 0 ) SelfREF.PlaceActorAtMe(Child) EndIf ENDEVENT This way you have 1 out of 100 chance to spawn the "Child", the script fire one time each time the 'Ability' executes and that's it. If you want to increase the 'Chances to Spawn', you do something like this: Actor SelfREF EVENT OnEffectStart(Actor akTarget, Actor akCaster) SelfREF = akTarget Int RWolf = Utility.RandomInt(0, 100) If ( RWolf == 0 ) SelfREF.PlaceActorAtMe(Child) ElseIf ( RWolf == 1 ) SelfREF.PlaceActorAtMe(Child) ElseIf ( RWolf == 2 ) SelfREF.PlaceActorAtMe(Child) EndIf ENDEVENT OR Int Property SpawnMaximum = 2 Auto {The Spawn chances, Default = 2, this means 0 to 2 which means 3 out of 100} Actor SelfREF EVENT OnEffectStart(Actor akTarget, Actor akCaster) SelfREF = akTarget Int RWolf = Utility.RandomInt(0, 100) If ( RWolf <= SpawnMaximum ) SelfREF.PlaceActorAtMe(Child) EndIf ENDEVENT Now you have 3 out of 100 chances to spawn a 'Child', and so on... Edited February 7, 2021 by maxarturo Link to comment Share on other sites More sharing options...
Gruffys Posted February 8, 2021 Author Share Posted February 8, 2021 (edited) Thank you max this looks perfect. I'll set aside a chunk of time to properly test how heavy this is going to be on large groups of actors by spawning a pile in Whiterun and checking the performance monitor tool. Just out of interest in regards to increasing spawn chance could we not for example just chance Int RWolf = Utility.RandomInt(0, 100) to something like Int RWolf = Utility.RandomInt(0, 1) would this not give the actor a 50% chance to spawn? Or does it not work like that? I've just tested the idea I had above and while it does work your last example with Int Property SpawnMaximum would be a better way to do it. Does If ( RWolf <= SpawnMaximum ) get the script to run however many time is defined in the SpawnMaximum Int in order to spawn a wolf or does the script just take the Int and calculate the result once? Edited February 8, 2021 by Gruffys Link to comment Share on other sites More sharing options...
Recommended Posts