LOUDMOUTH Posted August 22, 2009 Share Posted August 22, 2009 I have the following code to update a players attributes on a game. right now it updates Awake and Nerve and Energy + HP in Different amounts. I am trying to make it update all attributes 25% each time instead. Can anyone help me convert the below PHP to refill 25% each update instead of the current amounts I have? $result = mysql_query("SELECT * FROM `5150players`"); while($line = mysql_fetch_assoc($result)) { $updated_user = new User($line['id']); if ($updated_user->rmdays > 0) { $multiplier = 2; } else { $multiplier = 1; } $username = $updated_user->username; $newawake = $updated_user->awake + (5 * $num_updated) * $multiplier; $newawake = ($newawake > $updated_user->maxawake) ? $updated_user->maxawake : $newawake; $newhp = $updated_user->hp + (100 * $num_updated) * $multiplier; $newhp = ($newhp > $updated_user->maxhp) ? $updated_user->maxhp : $newhp; $newenergy = $updated_user->energy + (25 * $num_updated) * $multiplier; $newenergy = ($newenergy > $updated_user->maxenergy) ? $updated_user->maxenergy : $newenergy; $newnerve = $updated_user->nerve + (25 * $num_updated) * $multiplier; $newnerve = ($newnerve > $updated_user->maxnerve) ? $updated_user->maxnerve : $newnerve; $result2 = mysql_query("UPDATE `5150players` SET `awake` = '".$newawake."', `energy` = '".$newenergy."', `nerve` = '".$newnerve."', `hp` = '".$newhp."' WHERE `username` = '".$username."'"); } Quote Link to comment Share on other sites More sharing options...
AngelicS Posted August 23, 2009 Share Posted August 23, 2009 This is simple math =) Let's say I have the variable 10. I'd write it like this $num=10; Now I want to increase the value of that variable by 25%. All I need to do is multiply the variable with 1.25, which is +25%. The code would look like this: $num=10; $num*=1.25; echo $num; The output would be 12.5, because 0.25(25%) out of 10 is 2.5, and + the 1 (100%), it becomes 12.5. Hope this helped =) Best wishes //AngelicS 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.