Runcron for PvP what interval?

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Runcron for PvP what interval?

Post by vitinho444 »

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?
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Foofighter
Posts: 121
Joined: Sun Mar 04, 2012 1:52 pm

Re: Runcron for PvP what interval?

Post by Foofighter »

why do you need to refresh the page so often?
pls describe how your pvp system works?
what time of the battle?
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: Runcron for PvP what interval?

Post by vitinho444 »

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 :D

Thanks
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: Runcron for PvP what interval?

Post by Ark »

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:
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."
how to add a cron:
How 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
source: http://www.instantphp.com/news/37-tips- ... n-job.html

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
User avatar
Foofighter
Posts: 121
Joined: Sun Mar 04, 2012 1:52 pm

Re: Runcron for PvP what interval?

Post by Foofighter »

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 :D

Thanks
i dont quite understand why u think u need a cronjob here..
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..
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: Runcron for PvP what interval?

Post by vitinho444 »

Oh i see, just put

if(attack)
{
see time of arrival

if(currentime > eta)
calc attack

else
show time left

}

like that?
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Foofighter
Posts: 121
Joined: Sun Mar 04, 2012 1:52 pm

Re: Runcron for PvP what interval?

Post by Foofighter »

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
?>
just copied it out of my code.. hope it helps - i edited a few things for your purpose but not all

regards
User avatar
vitinho444
Posts: 2825
Joined: Mon Mar 21, 2011 4:54 pm

Re: Runcron for PvP what interval?

Post by vitinho444 »

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..
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Post Reply

Return to “Advanced Help and Support”