Jump to content

Help with Crons


seany123

Recommended Posts

the way im using this code is when someone goes to the home page it updates the databse using the cron...

 

that means that if just 1 person goes to home, it will only update his database but no1 elses...

 

im wanting it so if anyone goes on the home page then it will update everyones database.

the way im using this code is when someone goes to the home page it updates the databse using the cron...

 

that means that if just 1 person goes to home, it will only update his database but no1 elses...

 

im wanting it so if anyone goes on the home page then it will update everyones database.

 

What?  Cron does its thing automatically, so no one needs to visit any pages...

okay to make things easier...

on my home page i have a include(autocron.php);

 

This is my Autocron.php:

<?php

$query = $db->execute("select * from `cron`");

while($row = $query->fetchrow())
{
$cron[$row['name']] = $row['value'];
}

$now = time();

$diff = ($now - $cron['reset_last']);
if($diff >= $cron['reset_time'])
{
include("cron/reset.php");
$db->execute("update `cron` set `value`=? where `name`=?", array($now, "reset_last"));
}

$diff = ($now - $cron['revive_last']);
if($diff >= $cron['revive_time'])
{
include("cron/revive.php");
$db->execute("update `cron` set `value`=? where `name`=?", array($now, "revive_last"));
}

?>

 

This is my Revive.php

<?php
if(!defined('IN_GAME')) die('HACK');

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $energy = $row['energy'] + ($row['maxenergy'] * .20);
   $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy;
   $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $nerve = $row['nerve'] + ($row['maxnerve'] * .20);
   $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve;
   $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$query = "SELECT * FROM players";
$result = mysql_query($query) OR die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
   $hp = $row['hp'] + ($row['maxhp'] * .25);
   $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp;
   $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']);
   mysql_query($query) or die(mysql_error());
}

$awakeupdate = $player->awake + 5;
$query = $db->execute("update `players` set `awake`=? where `id`=? and `awake`<`maxawake`",
array($awakeupdate, $player->id));
?>

 

Okay so with the revive code (above) when someone goes to the homepage and it runs the autocron.php, which runs revive.php

 

Will it update EVERYONES databases or just that person?

 

if it only updates the 1 person, what code could be used to make it update everyones?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.