Miks Posted December 23, 2012 Share Posted December 23, 2012 Is there a way to to restrict items (primarily weapons) to a certain level. The problem is I dont want the lower down levels i.e newbs to be able to purchase the high powered weapons. Is there an easy way to add level restrictions to the item creation page? Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 23, 2012 Share Posted December 23, 2012 Sure there is, its similar to what is done for cities. I have something similar but instead of level i use player class. The only thing is that they are able to purchase the weapon it just does not allow them to use it Quote Link to comment Share on other sites More sharing options...
sniko Posted December 23, 2012 Share Posted December 23, 2012 New database column in `items` Edit the staff items to show another form entry for the minimal level Edit the queries in staff items Do a binary-like check in equip item IF ( [weapon_minimum_level] > [my_level] ) DISPLAY "Can't equip. Level up!" END IF Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 Ok I have tried to edit equip_weapon.php but I need some help as I'm not a coder. I get this error "Parse error: syntax error, unexpected T_ELSE " $plevel=($r['level']); if ($ir['wlevel'] > $plevel); { echo "Can't equip. Level up!"; } else ($ir[$_POST['type']] > 0); { item_add($userid, $ir[$_POST['type']], 1); } item_remove($userid, $r['itmid'], 1); $db->query( "UPDATE `users` SET `{$_POST['type']}` = {$r['itmid']} WHERE `userid` = {$userid}"); echo "Item {$r['itmname']} equipped successfully."; I have updated the item table and added a new field called wlevel. Just cant get this part to work. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 25, 2012 Share Posted December 25, 2012 (edited) Ok I have tried to edit equip_weapon.php but I need some help as I'm not a coder. I get this error "Parse error: syntax error, unexpected T_ELSE " $plevel=($r['level']); if ($ir['wlevel'] > $plevel); { echo "Can't equip. Level up!"; } else ($ir[$_POST['type']] > 0); { item_add($userid, $ir[$_POST['type']], 1); } item_remove($userid, $r['itmid'], 1); $db->query( "UPDATE `users` SET `{$_POST['type']}` = {$r['itmid']} WHERE `userid` = {$userid}"); echo "Item {$r['itmname']} equipped successfully."; I have updated the item table and added a new field called wlevel. Just cant get this part to work. Try something like this: if (isset($_POST['type'])) { if (!in_array($_POST['type'], array("equip_primary", "equip_secondary"), true)) { echo "This slot ID is not valid."; $h->endpage(); exit; } else if ($r['wlevel'] > $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } if ($ir[$_POST['type']] > 0) { item_add($userid, $ir[$_POST['type']], 1); } item_remove($userid, $r['itmid'], 1); cause i believe your statements went a little something like this: if else else else if works great in between an if and else statement Edited December 25, 2012 by KyleMassacre Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 Cheers KyleMassacre My error has now disappeared but the script ignores the level restriction command and equips the weapons. I have a weapon set to wlevel 8 and my level is 4 but instead of throwing back "You are not at a high enough level to equip this" it stills assigns the weapon. Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 This is the contents of the equip_weapon.php file <?php /** * MCCodes Version 2.0.5b * Copyright © 2005-2012 Dabomstew * All rights reserved. * * Redistribution of this code in any form is prohibited, except in * the specific cases set out in the MCCodes Customer License. * * This code license may be used to run one (1) game. * A game is defined as the set of users and other game database data, * so you are permitted to create alternative clients for your game. * * If you did not obtain this code from MCCodes.com, you are in all likelihood * using it illegally. Please contact MCCodes to discuss licensing options * in this case. * * File: equip_weapon.php * Signature: 5fa6ce6f751fd7f09cde14b86ba287bf * Date: Fri, 20 Apr 12 08:50:30 +0000 */ require_once('globals.php'); $_GET['ID'] = (isset($_GET['ID']) && is_numeric($_GET['ID'])) ? abs((int) $_GET['ID']) : 0; $id = $db->query( "SELECT `weapon`, `itmid`, `itmname` FROM `inventory` AS `iv` LEFT JOIN `items` AS `it` ON `iv`.`inv_itemid` = `it`.`itmid` WHERE `iv`.`inv_id` = {$_GET['ID']} AND `iv`.`inv_userid` = $userid LIMIT 1"); if ($db->num_rows($id) == 0) { $db->free_result($id); echo "Invalid item ID"; $h->endpage(); exit; } else { $r = $db->fetch_row($id); $db->free_result($id); } if (!$r['weapon']) { echo "This item cannot be equipped to this slot."; $h->endpage(); exit; } if (isset($_POST['type'])) { if (!in_array($_POST['type'], array("equip_primary", "equip_secondary"), true)) { echo "This slot ID is not valid."; $h->endpage(); exit; } elseif ($r['wlevel'] > $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } if ($ir[$_POST['type']] > 0) { item_add($userid, $ir[$_POST['type']], 1); } item_remove($userid, $r['itmid'], 1); $db->query( "UPDATE `users` SET `{$_POST['type']}` = {$r['itmid']} WHERE `userid` = {$userid}"); echo "Item {$r['itmname']} equipped successfully."; } else { echo "<h3>Equip Weapon</h3><hr /> <form action='equip_weapon.php?ID={$_GET['ID']}' method='post'> Please choose the slot to equip {$r['itmname']} to, if there is already a weapon in that slot, it will be removed back to your inventory.<br /> <input type='radio' name='type' value='equip_primary' checked='checked' /> Primary<br /> <input type='radio' name='type' value='equip_secondary' /> Secondary<br /> <input type='submit' value='Equip Weapon' /> </form>"; } $h->endpage(); Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 25, 2012 Share Posted December 25, 2012 change my else if to if and see if that works p.s. use [*code*] tags [/*code*] without the stars Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 Hi KyleMassacre, Thanks for the tip. I tried replace the else if with just if and it was producing the same results, its like its bypassing the level restriction...... Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 It works!! I had to replce else if ($r['wlevel'] > $ir['level']) with else if ($r['wlevel'] < $ir['level']) Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 Sorry I mean I had to replce if ($r['wlevel'] > $ir['level']) with if ($r['wlevel'] < $ir['level']) Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 Hopefully its the final post but I had to alter the above code and replace it with if ($r['wlevel'] >= $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } As far as I am aware it is working correctly now Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted December 25, 2012 Share Posted December 25, 2012 I will tell you what I would do for this... In items table create a new field called restrict and make it ENUM On,Off Then update your item staff page and add that options, so when making an item you can decide if you want that weapon to be restricted to new players or older... Then add something along the lines in check level part ... if($ir['level'] > 10){ UPDATE FIELD TO OFF IF IT IS ON } Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted December 25, 2012 Share Posted December 25, 2012 Hopefully its the final post but I had to alter the above code and replace it with if ($r['wlevel'] >= $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } As far as I am aware it is working correctly now That may work fine. Try equipping an item you can equip though just to be sure I will tell you what I would do for this... In items table create a new field called restrict and make it ENUM On,Off Then update your item staff page and add that options, so when making an item you can decide if you want that weapon to be restricted to new players or older... Then add something along the lines in check level part ... if($ir['level'] > 10){ UPDATE FIELD TO OFF IF IT IS ON } Sounds way to complicated haha Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 I can get the script to work like this which isnt correct. If you're higher than the weapon level you cant have the weapon, but when the weapon level is higher than your level it works. I know its a case of changing the bracket to ">" but weirdly it doesnt work like that but does work "<" if (isset($_POST['type'])) { if (!in_array($_POST['type'], array("equip_primary", "equip_secondary"), true)) { echo "This slot ID is not valid."; $h->endpage(); exit; } if ($r['wlevel'] > $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } if ($ir[$_POST['type']] > 0) { item_add($userid, $ir[$_POST['type']], 1); } item_remove($userid, $r['itmid'], 1); $db->query( "UPDATE `users` SET `{$_POST['type']}` = {$r['itmid']} WHERE `userid` = {$userid}"); echo "Item {$r['itmname']} equipped successfully."; The above is how it should be but doesnt work. if (isset($_POST['type'])) { if (!in_array($_POST['type'], array("equip_primary", "equip_secondary"), true)) { echo "This slot ID is not valid."; $h->endpage(); exit; } if ($r['wlevel'] < $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } if ($ir[$_POST['type']] > 0) { item_add($userid, $ir[$_POST['type']], 1); } item_remove($userid, $r['itmid'], 1); $db->query( "UPDATE `users` SET `{$_POST['type']}` = {$r['itmid']} WHERE `userid` = {$userid}"); echo "Item {$r['itmname']} equipped successfully."; But when the bracket is round the wrong way it does work but not how I want it. Hope that made sense, any further help is greatly appreciated!! Quote Link to comment Share on other sites More sharing options...
Someone Posted December 25, 2012 Share Posted December 25, 2012 Apparently $ir['level'] is for some reason never higher than $r['wlevel'] I suspect there is something wrong with one of the variables. echo 'if ('.$r['wlevel'].' < '.$ir['level'].')'; // should show clearly if there is anything wrong with the vars if ($r['wlevel'] < $ir['level']) { echo "You are not at a high enough level to equip this."; $h->endpage(); exit; } Quote Link to comment Share on other sites More sharing options...
Miks Posted December 25, 2012 Author Share Posted December 25, 2012 @1331 I added the line as you suggest i.e echo 'if ('.$r['wlevel'].' > '.$ir['level'].')'; if ($r['wlevel'] > $ir['level']) { echo "You are not at a high enough level to equip this.<br><a href='inventory.php'> Return to inventory</a>"; $h->endpage(); exit; } The result was if ( > 4)Item Chainsaw equipped successfully. Return to inventory The weapon level I am testing this on is 12 and my level is 4. Quote Link to comment Share on other sites More sharing options...
Someone Posted December 25, 2012 Share Posted December 25, 2012 (edited) As you can see from the output, the variable $r['wlevel'] is not set properly, its blank. And therefore always less than 4. There correct echoed result then be should be: if (12 > 4)Item Chainsaw equipped successfully. You need to backtrack to where $r['wlevel'] is suppose to be set, $r is usually a query result, search your code for $r = Most likely you will find a query of some sort. $db->query("SELECT * FROM ... WHERE") or mysql_query("SELECT * FROM ... WHERE"); Either add a or die(mysql_error()) to the query, or echo out whats between the " " then run that in phpmyadmin I have not touched mccodes in years, dont recall exactly how that system is built. EDIT: You can also do a print_r($r); To see if the data has been retrieved correctly from the database Edited December 25, 2012 by Someone 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.