x


How to use real life timer

What i am trying to do: event in game like a boss spawn, it got killed. the time when it is killed is recorded in real life time. After 24 hours or 6 hours of real life time, it will re-spawn once a player enter the map.

I had read this: http://msdn.microsoft.com/en-us/library/system.datetime.now%28VS.80%29.aspx

I can records the time when boss get killed. do not know how to check if 24 hours or 6 hours has passed after boss gotten kill.

prefer help with the codes in java, or C#

any help would be much appreciated.

more ▼

asked Jan 13 '12 at 04:07 PM

hdy gravatar image

hdy
1 2 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If you already know how to get the current time with datetime.now, just do the same thing in an update event, and compare the death tiem with the current time, and respawn if the desired time has elapsed.

-Larry

more ▼

answered Jan 13 '12 at 04:28 PM

Larry Dietz gravatar image

Larry Dietz
472 9 13 23

I guess i should say i don't know how to compare them.

DateTime saveTime = DateTime.Now;

then on the update event...

This is the line that i dont know how to code:

if ( (DateTime.Now - saveTime) > 12){

monsterRespawn();}

Jan 13 '12 at 04:40 PM hdy

Try something like...

if ((DateTime.Now-saveTime).Hours > 12){ monsterRespawn(); }

-Larry

Jan 13 '12 at 05:25 PM Larry Dietz

ah .Hours! Thank you

Jan 13 '12 at 05:30 PM hdy

Glad I was able to help.

-Larry

Jan 13 '12 at 05:32 PM Larry Dietz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x589
x356
x111
x28

asked: Jan 13 '12 at 04:07 PM

Seen: 748 times

Last Updated: Jan 13 '12 at 05:32 PM