zelig Posted May 1, 2012 Share Posted May 1, 2012 Okay, I have a healing spell that allows people to regain stats when it's cast. But, how do I limit it so that they can't go over their maxhp? Here's what I have so far: $db->execute("UPDATE `users` SET `hp`=?, `mp`=?, `energy`=? WHERE `id`=?", array($player->hp + $healspell, $player->mp - $spell['mp'], $player->energy - $spell['energy'], $player->id)); What do I need to do in this to tell it to limit it to the maxhp but never going over it? $healspell is a random number, so it is quite possible to go over the maxhp at the moment. Thank you! Link to comment https://forums.phpfreaks.com/topic/261875-not-going-past-a-maximum-amount/ Share on other sites More sharing options...
marcus Posted May 1, 2012 Share Posted May 1, 2012 array(min($player->hp + $healspell, $whatEverYourMaxHPValueIs), 'etc....') Link to comment https://forums.phpfreaks.com/topic/261875-not-going-past-a-maximum-amount/#findComment-1341828 Share on other sites More sharing options...
zelig Posted May 1, 2012 Author Share Posted May 1, 2012 Fantastic! Thank you! Link to comment https://forums.phpfreaks.com/topic/261875-not-going-past-a-maximum-amount/#findComment-1341832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.