Erm, what I would do is make a thread, checking for that time periodically, then execute that once the time has come. And make a bool and so it doesn't keep trying to spawn the mob after it has already spawn.
Erm, what I would do is make a thread, checking for that time periodically, then execute that once the time has come. And make a bool and so it doesn't keep trying to spawn the mob after it has already spawn.
If mob spawned client.Map.RemoveEntity(entity);
client.Map.AddEntity(entity);
Server remove it and add new one
Or it is not ***?
#edit his code don't work way?
Don't use DateTime.Now.Second, because your thread/timer might not hit exactly at the second, rather use a boolean to check if it have been executed once.
Okay simple.
In program cs create a new variable,
public static Thread MonsterThread;
and then,
public static Boolean MonsterSpawned = false;
Then inside the main void, initialize it.
MonsterThread = new Thread(Monster.Spawn);
MonsterThread.Start();
Then the Monster.Spawn void do someshit like
public static void Spawn(GameClient Client, UInt16 Mesh)
{
if (Blah blah time check && !Program.MonsterSpawned)
{
All that spawn ****.
Program.MonsterSpawned = true;
//And if you plan on resetting your server once a day, then you can just abort the thread. Likee so,
Program.MonsterThread.Abort();
}
else
Thread.Sleep(500);
}
So wait.. you want to spawn a monster EVERY hour at 35 minutes?
It's easier if your source handles spawn times in a particular way but it's not too much harder to do it this way (note: albetros uses a 'spawndelay' int which could just be set on mob dying but that's beside the point).
Here's how I'd do it with a thread though... (simplest way really)
public class MonsterSpawnThread
{
public void Run()
{
while(true)//infinite loop. use break; or return; to exit the thread!
{
try
{
if(DateTime.Now.Minute == 33)
{
//Spawn monster Code
Thread.Sleep(60000);//sleep for one minute so that the thread CANNOT re-execute this code within the same minute
}
}
catch{}
Thread.Sleep(30000);//run thread every 30 seconds
}
}
}
Now when starting up server you have to start this thread.
C# DateTime Struktur Problem 11/15/2011 - .NET Languages - 0 Replies Hey,
ich hab ein Problem... ich möchte eine Anloguhr darstellen, dazu benutz ich eine fertige .dll von CodeProject: Link
Nun will ich eine eigene Zeit einstellen (nicht DateTime.Now)...
Wie bei CodeProject klappt der Code ganz gut...
analogClock1.Time = DateTime.Now;
Nur will ich ja eine eigene Zeit....
Ich hab schon einiges ausprobiert, aber iwie habe ich immer einen Fehler drin :(
String MyString;
MyString = "15.11.2011 " + sys_hour + ":" + sys_min +...
datetime and count 09/14/2010 - CO2 Private Server - 2 Replies okay i was trying to count how long an action took.
but it counted how long it took to send the action, but not how long it took.
How can i make it count after the action is send.
And yea I did put the time after the action, but still doing it.
Something I can use to check if action is done?
Is for 5165 tanel.
DateTime Guild War 12/16/2009 - CO2 Private Server - 5 Replies Alright well in the 5165 source I made a datetime start for guild war.
Here's the code.
public static void GuildWarTime()// On or Off
{
if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday && DateTime.Now.Hour == 2 && DateTime.Now.Minute == 15)
{
StartWar();
}
}
[QUESTion] DateTime Help 07/23/2009 - CO2 Private Server - 6 Replies Ok im looking at this one datetime im trying to make one but i dont understand this hour part where it says ServerTime.Hour == 8 what time is the 8 lol
else if ((World.ServerTime.DayName == "Monday" || World.ServerTime.DayName == "Wednesday") && World.ServerTime.Hour == 8 && World.ServerTime.Minute == 50)
[HELP] Datetime error 06/23/2009 - CO2 Private Server - 0 Replies Ok im geting this error when i try to load 10 expballs per day here it is http://img188.imageshack.us/img188/8279/erroryfn.p ng