Jump to content
MakeWebGames

Weapon/Item Level Restriction


Miks

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by KyleMassacre
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 }

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
}
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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