spazz Posted August 21, 2008 Share Posted August 21, 2008 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! Quote Link to comment Share on other sites More sharing options...
Floydian Posted August 21, 2008 Share Posted August 21, 2008 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! Quote Link to comment Share on other sites More sharing options...
spazz Posted August 21, 2008 Author Share Posted August 21, 2008 Re: EXP% Cap That didn't work. I am looking for it to give a player a maximum of 20% exp when they choose Leave Them Quote Link to comment Share on other sites More sharing options...
Floydian Posted August 21, 2008 Share Posted August 21, 2008 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. ;) Quote Link to comment Share on other sites More sharing options...
spazz Posted August 22, 2008 Author Share Posted August 22, 2008 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 Quote Link to comment Share on other sites More sharing options...
Floydian Posted August 22, 2008 Share Posted August 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted August 23, 2008 Share Posted August 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 2, 2008 Share Posted September 2, 2008 Re: EXP% Cap why not just use a rand rand(0,20); I mite be wrong here but woud be best idea for you. Quote Link to comment Share on other sites More sharing options...
spazz Posted September 3, 2008 Author Share Posted September 3, 2008 Re: EXP% Cap Floydians way works the way I like it too. BTW Thank you I don't want random amounts given.... I still want it calculated based on level except that if if it calculates that you will get more than 20%....you only get 20% Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted September 9, 2008 Share Posted September 9, 2008 Re: EXP% Cap my way works also mate give it a go if ya like Quote Link to comment Share on other sites More sharing options...
ADN Posted September 11, 2008 Share Posted September 11, 2008 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); Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 11, 2008 Share Posted September 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
ADN Posted September 11, 2008 Share Posted September 11, 2008 Re: EXP% Cap And now the question is : who is gonna help me to create those arrays? :-o Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted September 12, 2008 Share Posted September 12, 2008 Re: EXP% Cap wow kyle that's pretty numbers lol what arrays? Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 12, 2008 Share Posted September 12, 2008 Re: EXP% Cap Well zero-affect, its pretty easy... if they are level blah below run that $qe or what ever. Quote Link to comment Share on other sites More sharing options...
ADN Posted September 13, 2008 Share Posted September 13, 2008 Re: EXP% Cap Zero-Affect, if statement's for this exp code :| Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted September 15, 2008 Share Posted September 15, 2008 Re: EXP% Cap ah sorry i was lost for a second there Quote Link to comment Share on other sites More sharing options...
ADN Posted September 16, 2008 Share Posted September 16, 2008 Re: EXP% Cap I'm lost from 1 week here .... lol Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted September 21, 2008 Share Posted September 21, 2008 Re: EXP% Cap mine works perfectly fine Quote Link to comment Share on other sites More sharing options...
ADN Posted September 22, 2008 Share Posted September 22, 2008 Re: EXP% Cap And in attackwon.php & attacktake.php, what is your exp formula ? 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.