gideon prewett Posted October 5, 2009 Posted October 5, 2009 ive made a point system for my game and ive added it so u get points for reaching cirtan lvls this is a bit of the code im useing if($ir['level'] == 5) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 5, for doing so you have recieved one Point!",$c); } i reach lvl 5 and i get the point but i also gain a point for every link i click on or refresh i make after that any ideas? ?( Quote
Danny696 Posted October 5, 2009 Posted October 5, 2009 Global_Func.php -> Function Check_Level -> After query post it, that will give them a point everytime they re-load there page, mabey add another row, and when they get a point, it goes up. Quote
Curt Posted October 5, 2009 Posted October 5, 2009 do you want it to give a certain amount of points each time you grow a level ? then do as danny696 says...but if you want it to give points every 5 levels, and so on you could add a row in your query saying sumthin like points_recieved or wte..and add a 1 to it and and add if points_recieved is one then no points...then make it if level is 10 add points and add 1 to points_recieved...and so on.. i think something like that would work.... im still learning c ya Quote
gideon prewett Posted October 5, 2009 Author Posted October 5, 2009 this is from my global func 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); if($ir['level'] == 5) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 5, for doing so you have recieved one Point!",$c); } if($ir['level'] == 10) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 10, for doing so you have recieved one Point!",$c); } if($ir['level'] == 15) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 15, for doing so you have recieved one Point!",$c); } if($ir['level'] == 20) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 20, for doing so you have recieved one Point!",$c); } if($ir['level'] == 30) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 30, for doing so you have recieved one Point!",$c); } if($ir['level'] == 40) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 40, for doing so you have recieved one Point!",$c); } if($ir['level'] == 50) { $db->query("UPDATE users SET points=points+2 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 50, for doing so you have recieved Two Points!",$c); } if($ir['level'] == 60) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 60, for doing so you have recieved one Point!",$c); } if($ir['level'] == 70) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 70, for doing so you have recieved one Point!",$c); } if($ir['level'] == 80) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 80, for doing so you have recieved one Point!",$c); } if($ir['level'] == 90) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 90, for doing so you have recieved one Point!",$c); } if($ir['level'] == 100) { $db->query("UPDATE users SET points=points+2 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 100, for doing so you have recieved Two Points!",$c); } if($ir['level'] == 110) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 110, for doing so you have recieved one Point!",$c); } if($ir['level'] == 120) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 120, for doing so you have recieved one Point!",$c); } if($ir['level'] == 130) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 130, for doing so you have recieved one Point!",$c); } if($ir['level'] == 140) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 140, for doing so you have recieved one Point!",$c); } if($ir['level'] == 150) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 150, for doing so you have recieved one Point!",$c); } if($ir['level'] == 160) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 160, for doing so you have recieved one Point!",$c); } if($ir['level'] == 170) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 170, for doing so you have recieved one Point!",$c); } if($ir['level'] == 180) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 180, for doing so you have recieved one Point!",$c); } if($ir['level'] == 190) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 190, for doing so you have recieved one Point!",$c); } if($ir['level'] == 200) { $db->query("UPDATE users SET points=points+2 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 200, for doing so you have recieved Two Points!",$c); } } im new to this and have been away for a month so im trying to get back in to it and atm im confused ?( Quote
Danny696 Posted October 5, 2009 Posted October 5, 2009 Use an array, $array = array('5', '10', '15,'); etc... Quote
Curt Posted October 5, 2009 Posted October 5, 2009 thats looks good your problem is that as long as your are the level you specifed you will keep recieving the points until you grow another level....you need to specify it so you only gain the point/s once... if($ir['level'] == 5) { if($ir['yourvairable'] == 0) { $db->query("UPDATE users SET points=points+1 yourvairable+yourvairable+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 5, for doing so you have recieved one Point!",$c); } } //next level code if($ir['level'] == 10) { if($ir['yourvairable'] == 1) { $db->query("UPDATE users SET points=points+1 yourvairable+yourvairable+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 10, for doing so you have recieved one Point!",$c); } } I think something like that would work...NOT TESTED AT ALL :P Quote
seanybob Posted October 5, 2009 Posted October 5, 2009 RE: this is from my global func 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); if($ir['class'] == 1) { $db->query("UPDATE users SET level=level+1,exp=$expu,energy=energy+1,brave=brave+2,maxenergy=maxenergy+1,maxbrave=maxbrave+2, hp=hp+100,maxhp=maxhp+100 WHERE userid=$userid",$c); $stats=$ir['strength']*0.02; $db->query("UPDATE userstats SET strength=strength+$stats WHERE userid=$userid",$c); $stats=$ir['agility']*0.01; $db->query("UPDATE userstats SET agility=agility-$stats WHERE userid=$userid",$c); } else if($ir['class'] == 2) { $db->query("UPDATE users SET level=level+1,exp=$expu,energy=energy+1,brave=brave+2,maxenergy=maxenergy+1,maxbrave=maxbrave+2, hp=hp+50,maxhp=maxhp+50 WHERE userid=$userid",$c); $stats=$ir['agility']*0.01; $db->query("UPDATE userstats SET agility=agility+$stats WHERE userid=$userid",$c); $stats=$ir['strength']*0.005; $db->query("UPDATE userstats SET strength=strength-$stats WHERE userid=$userid",$c); } else if($ir['class'] == 3) { $db->query("UPDATE users SET level=level+1,exp=$expu,energy=energy+1,brave=brave+2,maxenergy=maxenergy+1,maxbrave=maxbrave+2, hp=hp+100,maxhp=maxhp+100 WHERE userid=$userid",$c); $stats=$ir['guard']*0.02; $db->query("UPDATE userstats SET guard=guard+$stats WHERE userid=$userid",$c); $stats=$ir['agility']*0.01; $db->query("UPDATE userstats SET agility=agility-$stats WHERE userid=$userid",$c); } else if($ir['class'] == 4) { $db->query("UPDATE users SET level=level+1,exp=$expu,energy=energy+1,brave=brave+2,maxenergy=maxenergy+1,maxbrave=maxbrave+2, hp=hp+50,maxhp=maxhp+50 WHERE userid=$userid",$c); } $db->query("UPDATE users SET level=level+0,exp=$expu,energy=energy+0,brave=brave+0,maxenergy=maxenergy+0,maxbrave=maxbrave+0, hp=hp+0,maxhp=maxhp+0 where userid=$userid"); } if($ir['level'] == 5) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 5, for doing so you have recieved one Point!",$c); } if($ir['level'] == 10) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 10, for doing so you have recieved one Point!",$c); } if($ir['level'] == 15) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 15, for doing so you have recieved one Point!",$c); } if($ir['level'] == 20) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 20, for doing so you have recieved one Point!",$c); } if($ir['level'] == 30) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 30, for doing so you have recieved one Point!",$c); } if($ir['level'] == 40) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 40, for doing so you have recieved one Point!",$c); } if($ir['level'] == 50) { $db->query("UPDATE users SET points=points+2 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 50, for doing so you have recieved Two Points!",$c); } if($ir['level'] == 60) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 60, for doing so you have recieved one Point!",$c); } if($ir['level'] == 70) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 70, for doing so you have recieved one Point!",$c); } if($ir['level'] == 80) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 80, for doing so you have recieved one Point!",$c); } if($ir['level'] == 90) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 90, for doing so you have recieved one Point!",$c); } if($ir['level'] == 100) { $db->query("UPDATE users SET points=points+2 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 100, for doing so you have recieved Two Points!",$c); } if($ir['level'] == 110) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 110, for doing so you have recieved one Point!",$c); } if($ir['level'] == 120) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 120, for doing so you have recieved one Point!",$c); } if($ir['level'] == 130) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 130, for doing so you have recieved one Point!",$c); } if($ir['level'] == 140) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 140, for doing so you have recieved one Point!",$c); } if($ir['level'] == 150) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 150, for doing so you have recieved one Point!",$c); } if($ir['level'] == 160) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 160, for doing so you have recieved one Point!",$c); } if($ir['level'] == 170) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 170, for doing so you have recieved one Point!",$c); } if($ir['level'] == 180) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 180, for doing so you have recieved one Point!",$c); } if($ir['level'] == 190) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 190, for doing so you have recieved one Point!",$c); } if($ir['level'] == 200) { $db->query("UPDATE users SET points=points+2 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 200, for doing so you have recieved Two Points!",$c); } } im new to this and have been away for a month so im trying to get back in to it and atm im confused ?( AHHH! Instead of using an if statement for every single possible outcome, consider using just one that will cover all the above. In a sense, this is the heart of computer science - using algorithms to make the computer do all the work for you (as opposed to typing it all in yourself). if($ir['level'] % 10 == 0 || $ir['level']==5 || $ir['level'] == 15) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level ".$ir['level'].", for doing so you have recieved One Point!",$c); } Quote
gideon prewett Posted October 5, 2009 Author Posted October 5, 2009 if($ir['level'] == 5) { if($ir['yourvairable'] == 0) { $db->query("UPDATE users SET points=points+1 yourvairable+yourvairable+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 5, for doing so you have recieved one Point!",$c); } } //next level code if($ir['level'] == 10) { if($ir['yourvairable'] == 1) { $db->query("UPDATE users SET points=points+1 yourvairable+yourvairable+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 10, for doing so you have recieved one Point!",$c); } } was if($ir['level'] == 5) { if($ir['yourvairable'] == 0) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); $db->query("UPDATE users SET yourvairable=yourvairable+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 5, for doing so you have recieved one Point!",$c); } } //next level code if($ir['level'] == 10) { if($ir['yourvairable'] == 1) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); $db->query("UPDATE users SET yourvairable=yourvairable+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting to level 10, for doing so you have recieved one Point!",$c); } } but it worked thx Quote
chicka Posted October 5, 2009 Posted October 5, 2009 seanybob has the right idea. I tested it to do something with my game and it works perfectly just the way it should Quote
gideon prewett Posted October 6, 2009 Author Posted October 6, 2009 more problems <?php include "globals.php"; if($ir['hospital']) { die("You cant bust while you are in the hospital > [url='index.php']Back[/url]"); $h->endpage(); exit; } if($ir['jail']) { die("You cant bust while you are in the jail > [url='index.php']Back[/url]"); $h->endpage(); exit; } if($ir['brave'] < 5) { die("Sorry, it costs 5 brave to bust someone. You only have {$ir['brave']} brave. Come back later."); } if($ir['jail']) { die("You cannot bust out people while in jail."); } $_GET['ID']=abs((int) $_GET['ID']); $r=$db->fetch_row($db->query("SELECT * FROM users WHERE userid={$_GET['ID']}")); if(!$r['userid']) { die("Invalid user"); } if(!$r['jail']) { die("That user is not in jail!"); } $mult=$r['level']*$r['level']; $chance=min(($ir['energy']/$mult)*50+1, 95); $test=$r['level']; if(rand(1,100) < $chance) { $gain=$r['level']*5; print "You successfully busted {$r['username']} out of jail. > [url='jail.php']Back[/url]"; $db->query("UPDATE users SET crimexp=crimexp+{$gain} WHERE userid=$userid"); $db->query("UPDATE users SET jail=0 WHERE userid={$r['userid']}"); $db->query("UPDATE users SET brave=brave-5 WHERE userid=$userid",$c); $db->query("UPDATE users SET exp=exp+2 WHERE userid=$userid",$c); $db->query("UPDATE users SET jailbusts=jailbusts+1 WHERE userid=$userid",$c); event_add($r['userid'], "[url='viewuser.php?u={$ir[']{$ir['username']}[/url] busted you out of jail.", $c); } if($ir['jailbusts'] == 0) { if($ir['yourbust'] == 1) { $db->query("UPDATE users SET points=points+1 WHERE userid=$userid",$c); $db->query("UPDATE users SET yourbusts=yourbusts+1 WHERE userid=$userid",$c); event_add($ir['userid'],"Congratulations on getting your first Bust! Once you get 100 you will receive a point! you will then on receive a point after every 100 busts!",$c); } print "While trying to bust out your friend, a guard spotted you and dragged you into jail yourself. Unlucky! > [url='jail.php']Back[/url]"; $time=min($test, 100); $db->query("UPDATE users SET jail=$time, jail_reason='Caught trying to bust out {$r['username']}' WHERE userid=$userid"); $db->query("UPDATE users SET brave=brave-5 WHERE userid=$userid",$c); event_add($r['userid'], "[url='viewuser.php?u={$ir[']{$ir['username']}[/url] was caught trying to bust you out of jail.", $c); } $h->endpage(); ?> ok now ive tryed to add it so u get points for busting when the bust succeeds u see the msg but dont when it fails Quote
Curt Posted October 6, 2009 Posted October 6, 2009 hmm...well this one is kinda confusing for me...the way it looks is that the message would come up during your first bust only...also your not telling it if you passed or failed....so it doesnt know to run the other code...thats my guess.. hope it helps Quote
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.