Hey guys, as the title says, im making the PvP for my browser game.. and i need to check for the time of the battle so it works right.. but i cant do it from hour to hour because that's too much...
My concern is that second by second it puts the server too laggy... what can i do for this?
Runcron for PvP what interval?
- vitinho444
- Posts: 2825
- Joined: Mon Mar 21, 2011 4:54 pm
- Foofighter
- Posts: 121
- Joined: Sun Mar 04, 2012 1:52 pm
Re: Runcron for PvP what interval?
why do you need to refresh the page so often?
pls describe how your pvp system works?
what time of the battle?
pls describe how your pvp system works?
what time of the battle?
- vitinho444
- Posts: 2825
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Runcron for PvP what interval?
ok it goes like this:
Player chooses troops basicly, then they are removed from the village and stored in a db with the id of the 2 players, the attack and defense power and the time of arrival.
Then i want to make a script that checks, if there's a battle, for the time of arrival = current time..
Then i will calculate both attack and defense powers and make the result of the battle..
It can be anything else besides runcron but i dont know any other way so im asking you guys
Thanks
Player chooses troops basicly, then they are removed from the village and stored in a db with the id of the 2 players, the attack and defense power and the time of arrival.
Then i want to make a script that checks, if there's a battle, for the time of arrival = current time..
Then i will calculate both attack and defense powers and make the result of the battle..
It can be anything else besides runcron but i dont know any other way so im asking you guys
Thanks
Re: Runcron for PvP what interval?
Ok so based on that cronjobs only run at unix and linux servers, you would have to make a command for that server to create a cronjob.
As your game is just like tribalwars (I miss that game!) you don't have to make an interval to run every second or min, that'll waste resources. Better just to make a cronjob especifically for that 'attack', and then delete it.
some of the basics:
well I think that's the way to go, I admit i'm no expert on cronjobs and don't know exactly how to do it but hope the info would be helpful.
As your game is just like tribalwars (I miss that game!) you don't have to make an interval to run every second or min, that'll waste resources. Better just to make a cronjob especifically for that 'attack', and then delete it.
some of the basics:
how to add a cron:Cron Job Command Basics
In the following example, the crontab command shown below will activate the cron tasks automatically on the hour:
0 * * * * wget -O - -q -t 1 http://www.instantphp.com/cron.php
the 0 * * * * part in the example above is the time when the cron job is going to happen. There is a diagram below to explain the general crontab syntax
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
* * * * * command to be executed
Thus, the cron command example above means "ping http://www.instantphp.com/cron.php at the zero minute on every hour of every day of every month of every day of the week."
source: http://www.instantphp.com/news/37-tips- ... n-job.htmlHow To Add A Cron Job
Cron jobs are scheduled by setting up a "crontab." A crontab is a text file that contains the commands to be run. This file can be created and edited either through the command line interface
well I think that's the way to go, I admit i'm no expert on cronjobs and don't know exactly how to do it but hope the info would be helpful.
Orgullo Catracho
- Foofighter
- Posts: 121
- Joined: Sun Mar 04, 2012 1:52 pm
Re: Runcron for PvP what interval?
i dont quite understand why u think u need a cronjob here..vitinho444 wrote:ok it goes like this:
Player chooses troops basicly, then they are removed from the village and stored in a db with the id of the 2 players, the attack and defense power and the time of arrival.
Then i want to make a script that checks, if there's a battle, for the time of arrival = current time..
Then i will calculate both attack and defense powers and make the result of the battle..
It can be anything else besides runcron but i dont know any other way so im asking you guys
Thanks
u got already the time of the arrival in the db.. i would suggest that u save instead a timestamp in the db(time()+traveltime) and then make a simple check if timestamp <= time() do the calcs for my battle..
- vitinho444
- Posts: 2825
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Runcron for PvP what interval?
Oh i see, just put
if(attack)
{
see time of arrival
if(currentime > eta)
calc attack
else
show time left
}
like that?
if(attack)
{
see time of arrival
if(currentime > eta)
calc attack
else
show time left
}
like that?
- Foofighter
- Posts: 121
- Joined: Sun Mar 04, 2012 1:52 pm
Re: Runcron for PvP what interval?
Code: Select all
<?php
if (isset($_POST['attack']))
{
$time=time() + TRAVELTIME;
mysql_query("UPDATE [u]table[/u] SET Attack_time = $time WHERE id ='".$_SESSION['uid']."'");
}
/*-------------------------------------------------------------*/
?>
<?php if (DBQUERY-Attack_time > 0)
{
?> Restbauzeit: <?php $rest=ATTACK-time - time(); if ($rest <0){$rest = 0;} echo"$rest"?> <?php //shows the time which is left
}
else
{ ?>
<form action="#" method="post">
<input type="submit" value="attack" name="bau" >
</form>
<?php } ?>
<?php
//button for attack dunno if u need
?>
regards
- vitinho444
- Posts: 2825
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Runcron for PvP what interval?
I got the "button" as long the system working very fine, i was just asking if it can be done as i said, just check for attack if you visit the page..