Jump to content
MakeWebGames

EXP% Cap


spazz

Recommended Posts

I have been trying to figure out how to limit the amount of experience you get from a successful attack to a maximum of 20%

I believe this is the code I need to midify. Any insight would be helpful

 

$qe=$r['level']*$r['level']*$r['level'];
$expgain=rand($qe/2,$qe);
$expperc=(int) ($expgain/$ir['exp_needed']*100);
print "and gained $expperc% EXP!
Link to comment
Share on other sites

Re: EXP% Cap

If you mean a cap exp gain at 20% of EXP NEEDED, then:

 

$qe=$r['level']*$r['level']*$r['level'];
$expgain=rand($qe/2,$qe);
$expperc=(int) ($expgain/$ir['exp_needed']*100);
$expperc = $expperc > $ir['exp_needed'] *0.2 ? $ir['exp_needed'] * 0.2 : $expperc; // this is the dealy
print "and gained $expperc% EXP!
Link to comment
Share on other sites

Re: EXP% Cap

 

$qe=$r['level']*$r['level']*$r['level'];
$expgain=rand($qe/2,$qe);
$expgain = $expgain > floor($ir['exp_needed'] * 0.2) ? floor($ir['exp_needed'] * 0.2) : $expgain; // that should do it
$expperc=(int) ($expgain/$ir['exp_needed']*100);
print "and gained $expperc% EXP!

 

Alrighty, try that out. If that doesn't work for you, can you be more specific as to what you want. As in, you want exp gain that is no greater than 20%, but 20% of what?

I think that will work though. ;)

Link to comment
Share on other sites

Re: EXP% Cap

I am referring to how much of a percentage your exp bar in the header goes up by, do not want it to exceed a 20% increase no matter how much someone should have gotten. I don't want players to beat someone and gain 1000's of exp and jump dozens of levels.

For instance I don't want this:

You beat ***** and gained 3776% EXP!

That happened after I placed the above code in the attacktake.php

Link to comment
Share on other sites

Re: EXP% Cap

It sounds to me like $ir['exp_needed'] isn't holding the correct value.

$expperc=(int) ($expgain/$ir['exp_needed']*100);

That line there takes $expgain and turns it into a % of exp needed.

 

$expgain = $expgain > floor($ir['exp_needed'] * 0.2) ? floor($ir['exp_needed'] * 0.2) : $expgain; // that should do it

 

Look at: floor($ir['exp_needed'] * 0.2)

Here I calculate what 20% of exp needed is

I then test of expgain is greater than that raw amount, if it is, set it to 20% of exp needed, if not, leave the orig value.

 

The math on that code will work. Unfortunately I cannot do anything more for you without actually testing out your script.

Link to comment
Share on other sites

Re: EXP% Cap

if its the problem when you get to like level 990 and they try going to 991 and then they go into the minus then

in global_func.php find:

function check_level()
{
global $db;
global $ir,$c,$userid;
$ir['exp_needed']=(int) (($ir['level']+1)*($ir['level']+1)*($ir['level']+1)*2.2);
if($ir['exp'] >= $ir['exp_needed'])
{
$expu=$ir['exp']-$ir['exp_needed'];
$ir['level']+=1;
$ir['exp']=$expu;
$ir['energy']+=2;
$ir['brave']+=2;
$ir['maxenergy']+=2;
$ir['maxbrave']+=2;
$ir['hp']+=50;
$ir['maxhp']+=50;
$ir['exp_needed']=(int) (($ir['level']+1)*($ir['level']+1)*($ir['level']+1)*2.2);
$db->query("UPDATE users SET level=level+1,exp=$expu,energy=energy+2,brave=brave+2,maxenergy=maxenergy+2,maxbrave=maxbrave+2,
hp=hp+50,maxhp=maxhp+50 where userid=$userid");
}
}

and replace with:

function check_level()
{
global $db;
global $ir,$c,$userid;
$ir['exp_needed']=(float) (($ir['level']+1)*($ir['level']+1)*($ir['level']+1)*2.2);
if($ir['exp'] >= $ir['exp_needed'])
{
$expu=$ir['exp']-$ir['exp_needed'];
$ir['level']+=1;
$ir['exp']=$expu;
$ir['energy']+=2;
$ir['brave']+=2;
$ir['maxenergy']+=2;
$ir['maxbrave']+=2;
$ir['hp']+=50;
$ir['maxhp']+=50;
$ir['exp_needed']=(float) (($ir['level']+1)*($ir['level']+1)*($ir['level']+1)*2.2);
$db->query("UPDATE users SET level=level+1,exp=$expu,energy=energy+2,brave=brave+2,maxenergy=maxenergy+2,maxbrave=maxbrave+2,
hp=hp+50,maxhp=maxhp+50 where userid=$userid");
}
}

 

Noelle helped me with this so i thought i'd share it with the masses incase anyone else has this problem

Link to comment
Share on other sites

  • 2 weeks later...

Re: EXP% Cap

Zero-Affect, i have the same problem. Or i take 8237 EXP from beating somebody, or 0. I change that code in global_func.php, but in still have the same problem. I think the issue is on this code. But i am not a php-guru :(

 

$qe=$r['level']*$r['level']*$r['level'];

$expgain=rand($qe/2,$qe);

$expperc=(int) ($expgain/$ir['exp_needed']*100);

Link to comment
Share on other sites

Re: EXP% Cap

 

$qe=$r['level']*$r['level']*$r['level'];
$expgain=rand($qe/2,$qe);
$expperc=(int) ($expgain/$ir['exp_needed']*100);

 

Ok let's say they are level 1...

$qe = 1*1*1 = 1;

$expgain = rand(0,1);

You either win there 0 or 1 but mainly it is going to be 0.

If you change $qe to:

$qe = $ir['level']*2*$ir['level'];

That will be:

$qe = 1 * 2 * 1 = 2;

You are guaranteed to get 1 exp, but that could effect if they are level 100 or example:

$qe = 100 * 2 * 100 = 20000;

I would suggest using a couple array's or if statement's.

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