katarra Posted April 15, 2010 Share Posted April 15, 2010 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'])); } } } Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 15, 2010 Share Posted April 15, 2010 Your quotes appear to be pretty messed up, you might want to have a look: "update `users` set `hp` = IF((hp + (maxhp + 3))<maxhp, (hp + (maxhp + 3)), maxhp)" where array($row['id])) Quote Link to comment Share on other sites More sharing options...
katarra Posted April 15, 2010 Author Share Posted April 15, 2010 Well, that fixed it, except now, instead of going up gradually (that +3 bit), it just goes straight to max levels. Any thoughts? Thanks for the fix for the earlier thing though! Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 $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.. ) Quote Link to comment Share on other sites More sharing options...
katarra Posted April 15, 2010 Author Share Posted April 15, 2010 Fixed. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.