in my application I get var $curxp , which contains an int, now I want to create a function that automatically returns $xplvlup (which contains an int, how much XP is needed for the next level and a function that returns the current level.
Now I can just specify hardcode with switch statements and calculated numbers, for example:
switch($curxp){ case <10: $xplvlup = 10; break; }
But it would be much better if I could use the algorithm, so that there is no maximum level. I know that I need to work with exhibitors to get a good curve, but I just don’t know how to get started.
UPDATE
Thanks to Oltarus, I came to the following solution:
$curxp = 20; function level($lvl){ return $xp = pow($lvl,2) + 5 * $lvl; } $lvl = 0; while (level($lvl) < $curxp) $lvl++; $totxp = level($lvl); $xplvlup = level($lvl) - $curxp; echo 'Level: '.$lvl."<br />"; echo 'Total XP: '.$totxp."<br />"; echo 'XP needed for Levelup: '.$xplvlup;
source share