Jump to content

Cron not working for some reason...


katarra

Recommended Posts

I've developed a cron that will allow someone to gain back some playing stats, but for some reason, it doesn't appear to be working.

 

$query = $db->execute("select * from `users` where `state`='rest'");
while($row = $query->fetchrow()){
    if($row['energy'] > $row['maxenergy'] && $row['hp'] > $row['maxhp'] && $row['mp'] > $row['maxmp'])
    {
         $query = $db->execute("update `users` set `energy`=?, `hp`=?, `mp`=?,`state`='getup' where `id`=?", array($row['maxenergy'], $row['maxhp'], $row['maxmp'], $row['id'])) or trigger_error(mysql_error());
         if($query){
         $query = $db->execute("select * from `users` where `state`='rest'");
         $row = $query->fetchrow();
             $msg = $row['chat']."<b>You have max HP, Energy and MP. Your state is- Getup</b><br>";
             $query = $db->execute("update `users` set `chat`=? where `id`=?", array($msg, $row['id'])) or trigger_error(mysql_error());
         }
    }
    else
    {
      //  $query = $db->execute("update `users` set `hp`=?, `mp`=?, `energy`=? where `id`=?",array($row['hp'] + 3, $row['mp'] + 3, $row['energy'] + 3, $row['id'])) or trigger_error(mysql_error());
$query = $db->execute("update `users` set `hp` = IF((hp + (maxhp + 3))<maxhp, (hp + (maxhp + 3)), maxhp)" where `id`=?",array($row['id]))  or trigger_error(mysql_error());
$query = $db->execute("update `users` set `mp` = IF((mp + (maxmp + 3))<maxmp, (mp + (maxmp + 3)), maxmp)" where `id`=?",array($row['id]))  or trigger_error(mysql_error());
$query = $db->execute("update `users` set `energy` = IF((energy + (maxenergy + 3))<maxenergy, (energy + (maxenergy + 3)), maxenergy) where `id`=?",array($row['id]))  or trigger_error(mysql_error());
        if($query){
         $query = $db->execute("select * from `users` where `state`='rest'");
         $row = $query->fetchrow();
             $msg = "".$row['chat']."<b><center>You have ".$row['hp']." / ".$row['maxhp']." HP, ".$row['energy']." / ".$row['maxenergy']." Energy, and ".$row['mp']." / ".$row['maxmp']." MP.</center></b><br>";
             $query = $db->execute("update `users` set `chat`=? where `id`=?", array($msg, $row['id']));
        }
    }
}

Link to comment
Share on other sites

$query = $db->execute("update `users` set `hp` = IF((hp + (maxhp + 3))<maxhp, (hp + (maxhp + 3)), maxhp)" where `id`=?",array($row['id']))  or trigger_error(mysql_error());

 

if hp + (maxhp + 3) is smaller than maxhp

Thats like.. hp + maxhp, that'll never be smaller than maxhp. There for, it'll always return false?

, (hp + (maxhp + 3)), maxhp

I'm not quite sure what you are trying to achieve. (I'm not sure what the comma respresents in the whole statement really.. )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

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.