cheekybuttsweet Posted March 8, 2009 Share Posted March 8, 2009 I need to change a code in a game i am trying to help with. When you attack someone it gives a random amount of EXp (used to level up) I want to insert set amount of EXP using a table i made which is so much exp per what level the attacker and attackee is.. Not a random number.. The code now is: $qe=$r['level']*$r['level']*$r['level']; $expgain=rand($qe/2,$qe); $expperc=(int) ($expgain/$ir['exp_needed']*100); But i have a table i made up in excel which i think is more fair.. Is there a way to do what i want????? Quote Link to comment Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 Where exactly are you stuck? Quote Link to comment Share on other sites More sharing options...
cheekybuttsweet Posted March 8, 2009 Author Share Posted March 8, 2009 Well this only gives a random number of EXp to the winner of the attack. What i want to be able to do it set the amount of exp given for winning. That way i can set it so that if a level 10 beats a level 5 they get 0.05 exp but if the same level 10 player beats a level 30 player they will get 15exp.. Not those exact numbers but you know what i mean.. An exact amount given rather than a random?? I dont know how to code that in Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted March 8, 2009 Share Posted March 8, 2009 Well a simple equation would be $experience = $loserLevel / $winnerLevel which would give 2exp to the 5th level player who beats a 10th level player, or 0.5exp to the 10th level player who beats a 5th level player; or 3exp to the 10th level player who beats a 30th level player, or 0.33exp to the 30th level player who beats a 10th level player. Alternatively $experience = ($loserLevel * $loserLevel) / $winnerLevel which would give 20exp to the 5th level player who beats a 10th level player, or 2.5exp to the 10th level player who beats a 5th level player; or 90exp to the 10th level player who beats a 30th level player, or 3.33exp to the 30th level player who beats a 10th level player. But you'll really need to come up with an equation yourself. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted March 8, 2009 Share Posted March 8, 2009 If you've worked out a set of winner and loser levels and experience values in Excel, then can you use Excel to give you an appropriate equation to use; or give us a series of values, and we might be able to work out an appropriate equation for you Quote Link to comment Share on other sites More sharing options...
cheekybuttsweet Posted March 8, 2009 Author Share Posted March 8, 2009 ahhh I see it now Its like a formula Ok.. I will have to rethink my excel table now as there is no way i can make a formula for what i had. Thanks heaps guys I kinda understand it allot better now At least i can get rid of the random anyway..lol I would love to show you the excel sheet and see if you could understand it.. Not on my computer right now though and its on that. Will get back to you THANKS Quote Link to comment Share on other sites More sharing options...
cheekybuttsweet Posted March 8, 2009 Author Share Posted March 8, 2009 Well i added your equation because i thought i could live with that. But it didnt work for me :'( This is the code i have which gives a random EXP { print "Your Victorious over {$r['username']} "; $qe=$r['level']*$r['level']*$r['level']; $expgain=rand($qe/2,$qe); $expperc=(int) ($expgain/$ir['exp_needed']*100); print "and earned yourself $expperc% EXP!<br /> I changed it to this { print "Your Victorious over {$r['username']} "; $qe=$r['level']*$r['level']*$r['level']; $expgain=$experience = $loserLevel / $winnerLevel; $expperc=(int) ($expgain/$ir['exp_needed']*100); print "and earned yourself $expperc% EXP!<br /> But got a whole heap of errors :'( I know i really need to study this more as I am only new to it but it kinda needs fixing before I have the time to learn Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted March 8, 2009 Share Posted March 8, 2009 ahhh I see it now Its like a formula Ok.. I will have to rethink my excel table now as there is no way i can make a formula for what i had. You might be surprised An easy way is to create an Excel chart using the loser level / the winner level as your X-axis data, and the proposed experience as your Y-axis series, and see what kind of line you get. You can also vary the X-axis to use loser - winner instead. Depending on the type of line, you can use the "add trend lines" chart option to work out a best fit to that line. This can help give you a "best fit" equation to use, within a range of linear, logarithmic, exponential, power, or polynomials or various orders (2 to 6). The Excel LINEST() and LOGEST() functions can also provide a lot of information about the equation that suits the "best fit" line. Quote Link to comment Share on other sites More sharing options...
cheekybuttsweet Posted March 8, 2009 Author Share Posted March 8, 2009 aHH Mark You just used words i can not even pronounce no matter try and know what they mean, However.. If i batter my eyelids at you could you possibly take a look at what i want to have as my attack EXP gained and tell me if there is a possible forumla for it that i can use in the above code.. http://spreadsheets.google.com/pub?key=ptIcZAVOmMoXste4BeTeELw Really do appreciate your help..thanks so much Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted March 8, 2009 Share Posted March 8, 2009 If i batter my eyelids at youI can never resist. Your calculation is actually very straightforward. Try the following $testRange = 22; function calculateExperience($loserLevel,$winnerLevel) { $levelDifference = $winnerLevel - $loserLevel; if ($levelDifference < 0) { $experience = 0.1 - abs($levelDifference * 0.005); } elseif ($levelDifference > 0) { $experience = 1 + $levelDifference * 0.5; } else { $experience = 1; } return $experience; } echo '<table border="1">'; echo '<tr><td></td><td colspan="'.$testRange.'" align="center"><b>Loser Level</b></td></tr>'; echo '<tr><td align="center"><b>Winner Level</b></td>'; for ($i = 1; $i <= $testRange; $i++) { echo '<td align="center"><b>'.$i.'<b></td>'; } echo '</tr>'; for ($winner = 1; $winner <= $testRange; $winner++) { echo '<tr><td align="right"><b>'.$winner.'</b></td>'; for ($loser = 1; $loser <= $testRange; $loser++) { echo '<td align="right">'.calculateExperience($winner,$loser).'</td>'; } echo '</tr>'; } echo '</table>'; But watch out when the difference between the winner and loser exceeds 20 levels. You end up with no experience at all if the winner is 21 levels above the loser; and if the level difference is higher than 21 then the winner can actually lose experience for picking on easy targets. Quote Link to comment Share on other sites More sharing options...
cheekybuttsweet Posted March 8, 2009 Author Share Posted March 8, 2009 ;D :-* Your Totally Awesome I will enter it tomorrow and let you know how it goes 2am in Australia right now though so im off to bed Thankyou so very much :-* 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.