• Welcome to AtomicTorch Studio Forums.
 

Spawn scripts with more population density

Started by MightyMonte88, December 07, 2020, 01:53:33 PM

MightyMonte88

Hey i'm wondering how i would go about making a script to spawn in mobs in zones, in much higher numbers. I was able to add Raider NPCs to the game, using the Basic NPC mod (big thanks to Kallvin, the author of Basic NPC ) as an example of how to do so, after a good deal of trail and error i was able to add in two classes of NPC raiders. However, using a script setup like what Kallvin has done, i am only able to get the raiders to spawn in, very spread apart and in few numbers.

Here's the script called to spawn the raider mobs

namespace AtomicTorch.CBND.CoreMod.Zones
{
    using System;
    using AtomicTorch.CBND.CoreMod.Characters.Mobs;
    using AtomicTorch.CBND.CoreMod.Triggers;

    public class SpawnMobsHuman_00 : ProtoZoneSpawnScript
    {
        protected override void PrepareZoneSpawnScript(Triggers triggers, SpawnList spawnList)
        {
            triggers
                .Add(GetTrigger<TriggerWorldInit>())
                .Add(GetTrigger<TriggerTimeInterval>().Configure(TimeSpan.FromMinutes(10)));

            spawnList.CreatePreset(interval: 30, padding: 0.5, useSectorDensity: false)
                     .Add<MobMaleRaider_01>()
                     .Add<MobMaleRaider_02>()
                     .SetCustomPaddingWithSelf(35);
        }
    }
}


And here's how it's being called

.Add(GetScript<SpawnMobsHuman_00>().Configure(densityMultiplier: 10.10));

I've tried adjusting densityMultiplier up to as high as 100 ( it was initially at 0.10) and it doesn't seem to be having any effect....

ai_enabled

Besides density (a reverse value derived from the defined "interval"), each object in the spawn list has a padding setting. For the snippet above:

            spawnList.CreatePreset(interval: 30, padding: 0.5, useSectorDensity: false)
                     .Add<MobMaleRaider_01>()
                     .Add<MobMaleRaider_02>()
                     .SetCustomPaddingWithSelf(35);


as you can see the interval is 30 tiles which means the spawn density will be 1 instance per 30*30 tiles. Even if you set it to zero, it still doesn't mean that you will get objects in each tile because there is also a padding value (0.5) that ensures that this object cannot be spawned closer to any other object than 0.5 tiles. And additionally, there is a custom padding with the objects of exactly the same types as defined in the spawn list ("SetCustomPaddingWithSelf(35)" call) meaning they cannot spawn closer than 35 tiles between each other (which makes the 30 tiles interval basically irrelevant!).
Usually, we're using SetCustomPaddingWithSelf to ensure object will not spawn too close with each other objects of the same type (e.g. pragmiium pillars in the desert should not spawn next to each other; if we simply increase the spawn interval there is still a chance that two objects of the same kind may spawn close as the density is either per sector or for the whole world).

This snippet:

.Add(GetScript<SpawnMobsHuman_00>().Configure(densityMultiplier: 10.10));

is useful only to adjust the density but it cannot adjust the padding setting (as they're often complex with different padding to different kinds of objects, and we never felt necessary to adjust padding this way).

Regards!

MightyMonte88

Thank you big help, i should have entire groups of raiders ready to fight now  :)