Jump to content
MakeWebGames

Removing Cron Jobs.


bloodless2010

Recommended Posts

Hey guys.

I managed to remove 1minute cronjob for my game,

But I'm having problem with the 1day and 5minute ones now.

http://makewebgames.io/archive/index.php/t-32642.html

Is the thread I used;

I am currently using this:

(It only works if a person clicks every 5 minutes, so you could leave for 20 and click and it would only update once)

$result = mysql_query("SELECT * FROM `updates` WHERE `name` = '5min'");
$result = mysql_fetch_assoc($result);
$hla = time() - $result['last'];

if($hla > (300))
{
$n = floor($hla / 300);

$allusers_query =
       "UPDATE `users`
       SET `brave` = LEAST(`brave` + ((`maxbrave` / 10) + 0.5), `maxbrave`),
       `hp` = LEAST(`hp` + (`maxhp` / 3), `maxhp`),
       `will` = LEAST(`will` + 10, `maxwill`)";
mysql_query($allusers_query, $c);
//enerwill update
$en_nd_query =
       "UPDATE `users`
       SET `energy` = LEAST(`energy` + (`maxenergy` / 12.5), `maxenergy`)
       WHERE `donatordays` = 0";
$en_don_query =
       "UPDATE `users`
       SET `energy` = LEAST(`energy` + (`maxenergy` / 6), `maxenergy`)
       WHERE `donatordays` > 0";
mysql_query($en_nd_query, $c);
mysql_query($en_don_query, $c);

$time = time();
mysql_query("UPDATE `updates` SET `last` = ".$time." WHERE `name` = '5min'");
$floor = $time - (floor($time / 300) * 300);


if($floor > 0)
{
$newUpdate = time() - $floor;
mysql_query("UPDATE `updates` SET `last` = ".$newUpdate." WHERE `name` = '5min'");
}
}

I need it to update properly like, if I don't click for 20 minutes and do, it increases it 4 times, if you understand what I mean.

Thanks!

Link to comment
Share on other sites

Good, glad I can be of some service. I believe the way he has it set up is it wont work till there is a click but once some on clicks they get their updates that they shouldve been rewarded. Example:

No users online and 1 user in jail for 1 minutes, 3 hours later the user is still in jail but a user logs in and boom the jailed user is no out of jail. Hope that makes sense but me personally I run crons.

Link to comment
Share on other sites

Cron's are a lot more accurate and should be used for thing such as hour and day cron. It is best to remove the 5min & 1min cron tho on mccodes.

Also, bloodless, you are correct in your code. You just need to "Times by $n" like so:

 

$n = floor($hla / 300);

$allusers_query =
       "UPDATE `users`
       SET `brave` = LEAST(`brave` + (((`maxbrave` / 10) + 0.5) * ".$n."), `maxbrave`),
       `hp` = LEAST(`hp` + ((`maxhp` / 3) * ".$n."), `maxhp`),
       `will` = LEAST(`will` + (10 * ".$n."), `maxwill`)";
mysql_query($allusers_query, $c);
//enerwill update
$en_nd_query =
       "UPDATE `users`
       SET `energy` = LEAST(`energy` + ((`maxenergy` / 12.5) * ".$n."), `maxenergy`)
       WHERE `donatordays` = 0";
$en_don_query =
       "UPDATE `users`
       SET `energy` = LEAST(`energy` + ((`maxenergy` / 6) * ".$n."), `maxenergy`)
       WHERE `donatordays` > 0";

 

That way, it will update by * the value by N, which is divided on top. n usually is 1, but then if 10 minutes are past. it will be 2, so the value is times by 2. if that makes sense.

But realistically, we don't need 3 queries, and can combine that into one.

 

$n = floor($hla / 300);

$update_users = 'UPDATE `users` SET `';
$update_users.= ' `brave` = LEAST(`brave` + (((`maxbrave` / 10) + 0.5) * '.$n.'), `maxbrave`),';
$update_users.= ' `hp` = LEAST(`hp` + ((`maxhp` / 3) * '.$n.'), `maxhp`),';
$update_users.= ' `will` = LEAST(`will` + (10 * '.$n.'), `maxwill`),';
$update_users.= ' `energy` = IF(`donatordays`, LEAST(`energy` + ((`maxenergy` / 6) * '.$n.')), LEAST(`energy` + ((`maxenergy` / 12.5) * '.$n.')))';

mysql_query($update_users);
Edited by HauntedDawg
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...