|
You last visited: Today at 01:14
Advertisement
[Help] Stucked at DateTime.Now
Discussion on [Help] Stucked at DateTime.Now within the CO2 Private Server forum part of the Conquer Online 2 category.
01/12/2012, 09:13
|
#1
|
elite*gold: 0
Join Date: Nov 2010
Posts: 159
Received Thanks: 39
|
[Help] Stucked at DateTime.Now
Quote:
using System.Text;
using Emu.Game;
using Emu.ServerBase;
using Emu.Network.GamePackets;
using System;
namespace Emu
{
public class Monster
{
public static void Spawn(Client.GameState client, ushort mesh)
{
if (DateTime.Now.Minute == 35 && DateTime.Now.Second == 00)
{
Database.MonsterInformation monster = new Emu.Database.MonsterInformation();
monster.Boss = true;
monster.Hitpoints = 50000000;
monster.Level = 140;
monster.Mesh = 950;
monster.Name = "Titan";
monster.MaxAttack = 10500;
monster.AttackRange = 5;
monster.AttackType = 2;
monster.AttackSpeed = 1000;
monster.ViewRange = 2;
monster.MoveSpeed = 500;
monster.RunSpeed = 500;
monster.MinAttack = 59000;
Game.Entity entity = new Game.Entity(Game.EntityFlag.Monster, false, null);
entity.MapObjType = Game.MapObjectType.Monster;
entity.MonsterInfo = monster;
entity.MonsterInfo.Owner = entity;
entity.Name = "Titan";
entity.MinAttack = monster.MinAttack;
entity.MaxAttack = entity.MagicAttack = monster.MaxAttack;
entity.Hitpoints = entity.MaxHitpoints = monster.Hitpoints;
entity.Body = monster.Mesh;
entity.Level = monster.Level;
entity.Defence = 5000;
entity.season = true;
entity.anti_revive = true;
entity.X = 641;
entity.Y = 544;
entity.UID = 500002;
entity.MapID = 1002;
entity.SendUpdates = true;
client.Map.RemoveEntity(entity);
client.Map.AddEntity(entity);
Program.WriteLine("Done");
}
}
}
}
|
His code should spawn monster in time xx.35 but don't work.way?
Thanks for help
|
|
|
01/12/2012, 09:17
|
#2
|
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
|
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.
|
|
|
01/12/2012, 09:26
|
#3
|
elite*gold: 0
Join Date: Nov 2010
Posts: 159
Received Thanks: 39
|
Quote:
Originally Posted by Arco.
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?
|
|
|
01/12/2012, 10:05
|
#4
|
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
|
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.
|
|
|
01/12/2012, 11:58
|
#5
|
elite*gold: 0
Join Date: Nov 2010
Posts: 159
Received Thanks: 39
|
Any more ides way timer don't work?
|
|
|
01/12/2012, 12:07
|
#6
|
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
|
How does your timer code look?
|
|
|
01/12/2012, 12:12
|
#7
|
elite*gold: 0
Join Date: Nov 2010
Posts: 159
Received Thanks: 39
|
System timer
Quote:
if (DateTime.Now.Hour == 20 && DateTime.Now.Minute == 00 && DateTime.Now.DayOfWeek == DayOfWeek.Saturday && DateTime.Now.Second == 00)
{
foreach (Client.GameState client in Kernel.GamePool.Values)
{
Program.WriteLine("Hello");
}
}
}
|
|
|
|
01/12/2012, 12:14
|
#8
|
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
|
I mean the timer that executes your event.
|
|
|
01/12/2012, 20:49
|
#9
|
elite*gold: 0
Join Date: Nov 2010
Posts: 159
Received Thanks: 39
|
Still don't haw answer
|
|
|
01/12/2012, 23:49
|
#10
|
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
|
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);
}
|
|
|
01/13/2012, 02:48
|
#11
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
|
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.
new Thread(new MonsterSpawnThread().Run);
Simple stuff really.
|
|
|
|
Similar Threads
|
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
|
All times are GMT +2. The time now is 01:14.
|
|