1 (edited by dlngle12 2005-10-23 05:59)

Topic: Hi the can some1 please look at this??

I am trying to use the cashmod in punbb and instead of it being cash I want to make it XP and everytime you get to a certain amount of "XP" your points go up heres the script I thought would work...

$cash == $pun_user['cm_cash'];
$lvl == $pun_user['lvl'];
$XP == $pun_user['XP'];
if ($cash<"20"){
    $lvl=="1";
    $XP =="20"-$cash;
    }
    else if ($cash=="20"){
    $lvl==$lvl+1;
    $XP =="20"-$cash;
    }
    else if ($cash=="40"){
    $lvl==$lvl+1;
    $XP =="40"-$cash;
    }
    else if ($cash=="65"){
    $lvl==$lvl+1;
    $XP =="65"-$cash;
    }
    else if ($cash=="90"){
    $lvl==$lvl+1;
    $XP =="90"-$cash;
    }
    else if ($cash=="120"){
    $lvl==$lvl+1;
    $XP =="120"-$cash;
    }
    else if ($cash=="150"){
    $lvl==$lvl+1;
    $XP =="150"-$cash;
    }
    else if ($cash=="185"){
    $lvl==$lvl+1;
    $XP =="185"-$cash;
    }
    else if ($cash=="225"){
    $lvl==$lvl+1;
    $XP =="225"-$cash;
    }
    else if ($cash=="270"){
    $lvl==$lvl+1;
    $XP =="270"-$cash;
    }
    else if ($cash=="300"){
    $lvl==$lvl+1;
    $XP =="300"-$cash;
    }
    else if ($cash=="350"){
    $lvl==$lvl+1;
    $XP =="350"-$cash;
    }
    else if ($cash=="400"){
    $lvl==$lvl+1;
    $XP =="400"-$cash;
    }
    else if ($cash=="450"){
    $lvl==$lvl+1;
    $XP =="450"-$cash;
    }
    else if ($cash=="500"){
    $lvl==$lvl+1;
    $XP =="500"-$cash;
    }
    else if ($cash=="550"){
    $lvl==$lvl+1;
    $XP =="550"-$cash;
    }
    else if ($cash=="600"){
    $lvl==$lvl+1;
    $XP =="600"-$cash;
    }
    else if ($cash=="650"){
    $lvl==$lvl+1;
    $XP =="650"-$cash;
    }
    else if ($cash=="700"){
    $lvl==$lvl+1;
    $XP =="700"-$cash;
    }
    else if ($cash=="750"){
    $lvl==$lvl+1;
    $XP =="750"-$cash;
    }
    else if ($cash=="800"){
    $lvl==$lvl+1;
    $XP =="800"-$cash;
    }
    else if ($cash=="850"){
    $lvl==$lvl+1;
    $XP =="850"-$cash;
    }
    else if ($cash=="900"){
    $lvl==$lvl+1;
    $XP =="900"-$cash;
    }
    else if ($cash=="1000"){
    $lvl==$lvl+1;
    $XP =="1000"-$cash;
    }
if ($tid) {
                $db->query('UPDATE '.$low_prio.$db->prefix.'users SET xp&lvl WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
                redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect'].'<br />You have gained '.$cur_posting['cm_cpp'].'XP');
            } else if($fid) {
                $db->query('UPDATE '.$low_prio.$db->prefix.'users SET xp&lvl WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
                process_uploaded_images($new_pid);
                redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect'].'<br />You have gained '.$cur_posting['cm_cpt'].'XP');

            }

Any Ideas? hmm

Free games/arcade at dlngle.com

2 (edited by Tobi 2005-10-23 09:24)

Re: Hi the can some1 please look at this??

I don't know the cash mod but first of all remove most of the double "="
They are for comparison while the single ones are for assignments.

Like this:

cash = $pun_user['cm_cash'];
$lvl = $pun_user['lvl'];
$XP = $pun_user['XP'];
if ($cash<"20"){
    $lvl="1";
    $XP ="20"-$cash;
    }
    else if ($cash=="20"){
    $lvl=$lvl+1;
    $XP ="20"-$cash;
    }
    else if ($cash=="40"){
    $lvl=$lvl+1;
    $XP ="40"-$cash;
    }
    else if ($cash=="65"){
    $lvl=$lvl+1;
    $XP ="65"-$cash;
    }
    else if ($cash=="90"){
    $lvl=$lvl+1;
    $XP ="90"-$cash;
    }
    else if ($cash=="120"){
    $lvl=$lvl+1;
    $XP ="120"-$cash;
    }
    else if ($cash=="150"){
    $lvl=$lvl+1;
    $XP ="150"-$cash;
    }
    else if ($cash=="185"){
    $lvl=$lvl+1;
    $XP ="185"-$cash;
    }
    else if ($cash=="225"){
    $lvl=$lvl+1;
    $XP ="225"-$cash;
    }
    else if ($cash=="270"){
    $lvl=$lvl+1;
    $XP ="270"-$cash;
    }
    else if ($cash=="300"){
    $lvl=$lvl+1;
    $XP ="300"-$cash;
    }
    else if ($cash=="350"){
    $lvl=$lvl+1;
    $XP =="350"-$cash;
    }
    else if ($cash=="400"){
    $lvl=$lvl+1;
    $XP ="400"-$cash;
    }
    else if ($cash=="450"){
    $lvl=$lvl+1;
    $XP ="450"-$cash;
    }
    else if ($cash=="500"){
    $lvl=$lvl+1;
    $XP ="500"-$cash;
    }
    else if ($cash=="550"){
    $lvl=$lvl+1;
    $XP ="550"-$cash;
    }
    else if ($cash=="600"){
    $lvl=$lvl+1;
    $XP ="600"-$cash;
    }
    else if ($cash=="650"){
    $lvl=$lvl+1;
    $XP ="650"-$cash;
    }
    else if ($cash=="700"){
    $lvl=$lvl+1;
    $XP ="700"-$cash;
    }
    else if ($cash=="750"){
    $lvl=$lvl+1;
    $XP ="750"-$cash;
    }
    else if ($cash=="800"){
    $lvl=$lvl+1;
    $XP ="800"-$cash;
    }
    else if ($cash=="850"){
    $lvl=$lvl+1;
    $XP ="850"-$cash;
    }
    else if ($cash=="900"){
    $lvl=$lvl+1;
    $XP ="900"-$cash;
    }
    else if ($cash=="1000"){
    $lvl=$lvl+1;
    $XP ="1000"-$cash;
    }

Don't know if this is the only bug but it's the most obvious one  smile

But if you change your code to

cash = $pun_user['cm_cash'];
$lvl = $pun_user['lvl'];
$XP = $pun_user['XP'];

$levels = array(0,20,40,65,90,120,150,185,225,270,300,350,400,450,
  500,550,600,650,700,750,800,850,900,1000);

# Start level
$lvl = '1';
$XP = (20 - $cash);
foreach($levels as $level_count)  {
  if($cash >= $level_count) {
    $lvl++;
    }
  }
$XP = ($levels[($lvl - 1)] - $cash);

you not only save some dozens lines of code, it will also be much easier for you to change/add levels.

The German PunBB Site:
PunBB-forum.de

Re: Hi the can some1 please look at this??

Wow! thanks heaps I get the basic Idea of php but syntax is not my thing smile would you know how to add the xp remaining and lvl to the database or did I have that right?

Free games/arcade at dlngle.com

4

Re: Hi the can some1 please look at this??

Provided that the fields exist in the table you are calling (you'll have to take care of that yourself wink ) you have to use

if ($tid) {
                $db->query('UPDATE '.$low_prio.$db->prefix.'users SET xp='.intval($XP).', lvl='.intval($lvl).' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
                redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect'].'<br />You have gained '.$cur_posting['cm_cpp'].'XP');
            } else if($fid) {
                $db->query('UPDATE '.$low_prio.$db->prefix.'users SET xp='.intval($XP).', lvl='.intval($lvl).' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
                process_uploaded_images($new_pid);
                redirect('viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $lang_post['Post redirect'].'<br />You have gained '.$cur_posting['cm_cpt'].'XP');

            }
The German PunBB Site:
PunBB-forum.de

Re: Hi the can some1 please look at this??

Kool just wat I was looking for in an answer wink
works fine now

Free games/arcade at dlngle.com