Jump to content
MakeWebGames

Incorrect EXP gain displayed


Recommended Posts

Hello, I am a bit confused in what I did wrong in one of my scripts. So in the Gym I allow it to show how much EXP it gains. However, it shows a different amount from how much it actually gain.

Generate gains -

$gain +=rand(1,3) / rand(800,1000) * rand(800,1000) * (($row['will'] + 50) / 300);

    $row['exp_needed'] =
           (int) (($row['level'] + 1) * ($row['level'] + 1)
                   * ($row['level'] + 1) * 2.2);

       $expgain = $gain;         
       $expperc = ($expgain / $row['exp_needed'] * 100);

 

Update users EXP -

$db->query("UPDATE `users` SET `exp` = `exp` + ({$gain} / 10) WHERE `userid` = ". $_SESSION['userid'] ."");

 

I don't see where I went wrong.

Link to comment
Share on other sites

What would you like to update it as?

Here is some dummy code I ran in phpfiddle:

<?php 
$gain = 0; 
$row['will'] = 100; 
$row['level'] = 5; 
$gain +=rand(1,3) / rand(800,1000) * rand(800,1000) * (($row['will'] + 50) / 300); 
$row['exp_needed'] = (int) (($row['level'] + 1) * ($row['level'] + 1) * ($row['level'] + 1) * 2.2); 
$expgain = $gain; 
$expperc = ($expgain / $row['exp_needed'] * 100); 
echo "Gain: ".$gain."<br/>Gain / 10: ".($gain/10)."<br/>Exp %: ".$expperc; 
?>

And here is the response it gave:

Gain: 0.502012072435

Gain / 10: 0.0502012072435

Exp %: 0.105686752091

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