tModLoader Any monster spawn rate and spawn cap mod?

Discussion in 'General Mod Discussion' started by Pacze, Aug 27, 2016.

  1. Pacze

    Pacze Terrarian

    Hey there,

    Some friends and me are looking for some very challenging server to play, as we do every now and then.
    What we are missing now is a mod (hopefully that uses tmodloader) that would let us increase the NPC spawn cap and lower the NPC spawn rate (lower meaning faster spawns) on a server.

    I used the search function multiple times with different keywords but couldn't find anything. Except for a piece of code posted by jopojelly some time ago in this thread:
    http://forums.terraria.org/index.php?threads/spawn-rate-question.45066/

    We'd rather avoid using "Cheat Sheet", cause of its extra features.
    So yep, does anyone know about a mod that would actually do this, or any way to do it? We would really appreciate it!

    Also, I'm sorry if i posted this on the wrong section, kinda tried to choose the one that seemed less incorrect to me.

    Grettings,
     
  2. jopojelly

    jopojelly Retinazer

    Well, you can make a folder called "SpawnBoostMod" and make a file called "SpawnBoostMod.cs" in that folder with the following code, then build it using the Mod Sources menu in tmodloader, and it's all ready to go.

    Code:
    using Terraria;
    using Terraria.ModLoader;
    
    namespace SpawnBoostMod
    {
        class SpawnBoostMod : Mod
        {
            public SpawnBoostMod()
            {
                Properties = new ModProperties()
                {
                    Autoload = true,
                };
            }
        }
    
        class SpawnRateMultiplierGlobalNPC : GlobalNPC
        {
            float multiplier = 5f;
            public override void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
            {
                spawnRate = (int)(spawnRate / multiplier);
                maxSpawns = (int)(maxSpawns * multiplier);
            }
        }
    }
    
     
  3. Pacze

    Pacze Terrarian

    thank you jopo! saved us~

    have a nice day ^^
     
  4. Codec

    Codec Terrarian

    Is there anyway to make this only apply if you are under the battle potion effect? Would love to make them about like how the 15x from cheatsheet works.
     
  5. Kazzymodus

    Kazzymodus Lunatic Cultist

    Try this:
    Code:
    using Terraria;
    using Terraria.ModLoader;
    
    namespace SpawnBoostMod
    {
        class SpawnBoostMod : Mod
        {
            public SpawnBoostMod()
            {
                Properties = new ModProperties()
                {
                    Autoload = true,
                };
            }
        }
    
        class SpawnRateMultiplierGlobalNPC : GlobalNPC
        {
            float multiplier = 5f;
            public override void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
            {
                if(player.enemySpawns)
                {
                    spawnRate = (int)(spawnRate / multiplier);
                    maxSpawns = (int)(maxSpawns * multiplier);
                }
            }
        }
    }
    
    I have a hunch that this will stack weirdly, so you will probably have to experiment with different values before it works.
     
    Codec likes this.
  6. Codec

    Codec Terrarian

    Thank you, this works great!
     
    Last edited: Sep 19, 2016
    Kazzymodus likes this.
  7. Shakou

    Shakou Terrarian

    Can i somehow choose how fast and how many mobs will spawn?
     
  8. jopojelly

    jopojelly Retinazer

    spawnRate is the 1:X chance each frame that an NPC will spawn provided maxSpawns isn't reached.
    maxSpawns is the total number of enemy NPC that can spawn. Most NPC count as 1 towards this number, some more, like bosses, some less.

    Adjust those numbers however you like. I used the same multiplier for each, but you can use different numbers if you want to.
     
  9. Shakou

    Shakou Terrarian

    I have no idea how this code works though, what if i want max 250 mobs on the screen while having them spawn 10/sec?
     
  10. jopojelly

    jopojelly Retinazer

    Oh, well the point of the code I posted was to take advantage of Peace candles and Water candles, but if you want it constant no matter what, know that there are 60 frames a seconds, so since you want 10 a second, I think 6 works:

    spawnRate = 6;
    maxSpawns = 250;
     
  11. Shakou

    Shakou Terrarian

    (int)(spawnRate / multiplier);

    Do i need to replace the whole line here with a number?
     
  12. jopojelly

    jopojelly Retinazer

    For what you want, yes, and I already showed you in my previous post.
     
  13. Potency

    Potency Terrarian

    Hey, I'm also looking to increase spawn rates, but the code shown above seems to be constant across all areas. For example, putting 'spawnRate = 6' also applies to Forest (Surface day) and will just make A LOT of slimes appear.

    http://terraria.gamepedia.com/NPC_spawning

    I would like to be able to just halve these spawn rates, while capping the maximum spawns to about 60. For example, I would love if Forest (Surface day) had a spawn rate of 300, and Meteorite (day) to have 120, instead of 600 and 240 respectively. Is this possible?
     
  14. jopojelly

    jopojelly Retinazer

    Yeah, look at the first example I posted earlier in the thread. (multiplier of 2) If you want more specific than 2x spawns depending on the Biome, you'll have to check the zones the player is in.
     
  15. Potency

    Potency Terrarian

    spawnRate = (int)(spawnRate / 2);
    maxSpawns = 60;

    Would I change it to this? Sorry, I'm a complete newb with code.
     
  16. jopojelly

    jopojelly Retinazer

    yes
     
  17. I_come_in_peaces

    I_come_in_peaces Terrarian

    I am so sorry for necrothreading but I'm having a lot of trouble with this because its the first thing I've done with mods and i was wondering if you could post an example with everything thats needed changed or a list of what needs to be changed and the description because I've found nothing on the internet or github (https://github.com/blushiemagic/tMo...Q#sequence-contains-no-matching-element-error) because it says "see ??? for more information"
    Please help, I will appreciate it

    -Clueless terraria modder
     
  18. Buggsoup

    Buggsoup Terrarian

    If you're able to get Cheat Sheet, that has a boost, up to 30x Max Spawn and Spawn Rate.
     
  19. imDED

    imDED Terrarian

    Is there a way to make the spawn rate change apply only to a specific monster?
     
  20. Ok i keep getting errors upon loadup

    code looks like this:

    using Terraria;
    using Terraria.ModLoader;

    namespace SpawnBoostMod
    {
    class SpawnBoostMod : Mod
    {
    public SpawnBoostMod()
    {
    Properties = new ModProperties()
    {
    Autoload = true,
    };
    }
    }

    class SpawnRateMultiplierGlobalNPC : GlobalNPC
    {
    float multiplier = 5f;
    public override void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
    {
    if(player.enemySpawns)
    {
    spawnRate = 6;
    maxSpawns = 50;
    }
    }
    }
    }

    And the error looks like this:
     

    Attached Files: