Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/148452-as-a-newbie-i-could-use-your-helpplease/
Share on other sites

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

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.

 

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

;D 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  ;D

 

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

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  ;D

 

 

 

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

 

 

;D aHH Mark

You just used words i can not even pronounce no matter try and know what they mean,  :o

 

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  :-*

 

 

If i batter my eyelids at you

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.