Jump to content
MakeWebGames

Leveling Mod


newttster

Recommended Posts

I have 3 problems with the code below and I can't figure out why they aren't updating the way they should.

1. It isn't doing the level check from the trialstable.

2. It does not advance the $ir['level'] if the condition is true but it does add the exp gained.

3. When it adds the exp, it does not add the correct amount. It is not subtracting the needed from the actual.

 

function check_level()
{
global $db;
global $ir,$c,$userid;
$ir['exp_needed']=(int) ($ir['level']*75);
    if ($ir['exp'] >= $ir['exp_needed'])
   {
   $trialcheck=$db->query("SELECT `level` FROM `trialstable` WHERE `userid`='{$ir['userid']}'");
   $r=$db->fetch_row($trialcheck);
if (($r['level'])<($ir['level']+1))
{
echo'blah blah';
}
else
                   {
                   $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']*75);
                   $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`='{$ir['userid']}'");
                   }
    }
}
Link to comment
Share on other sites

function check_level()
{
global $db;
global $ir,$c,$userid;
$ir['exp_needed']= ($ir['level']*75);
if ($ir['exp'] >= $ir['exp_needed'])
{
/*
This table has the users id, level (the level that they were at the last time they completed a trial).
It is updated when a user completes the trial for that level. The remaining fields are the trials they have completed.
This table gets updated when they have completed a trial. I am selecting the last known level that was posted 
to the table. If the last level posted in trialstable is less than the next $ir['level'] then they cannot advance.
*/
$trialcheck=$db->query("SELECT `level` FROM `trialstable` WHERE `userid`='{$ir['userid']}'");
$r=$db->fetch_row($trialcheck);
if (($r['level'])<($ir['level']+1))
/*
I am echoing something here to let the user know that if they have not completed the trial for
this level, then they will not advance level, as well as certain funtions in the game 
being locked to them.
*/
{
echo'You have not completed the trial for this level.<br />
In order to advance to the next level you must do so.<br />
Please see the Help Tutorial for further information.<br /><br />
<a href="helptutorial.php">Help Tutorial</a><br />';
                    $h->endpage();
                    exit;
}
else
{
$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']*75);
$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`='{$ir['userid']}'");
}
}
}

 

The only output that I can see that is happening is that it is adding the exp gained to the db.

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