KDawg08 Posted April 5, 2008 Share Posted April 5, 2008 What would be the easiest way to set a level limit... FOR EXAMPLE... if($ir['crystals']>24) { $ha="[url='tradement.php?spend=health']Buy[/url]"; } else if($ir['level']>75 AND $ir['level']<125) { $ba="N/A"; } else if($ir['level']>125) { $ba="Lvl Req."; } how would i set this PROPERLY? OR to make it so i don't have to do a SEPERATE tradement.php set it so if userlvl is 74 or lower they pay 25 crystals, 75-124 50crystals, 125-199 100crystals, etc. (PREFERABLY LIKE THIS) Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 5, 2008 Author Share Posted April 5, 2008 Re: How would i set level requirements?? OK so i've come up with this so far... $req=($ir['crystals']>49 AND $ir['level']>49); $req1=($ir['crystals']>49 AND $ir['level']<99); $req2=($ir['level']>49); $req3=($ir['level']<99); if($req A[code]ND $req1) { $ba="[url='tradement.php?spend=brave']Buy[/url]"; } else if($req2 AND $req3) { $ba="N/A"; } else { $ba="Lvl Req."; } how do i make it completely disappear for users not within those limits?[/code] Quote Link to comment Share on other sites More sharing options...
Tonka Posted April 5, 2008 Share Posted April 5, 2008 Re: How would i set level requirements?? i just use ($ir['level'] > 49); Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 5, 2008 Author Share Posted April 5, 2008 Re: How would i set level requirements?? i just use ($ir['level'] > 49); won't work like that... I want one for 50 to 100 and one for 101 to 150 etc. look at the coding so far... <?php session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=money_formatter($ir['money']); $cm=money_formatter($ir['crystals'],''); $lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm,$cm); $h->menuarea(); $req=($ir['crystals']>49 AND $ir['level']>49); $req1=($ir['crystals']>49 AND $ir['level']<99); $req2=($ir['level']>49); $req3=($ir['level']<99); if($ir['hospital'] || $ir['jail']) { print "You would have to be joking. You cant get into here through hospital."; exit; } if(!$_GET['spend']) { if($ir['crystals']>14) { $ea="[url='tradement.php?spend=refill']Buy[/url]"; } else { $ea="N/A"; } if($req AND $req1) { $ba="[url='tradement.php?spend=brave']Buy[/url]"; } else if($req2 AND $req3) { $ba="N/A"; } else { $ba="Lvl Req."; } if($ir['crystals']>24) { $ha="[url='tradement.php?spend=health']Buy[/url]"; } else { $ha="N/A"; } if($ir['crystals']>9999999) { $dpa="[url='tradement.php?spend=dp']Buy[/url]"; } else { $dpa="N/A"; } print "The Tradement Yard. What Do You Want To Spend Your {$ir['crystals']} Crystals On? Well it's back up and no mods other than fixing the crystals needed in hand. <table width=100% border=1> <tr><th>Reward</th><th>Crystals Needed</th><th>Level Requirement</th><th>Buy</th></tr> <tr><td>Energy Refill</td><td>15</td><td><center>N/A</center></td><td>$ea</td></tr> <tr><td>Brave Refill</td><td>20 <td><center>Level Must Be Under 50</center></td></td><td>$ba</td></tr> <tr><td>Health Refill</td><td>25</td><td><center>N/A</center></td><td>$ha</td></tr> <tr><td>IQ</td><td>1 Crystal for 5 IQ</td><td><center>N/A</center></td><td>[url='tradement.php?spend=IQ']Buy[/url]</td></tr> <tr><td>Money</td><td>1 Crystal per \$1000</td><td><center>N/A</center></td><td>[url='tradement.php?spend=money']Buy[/url]</td></tr> </table>"; } else { if($_GET['spend'] == 'refill') { if($ir['crystals'] <15) { print "You don't have enough crystals!"; } else if($ir['energy'] == $ir['maxenergy']) { print "You already have full energy."; } else { mysql_query("UPDATE users SET energy=maxenergy,crystals=crystals-15 WHERE userid=$userid",$c) or die("Energy refill area is down, please retry in 5 minutes."); print "Your energy is now full and you have paid 15 crystals."; } } else if($_GET['spend'] == 'IQ') { $amm=$ir['crystals']*5; print "Type in the amount of crystals you want to swap for IQ. You can get [b]$amm[/b] IQ with all your [b]{$ir['crystals']}[/b] crystals One crystal = 5 IQ.<form action='tradement.php?spend=IQ2' method='post'><input type='text' name='crystals' value='{$ir['crystals']}' /> <input type='submit' value='Swap' /></form>"; } else if($_GET['spend'] == 'IQ2') { $_POST['crystals']=(int) $_POST['crystals']; if($_POST['crystals'] <= 0 || $_POST['crystals'] > $ir['crystals']) { print "Error, you either do not have enough crystals or did not fill out the form. [url='tradement.php?spend=IQ']Back[/url]"; } else { $iqgain=$_POST['crystals']*5; mysql_query("UPDATE users SET crystals=crystals-{$_POST['crystals']} WHERE userid=$userid",$c); mysql_query("UPDATE userstats SET IQ=IQ+$iqgain WHERE userid=$userid",$c); print "You have gained $iqgain IQ and have just spent {$_POST['crystals']} crystals."; } } else if($_GET['spend'] == 'money') { $acm=$ir['crystals']*1000; print "Type in the amount of crystals you want to trade for cash. You can get \$$acm Cash for {$ir['crystals']} Crystals. One crystal = \$1000.<form action='tradement.php?spend=money2' method='post'><input type='text' name='crystals' value='{$ir['crystals']}' /> <input type='submit' value='Swap' /></form>"; } else if($_GET['spend'] == 'money2') { $_POST['crystals']=(int) $_POST['crystals']; if($_POST['crystals'] <= 0 || $_POST['crystals'] > $ir['crystals']) { print "Error, you either do not have enough crystals or did not fill out the form. [url='tradement.php?spend=money']Back[/url]"; } else { $iqgain=$_POST['crystals']*1000; mysql_query("UPDATE users SET crystals=crystals-{$_POST['crystals']},money=money+$iqgain WHERE userid=$userid",$c); print "You have recieved \$$iqgain and have spent {$_POST['crystals']}."; } } else if($_GET['spend'] == 'brave') { if($ir['crystals'] <20) { print "You don't have enough crystals!"; } else if($ir['brave'] == $ir['maxbrave']) { print "You already have full brave."; } else { $nowcrys=$ir['crystals']-20; mysql_query("UPDATE users SET brave=maxbrave,crystals=crystals-20 WHERE userid=$userid",$c); print "You now have full brave and have spent 20 crystals. You now have $nowcrys Crystals."; } } else if($_GET['spend'] == 'health') { if($ir['crystals'] <25) { print "You don't have enough crystals!"; } else if($ir['health'] == $ir['maxhealth']) { print "You already have full health."; } else { $nowcs=$ir['crystals']-25; mysql_query("UPDATE users SET health=maxhealth,crystals=crystals-50 WHERE userid=$userid",$c); print "You now have full health and have spent 25 crystals. You now have $nowcs crystals."; } } else if($_GET['spend'] == 'dp') { if($ir['crystals'] < 10000000000) { print "You don't have enough crystals!"; } else { $noww=$ir['crystals']-10000000; if($noww = 0) { $noww="no"; } mysql_query("UPDATE users SET donatordays=donatordays+30,crystals=crystals-100000000 WHERE userid=$userid",$c); print "You have a DP (Pack One) and have spent 1000 crystals.You wont recieve any benefits with this donator-pack. You now have $noww crystals."; } } } $h->endpage(); ?> NOTICE that it will work for lvl 50-100 but i need one working for lower levels and one for 101-175 and one for 176and up... Any suggestions? ONE problem that i would have with it would be this part of the code towards the bottom... else if($_GET['spend'] == 'brave') { if($ir['crystals'] <20) { print "You don't have enough crystals!"; } else if($ir['brave'] == $ir['maxbrave']) { print "You already have full brave."; } else { $nowcrys=$ir['crystals']-20; mysql_query("UPDATE users SET brave=maxbrave,crystals=crystals-20 WHERE userid=$userid",$c); print "You now have full brave and have spent 20 crystals. You now have $nowcrys Crystals."; } Quote Link to comment Share on other sites More sharing options...
Analog Posted April 5, 2008 Share Posted April 5, 2008 Re: How would i set level requirements?? I'm trying to work something out here but confused on what you are wanting. if level x then cost is x if level between x and x then cost y etc..... is that what you are wanting? Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 5, 2008 Author Share Posted April 5, 2008 Re: How would i set level requirements?? Here lemme try to explain easier.. For levels 49 and under, i want it to cost 20crystals for brave refill For levels 50 to 99, i want it to cost 50crystals for brave refill For levels 100 to 174, i want it to cost 100crystals for brave refill For levels 175 and up, i want it to cost 200crystals for brave refill Quote Link to comment Share on other sites More sharing options...
Analog Posted April 5, 2008 Share Posted April 5, 2008 Re: How would i set level requirements?? This starts by sitting $cost at 20, then proceeds to check if level falls into any of them. If it does, then $cost is changed to meet the desired results $cost = 20; if($ir['level'] >= 50 && $ir['level'] <= 99) { $cost = 50; } if($ir['level'] >= 100 && $ir['level'] <= 174) { $cost = 100; } if($ir['level'] >= 175) { $cost = 200; } Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 5, 2008 Author Share Posted April 5, 2008 Re: How would i set level requirements?? I know this is a definate noob question. How would i set that up into the script? Quote Link to comment Share on other sites More sharing options...
Analog Posted April 6, 2008 Share Posted April 6, 2008 Re: How would i set level requirements?? 1. Find where the brave refill is performed at else if($_GET['spend'] == 'brave') 2. Add the code that will set the price else if($_GET['spend'] == 'brave') { $cost = 20; if($ir['level'] >= 50 && $ir['level'] <= 99) { $cost = 50; } if($ir['level'] >= 100 && $ir['level'] <= 174) { $cost = 100; } if($ir['level'] >= 175) { $cost = 200; } 3. Update check that determines if user has enough crystals if($ir['crystals'] < $cost) 4. Update total price $nowcrys = $ir['crystals']-$cost; 5. Update query that sets the users crystals after they refill brave mysql_query("UPDATE users SET brave=maxbrave,crystals=crystals-$cost WHERE userid=$userid",$c); Thats all Folks! Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 6, 2008 Author Share Posted April 6, 2008 Re: How would i set level requirements?? That causes an error on this line: LINE 135 - else if($_GET['spend'] == 'health') Error is... Parse error: syntax error, unexpected T_ELSE in /home/teamms/public_html/tradement.php on line 135 Quote Link to comment Share on other sites More sharing options...
Analog Posted April 6, 2008 Share Posted April 6, 2008 Re: How would i set level requirements?? post a couple lines previous to that one Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 6, 2008 Author Share Posted April 6, 2008 Re: How would i set level requirements?? sry my bad, i forgot to add an extra } Quote Link to comment Share on other sites More sharing options...
Analog Posted April 6, 2008 Share Posted April 6, 2008 Re: How would i set level requirements?? thats what I was thinking Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted April 6, 2008 Share Posted April 6, 2008 Re: How would i set level requirements?? Here lemme try to explain easier.. For levels 49 and under, i want it to cost 20crystals for brave refill For levels 50 to 99, i want it to cost 50crystals for brave refill For levels 100 to 174, i want it to cost 100crystals for brave refill For levels 175 and up, i want it to cost 200crystals for brave refill PHP 101 - How complex is this ... if ($ir['level'] < 50) { $cost = 20; } else if ($ir['level'] < 100) { $cost = 50; } else if ($ir['level'] < 175) { $cost = 100; } else { $cost = 200; } Learn the language first before trying to run a game Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 7, 2008 Author Share Posted April 7, 2008 Re: How would i set level requirements?? Some people are such critics... It was posted at like 4pm my time. in which is the time i'm usually sleeping because of my work hours... What do you expect from someone working 18hours a day then working on scripting? Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted April 7, 2008 Share Posted April 7, 2008 Re: How would i set level requirements?? I'm assuming that wasn't directed at me ... after all I generally work around 18 hours per day actually writing this stuff, so I can see where others make mistakes. The original statement was poorly formatted - I had to waste time copying it into an editor, tidying the code fragment up and trying to decipher what you wanted to do. Later posters equally did not it make it plain, used poorly indented code fragments and IMHO did not accurately answer the question. The code I presented is clean, easy to read and understandable by other people who may be using the forums to learn a few basics. Our aim here is to try and bring people's skills up a notch or too, or at least give them a nudge in right direction. Yes, I can be ... short ... at times, my apologies for that. This is the type of question that is really fundamental to the language itself. There are several ways of doing it, but few if any are restricted to one game "engine" or another. References: http://www.php.net/manual/en/control-structures.if.php Quote Link to comment Share on other sites More sharing options...
KDawg08 Posted April 7, 2008 Author Share Posted April 7, 2008 Re: How would i set level requirements?? Wasn't trying to sound harsh if I did. My apologies if it came out that way. I was more or less looking at it and see it posted in MANY script requests/mods that "You shouldn't try to code a game unless you know the code" But for people such as myself, I learn HANDS ON ONLY! I can't sit and read all day to learn or i will forget 95% of what I learned. 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.