Da Random
Official Terrarian
I've been having an issue for the past few days and I haven't gotten much progress trying to figure it out.
The issue I'm having is trying to make a method check whether it's daytime or not. However, it only works right after compiling and doesn't get called any other time. I have no clue how to get it to update the local variable isDayTime. I have looked around a bit in Visual Studio with Intellisense and the documentation though I can't find anything sensible.
The code is copied from the thread Here, written by jopojelly. Essentially what I want it to do is:
I am not very familiar with modding Terraria. Though I do know C# rather well. Any assistance in this thread would be greatly appreciated!
The issue I'm having is trying to make a method check whether it's daytime or not. However, it only works right after compiling and doesn't get called any other time. I have no clue how to get it to update the local variable isDayTime. I have looked around a bit in Visual Studio with Intellisense and the documentation though I can't find anything sensible.
The code is copied from the thread Here, written by jopojelly. Essentially what I want it to do is:
- Change the spawn rate each new day when the sun is rising.
- And possibly change it each time you entered the world.
I am not very familiar with modding Terraria. Though I do know C# rather well. Any assistance in this thread would be greatly appreciated!
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace SpawnRate
{
class SpawnRate : Mod
{
public SpawnRate()
{
Properties = new ModProperties()
{
Autoload = true,
};
}
}
class SpawnrateMess : GlobalNPC
{
private static bool isDayTime = Main.dayTime;
private static bool changeSpawnrate = true;
static int spawnRateMult = 200;
static int maxSpawnsEdit = 200;
// Using it to test if it changes when joining the world
// It should randomize between 2-200 (inclusive)
private static int[] test = new int[]
{
2,
200
};
public override void EditSpawnRate(Player player, ref int spawnRate, ref int maxSpawns)
{
spawnRate = (int)(spawnRate / spawnRateMult);
maxSpawns = maxSpawnsEdit;
}
public static void CheckDayTime(ref bool dayTime)
{
isDayTime = dayTime;
if (isDayTime && changeSpawnrate)
{
spawnRateMult = Main.rand.Next(201);
maxSpawnsEdit = 200 - Main.rand.Next(101);
changeSpawnrate = false;
}
else if (!isDayTime)
{
changeSpawnrate = true;
}
}
}
}