Jump to content
MakeWebGames

EXP Bug After attacking a leaving a user for EXP


SaMz
 Share

Recommended Posts

Right, im having a problem with high level users gaining negative Exp when they attack a user. I cant find a way to resolve this. Really messes up the users account and gives unlimited levels and have to reset their exp and level back to mormal.

My Attacktake.php exp line:

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

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

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

print "and gained $expperc% EXP!<br />

Any help will be appriciated. If someone come out with a fix i will send them $15 through paypal.

Link to comment
Share on other sites

Thanks! I will test that out and see if the problem still persists. I have another major problem that once a user reaches over level 1620 they get negative exp and gain levels everytime they refresh...I cant seem to find out why this happens.

Link to comment
Share on other sites

Easy solution is to refresh the page that is doing it, make sure what that page is, then look over your coding, at calculations and queries, or post the page on here for someone to look at for you, if you are lost. If it's not in that page it could very well be the check_level function in global_func.php that is causing it...

Link to comment
Share on other sites

Easy solution is to refresh the page that is doing it, make sure what that page is, then look over your coding, at calculations and queries, or post the page on here for someone to look at for you, if you are lost. If it's not in that page it could very well be the check_level function in global_func.php that is causing it...

I cannot find the problem, Once you reach the level 1624-5 it starts giving negative exp and automatically levels up.

exp line in header.php

$experc=(int) ($ir['exp']/$ir['exp_needed']*100);

check_level global func.php

function check_level()

{

global $db;

global $ir,$c,$userid;

$ir['exp_needed']=(int) (($ir['level']+2)*($ir['level']+2)*($ir['level']+2)*0.5);

if($ir['exp'] >= $ir['exp_needed'])

{

$expu=$ir['exp']-$ir['exp_needed'];

$ir['level']+=1;

$ir['exp']=$expu;

$ir['brave']+=2;

$ir['maxbrave']+=2;

$ir['hp']+=50;

$ir['maxhp']+=50;

$ir['exp_needed']=(int) (($ir['level']+2)*($ir['level']+2)*($ir['level']+2)*0.5);

$db->query("UPDATE users SET level=level+1,exp=$expu,brave=brave+2,maxbrave=maxbrave+2,

hp=hp+50,maxhp=maxhp+50,mlevel=mlevel+1 where userid=$userid");

}

}

Link to comment
Share on other sites

I looked at what you have posted it has nothing to do with any of it post your attacktake.php, you must have a query incorrect causing it to go negative or, you have a statement that is less than or greater than a certain level or it could be your fields in your database set incorrectly..

Edited by lucky3809
Link to comment
Share on other sites

I looked at what you have posted it has nothing to do with any of it post your attacktake.php, you must have a query incorrect causing it to go negative or, you have a statement that is less than or greater than a certain level or it could be your fields in your database set incorrectly..

It has nothing to do with attack take anymore. It just happens.

Link to comment
Share on other sites

Hi samz,

This happens because the EXP needed to advance past level 1624 is a number greater than 2147483647.

So on this line:

$ir['exp_needed']=(int) (($ir['level']+2)*($ir['level']+2)*($ir['level']+2)*0.5);

When the (int) typecast occurs, it tries to change a number bigger than 2147483647 into an integer, which can only be 2147483647 at most on most servers. So it wraps back around to a negative number, causing your problem.

Possible solutions:

* Don't use ints for storing/calculating EXP - floats can hold bigger numbers

* Reduce EXP requirements per level by adjusting the numbers in the formula

* Put on a level cap, since levels 1600+ are pretty ridiculous to start with.

Link to comment
Share on other sites

Hi samz,

This happens because the EXP needed to advance past level 1624 is a number greater than 2147483647.

So on this line:

$ir['exp_needed']=(int) (($ir['level']+2)*($ir['level']+2)*($ir['level']+2)*0.5);

When the (int) typecast occurs, it tries to change a number bigger than 2147483647 into an integer, which can only be 2147483647 at most on most servers. So it wraps back around to a negative number, causing your problem.

Possible solutions:

* Don't use ints for storing/calculating EXP - floats can hold bigger numbers

* Reduce EXP requirements per level by adjusting the numbers in the formula

* Put on a level cap, since levels 1600+ are pretty ridiculous to start with.

Thanks, thats what i thaught... Can someone help me with how to implement a level cap?

Link to comment
Share on other sites

Hi samz,

This happens because the EXP needed to advance past level 1624 is a number greater than 2147483647.

So on this line:

$ir['exp_needed']=(int) (($ir['level']+2)*($ir['level']+2)*($ir['level']+2)*0.5);

When the (int) typecast occurs, it tries to change a number bigger than 2147483647 into an integer, which can only be 2147483647 at most on most servers. So it wraps back around to a negative number, causing your problem.

Possible solutions:

* Don't use ints for storing/calculating EXP - floats can hold bigger numbers

* Reduce EXP requirements per level by adjusting the numbers in the formula

* Put on a level cap, since levels 1600+ are pretty ridiculous to start with.

 

Hahaha really Dabs?

64bit os its been around for a long time now? you not heard of it??

Alternatively you could simply change this and use a exp table where you set your own rate of what exp the player is required to obtain before they level up.

As for the level 1600+ being ridiculous....well players like something to do. Gaining levels gives them something to do. So if i set a incentive on a game to be the first player to, for example, get to level 2000 and then players spend rl $ to be able to achieve it then thats game play and good business management.

Believe me it works....seen it. Have done it. Its a good part of any game.

Link to comment
Share on other sites

Alternatively you could simply change this and use a exp table where you set your own rate of what exp the player is required to obtain before they level up.

How would you do something like that? Could you not do that with a function as well? If level=1 and exp =75 then level =2 etc. That kind of thing.

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.

 Share

×
×
  • Create New...