I'm coding primarily in PHP. I'm wanting to have guild like entities be able to challenge each other to "wars" that would last a certain duration of 1-2 days long for points. I'm wondering if there is an easier way than me using a cron to this. I was thinking on the day a group gets challenged I could swap the variable to some type of ready modifier then start all wars for the day at say midnight server time swap the ready to in progress and run the duration.... then the next time the cron runs it shuts off all wars in progress and queues all the readies again. This seems kinda bulky and hard to sort out any type of dynamic loot/points if I was to use a cron. I can't think of an easier way tho. Is there a way to use time stamps of some kind effectively for this?
Any ideas would be appreciated. Thanks.
War Timer?
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: War Timer?
If I am understanding right, guilds will be able to challenge other guilds, at which point members of those guilds will be able to take some kind of hostile action towards each other, but only for up to 2 days? To do this without crons, set up the challenge to set a "startTime" field in the database. I believe you can simply insert NOW() into the database to capture the current time. Use that time stamp to calculate the last possible time when actions can occur (you could easily set this to be in 48 hours, or use a static time variable for midnight, and dynamically add in the date). Anytime a member of the guild is going to make a hostile action, since you have to check the database and make sure they are warring anyway, check the war closing time versus the current time to make sure the current time is still within the boundaries of the war.
The indelible lord of tl;dr
Re: War Timer?
Nice idea thanks for that. I'm still pretty clueless on how to manage the time functions outside of displaying the time now.
The players will be able to engage in pvp anytime they want but challenges against another group will give some extra benefits like exp for the "guild" exp for the players from the kills and possibly some equipment type items for special events i.e holidays.I want the wars to be long enough that the average active user can participate because the combat system is 1 sided as far as any interaction is involved but points will add up based on some different factors. So guild 1 will challenge guild 2 the "war" will last 24 or 48 hours (I'm undecided) A gank fest happens. Then when the time has expired the winner takes the spoils the guild points and of course moves up the ladder of guild rank e-peen. As A side note I also wanted the 2 "guilds" to have a window with the current enemy player names and the like for ease of attacks.
It gets sort of complex. I was hoping to do it case by case but if needed I could probably find a fixed equation that worked out nicely if I did have to do crons. I'll have to play with it and see what I can get functioning.
The players will be able to engage in pvp anytime they want but challenges against another group will give some extra benefits like exp for the "guild" exp for the players from the kills and possibly some equipment type items for special events i.e holidays.I want the wars to be long enough that the average active user can participate because the combat system is 1 sided as far as any interaction is involved but points will add up based on some different factors. So guild 1 will challenge guild 2 the "war" will last 24 or 48 hours (I'm undecided) A gank fest happens. Then when the time has expired the winner takes the spoils the guild points and of course moves up the ladder of guild rank e-peen. As A side note I also wanted the 2 "guilds" to have a window with the current enemy player names and the like for ease of attacks.
It gets sort of complex. I was hoping to do it case by case but if needed I could probably find a fixed equation that worked out nicely if I did have to do crons. I'll have to play with it and see what I can get functioning.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: War Timer?
While there are some more specific MySQL-based time formats that may be more elegant, an easy way to handle time is to use the time() function. It returns the number of seconds since the Unix epoch (midnight on January 1st, 1970). It makes it extremely easy to do math with very exact times. If you need to record a date 1 hour from your base date, multiply 60 * 60 (seconds in a minute * minutes in an hour) and add that number to your base variable. For 1 day in the future, multiple 60 * 60 * 24, and add that to the number. Then when you need to check to make sure the warring action is within the time boundary, use another time() call to get the current time, subtract that amount of seconds from the war end time amount of seconds, and make sure the result is >= 0. If the number is negative, the action is outside of the time boundary, and should not be executed. If the result is positive, it is still prior to the end of the war.
The downside to this ease of use, though, is that unix Epoch-style time stamps are quite large integers and can be kind of bulky in the database. However, even a couple hundred players warring quite often would not be able to produce enough timestamps to really cause any performance issues.
The downside to this ease of use, though, is that unix Epoch-style time stamps are quite large integers and can be kind of bulky in the database. However, even a couple hundred players warring quite often would not be able to produce enough timestamps to really cause any performance issues.
The indelible lord of tl;dr
- PaxBritannia
- Posts: 680
- Joined: Sun Apr 18, 2010 1:54 pm
Re: War Timer?
Or you could store it as datetime and then convert it into a unix timestamp when you do the comparisons.
Pax.
Pax.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: War Timer?
True. I could not remember the function name to look it up in the PHP documentation. What was it called again?
The indelible lord of tl;dr
- PaxBritannia
- Posts: 680
- Joined: Sun Apr 18, 2010 1:54 pm
Re: War Timer?
To convert the datetime field to timestamp in the mysql query, use "unix_timestamp()"
To convert it in php, use "strtotime"
Pax.
To convert it in php, use "strtotime"
Pax.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: War Timer?
Ahh, that's right. I have not had to use much if any date manipulation in my PHP applications yet, and only had seen them in books.
The indelible lord of tl;dr
Re: War Timer?
So they battle once per day for two days? Jackolanterns pretty much said it - you record a timestamp of when the battle starts, dividing it down to the day. Then when a player checks in you get it to check if one or two days have passed, then run one or two battles accordingly.
The freaky part is that if no players in the battle checked in for eight years, nothing happens until they check in (unless you use a cron). But to them, when they check in, it'll look like the battle happened eight years ago. So to speak. Database events don't need to match actual real time.
The freaky part is that if no players in the battle checked in for eight years, nothing happens until they check in (unless you use a cron). But to them, when they check in, it'll look like the battle happened eight years ago. So to speak. Database events don't need to match actual real time.
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
- PaxBritannia
- Posts: 680
- Joined: Sun Apr 18, 2010 1:54 pm
Re: War Timer?
Weird... there are two cron topic alive now.
What I've done is run crons every minute. If you can't do that you could simulate a cron by having in every page a command to check the db how long ago the cron was last performed and then include the cron script if it needs to be run.
But if you don't need the battle to update then you could make it update when logging back in. However, there may be some issues:
If player A is in a battle with player B.Then player C starts a battle with player A.
Both player A and B do not log in after two days.Player C logs in.
On the third day, A logs in. The health of player A would have changed before the battle with B was calculated.
Tell me if it doesn't make sense.
Pax.
What I've done is run crons every minute. If you can't do that you could simulate a cron by having in every page a command to check the db how long ago the cron was last performed and then include the cron script if it needs to be run.
But if you don't need the battle to update then you could make it update when logging back in. However, there may be some issues:
If player A is in a battle with player B.Then player C starts a battle with player A.
Both player A and B do not log in after two days.Player C logs in.
On the third day, A logs in. The health of player A would have changed before the battle with B was calculated.
Tell me if it doesn't make sense.
Pax.