Jump to content
MakeWebGames

Inventory > Item Type


Markku

Recommended Posts

Hii MakeWebGames, I'm just messing around with the Inventory file, And I've created 2 "item types" (Food/Drink)

I was wondering, What would be the best way to instead of show "(use)" for those 2 specific item types, For it to instead show "(Eat) (Drink)"

Thank you. ^_^

Edited by Markku
Link to comment
Share on other sites

What about using a switch case?

$use_string = '';
switch($type) {
case 'food':
	$use_string = 'Eat';
break;
case 'drink':
	$use_string = 'Drink';
break;
default:
	$$use_string = 'Use';
break;
}
echo $use_string;

 

You probably don't need to complicate it that much but yea, or you could use an array like this...

 

$item_uses = array( 'food' => 'Eat', 'drink' => 'Drink');
$use_string = in_array($i['itemtype'], $item_uses) ? $item_uses[$i['itemtype'] : 'Use';
Link to comment
Share on other sites

What about using a switch case?
$use_string = '';
switch($type) {
case 'food':
	$use_string = 'Eat';
break;
case 'drink':
	$use_string = 'Drink';
break;
default:
	$$use_string = 'Use';
break;
}
echo $use_string;

 

You probably don't need to complicate it that much but yea, or you could use an array like this...

 

$item_uses = array( 'food' => 'Eat', 'drink' => 'Drink');
$use_string = in_array($i['itemtype'], $item_uses) ? $item_uses[$i['itemtype'] : 'Use';

That's actually a good way of doing it, I'm playing around with the "array" at the moment. ^_^

If I can get it working I'll post here :)

 

Or store the action string in the database in `item_categories`, and fetch them before looping through your inventory?

I'm not sure If I've done anything like that before, But I'll look into it! :)

Link to comment
Share on other sites

Yeah [MENTION=70342]wrux[/MENTION] I think associative array would be best option or more like easiest option. I was going to suggest that but you beat me to it! :p

Well, look at you [MENTION=69670]Script47[/MENTION] using the tagging feature! :P

But using the array version [MENTION=70342]wrux[/MENTION] suggested is a little tricky, Because of how MCCodes have the itemtypes, But i'm close to figuring it out then i'll share it with everyone. ^_^ (Wouldn't be anywhere near figuring out without [MENTION=70342]wrux[/MENTION] & [MENTION=65371]sniko[/MENTION] i'm looking at he's way of doing it too!)

Link to comment
Share on other sites

[MENTION=70359]Markku[/MENTION] You could try using the item type ID instead of the name, might be easier

$array = array(

4 => 'Eat',

6 => 'Drink

);

You could use the item type id and reference it that way

Link to comment
Share on other sites

[MENTION=70359]Markku[/MENTION] You could try using the item type ID instead of the name, might be easier

$array = array(

4 => 'Eat',

6 => 'Drink

);

You could use the item type id and reference it that way

Hmmm tried this way, Still no luck.

 

Or you can create a usage label when you create the item in the staff panel and then add it to the list of columns to display in the inventory

What do you mean by create a usage label? ^_^

Link to comment
Share on other sites

Hmmm tried this way, Still no luck.

 

What do you mean by create a usage label? ^_^

In your items table you can create a new column for example "usage" so when you create a new item you can fill that in and that will be what is displayed.

Then you need to edit your inventory and add that in where the links for the item are like $r["usage"] or whatever it may be

Link to comment
Share on other sites

In your items table you can create a new column for example "usage" so when you create a new item you can fill that in and that will be what is displayed.

Then you need to edit your inventory and add that in where the links for the item are like $r["usage"] or whatever it may be

Oh i understand now, I was hoping I wouldn't have to add anything in the DB for this small feature.

It's just i'm having so much problems getting the array to work, Not sure why...

Link to comment
Share on other sites

Adding something to that table shouldnt really cause any overhead and its probably the easiest way to go about it code wise

Ooh okay, Well... The way me and wrux we're trying to do it was...

$item_uses = array( 6 => 'Eat', 7 => 'Drink');
$use_string = isset($item_uses[$i['itmtypeid']]) ? $item_uses[$i['itmtypeid']] : 'Use';

 

Obviously item ID 6/7 being "Food/Drink"

Then just replacing the "Use" with "use_string" but no luck...

Link to comment
Share on other sites

Well what is it showing as an end result.

Also, for each new item type you will have to edit your file ;)

If you just put:

echo $item_uses[6];

Anywhere in the file.

It'll display "EatEatEatEatEatEatEatEatEatEat" where you told it to echo.

But other than that, It just always displays "Use" on the actual link.

Link to comment
Share on other sites

Try this:

<?php
/**
* MCCodes Version 2.0.5b
* Copyright (C) 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: inventory.php
* Signature: 923658342519b486f3b2ebde8fa3d86f
* Date: Fri, 20 Apr 12 08:50:30 +0000
*/

require_once('globals.php');

//Add more here if required.
$itemActions = array (
   6 => 'Eat', //Alter to suit.
   7 => 'Drink', //Alter to suit.
);

$q =
       $db->query(
               "SELECT `itmid`, `itmname`
                FROM `items`
                WHERE `itmid`
                 IN({$ir['equip_primary']}, {$ir['equip_secondary']},
                    {$ir['equip_armor']})");
echo "<h3>Equipped Items</h3><hr />";
$equip = array();
while ($r = $db->fetch_row($q))
{
   $equip[$r['itmid']] = $r;
}
$db->free_result($q);
echo "<table width='75%' cellspacing='1' class='table'>
<tr>
<th>Primary Weapon</th>
<td>";
if (isset($equip[$ir['equip_primary']]))
{
   print
           $equip[$ir['equip_primary']]['itmname']
                   . "</td><td><a href='unequip.php?type=equip_primary'>Unequip Item</a></td>";
}
else
{
   echo "None equipped.</td><td> </td>";
}
echo "</tr>
<tr>
<th>Secondary Weapon</th>
<td>";
if (isset($equip[$ir['equip_secondary']]))
{
   print
           $equip[$ir['equip_secondary']]['itmname']
                   . "</td><td><a href='unequip.php?type=equip_secondary'>Unequip Item</a></td>";
}
else
{
   echo "None equipped.</td><td> </td>";
}
echo "</tr>
<tr>
<th>Armor</th>
<td>";
if (isset($equip[$ir['equip_armor']]))
{
   print
           $equip[$ir['equip_armor']]['itmname']
                   . "</td><td><a href='unequip.php?type=equip_armor'>Unequip Item</a></td>";
}
else
{
   echo "None equipped.</td><td> </td>";
}
echo "</tr>
</table><hr />
<h3>Inventory</h3><hr />";
$inv =
       $db->query(
               "SELECT `inv_qty`, `itmsellprice`, `itmid`, `inv_id`,
                `effect1_on`, `effect2_on`, `effect3_on`, `itmname`,
                `weapon`, `armor`, `itmtypename`, itmtypeid
                FROM `inventory` AS `iv`
                INNER JOIN `items` AS `i`
                ON `iv`.`inv_itemid` = `i`.`itmid`
                INNER JOIN `itemtypes` AS `it`
                ON `i`.`itmtype` = `it`.`itmtypeid`
                WHERE `iv`.`inv_userid` = {$userid}
                ORDER BY `i`.`itmtype` ASC, `i`.`itmname` ASC");
if ($db->num_rows($inv) == 0)
{
   echo "<b>You have no items!</b>";
}
else
{
   echo "<b>Your items are listed below.</b><br />
<table width=100% class=\"table\" border=\"0\" cellspacing=\"1\">
   <tr>
       <td class=\"h\">Item</td>
       <td class=\"h\">Sell Value</td>
       <td class=\"h\">Total Sell Value</td>
       <td class=\"h\">Links</td>
   </tr>";
   $lt = "";
   while ($i = $db->fetch_row($inv))
   {
       if ($lt != $i['itmtypename'])
       {
           $lt = $i['itmtypename'];
           echo "\n<tr>
                       <td colspan='4'>
                           <b>{$lt}</b>
                       </td>
                   </tr>";
       }
       if ($i['weapon'])
       {
           $i['itmname'] =
                   "<span style='color: red;'>*</span>" . $i['itmname'];
       }
       if ($i['armor'])
       {
           $i['itmname'] =
                   "<span style='color: green;'>*</span>" . $i['itmname'];
       }
       echo "<tr>
               <td>{$i['itmname']}";
       if ($i['inv_qty'] > 1)
       {
           echo " x{$i['inv_qty']}";
       }
       echo "</td>
             <td>" . money_formatter($i['itmsellprice'])
               . "</td>
             <td>";
       echo money_formatter($i['itmsellprice'] * $i['inv_qty']);
       echo "</td>
             <td>
                 [<a href='iteminfo.php?ID={$i['itmid']}'>Info</a>]
                 [<a href='itemsend.php?ID={$i['inv_id']}'>Send</a>]
                 [<a href='itemsell.php?ID={$i['inv_id']}'>Sell</a>]
                 [<a href='imadd.php?ID={$i['inv_id']}'>Add To Market</a>]";
       if ($i['effect1_on'] || $i['effect2_on'] || $i['effect3_on'])
       {
           if ( array_key_exists ( $i['itmtypeid'], $itemActions ) ) {
               echo ' [<a href="itemuse.php?ID='.$i['inv_id'].'">'.$itemActions[$i['itmtypeid']].'</a>]';
           } else {
               echo " [<a href='itemuse.php?ID={$i['inv_id']}'>Use</a>]";
           }
       }
       if ($i['weapon'] > 0)
       {
           echo " [<a href='equip_weapon.php?ID={$i['inv_id']}'>Equip as Weapon</a>]";
       }
       if ($i['armor'] > 0)
       {
           echo " [<a href='equip_armor.php?ID={$i['inv_id']}'>Equip as Armor</a>]";
       }
       echo "</td>
       </tr>";
   }
   echo "</table>";
   $db->free_result($inv);
   echo "<small><b>NB:</b> Items with a small red </small><span style='color: red;'>*</span><small> next to their name can be used as weapons in combat.<br />
Items with a small green </small><span style='color: green;'>*</span><small> next to their name can be used as armor in combat.</small>";
}
$h->endpage();

*Untested.

  • Like 1
Link to comment
Share on other sites

Try this:
<?php
/**
* MCCodes Version 2.0.5b
* Copyright (C) 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: inventory.php
* Signature: 923658342519b486f3b2ebde8fa3d86f
* Date: Fri, 20 Apr 12 08:50:30 +0000
*/

require_once('globals.php');

//Add more here if required.
$itemActions = array (
   6 => 'Eat', //Alter to suit.
   7 => 'Drink', //Alter to suit.
);

$q =
       $db->query(
               "SELECT `itmid`, `itmname`
                FROM `items`
                WHERE `itmid`
                 IN({$ir['equip_primary']}, {$ir['equip_secondary']},
                    {$ir['equip_armor']})");
echo "<h3>Equipped Items</h3><hr />";
$equip = array();
while ($r = $db->fetch_row($q))
{
   $equip[$r['itmid']] = $r;
}
$db->free_result($q);
echo "<table width='75%' cellspacing='1' class='table'>
<tr>
<th>Primary Weapon</th>
<td>";
if (isset($equip[$ir['equip_primary']]))
{
   print
           $equip[$ir['equip_primary']]['itmname']
                   . "</td><td><a href='unequip.php?type=equip_primary'>Unequip Item</a></td>";
}
else
{
   echo "None equipped.</td><td>*</td>";
}
echo "</tr>
<tr>
<th>Secondary Weapon</th>
<td>";
if (isset($equip[$ir['equip_secondary']]))
{
   print
           $equip[$ir['equip_secondary']]['itmname']
                   . "</td><td><a href='unequip.php?type=equip_secondary'>Unequip Item</a></td>";
}
else
{
   echo "None equipped.</td><td>*</td>";
}
echo "</tr>
<tr>
<th>Armor</th>
<td>";
if (isset($equip[$ir['equip_armor']]))
{
   print
           $equip[$ir['equip_armor']]['itmname']
                   . "</td><td><a href='unequip.php?type=equip_armor'>Unequip Item</a></td>";
}
else
{
   echo "None equipped.</td><td>*</td>";
}
echo "</tr>
</table><hr />
<h3>Inventory</h3><hr />";
$inv =
       $db->query(
               "SELECT `inv_qty`, `itmsellprice`, `itmid`, `inv_id`,
                `effect1_on`, `effect2_on`, `effect3_on`, `itmname`,
                `weapon`, `armor`, `itmtypename`, itmtypeid
                FROM `inventory` AS `iv`
                INNER JOIN `items` AS `i`
                ON `iv`.`inv_itemid` = `i`.`itmid`
                INNER JOIN `itemtypes` AS `it`
                ON `i`.`itmtype` = `it`.`itmtypeid`
                WHERE `iv`.`inv_userid` = {$userid}
                ORDER BY `i`.`itmtype` ASC, `i`.`itmname` ASC");
if ($db->num_rows($inv) == 0)
{
   echo "<b>You have no items!</b>";
}
else
{
   echo "<b>Your items are listed below.</b><br />
<table width=100% class=\"table\" border=\"0\" cellspacing=\"1\">
   <tr>
       <td class=\"h\">Item</td>
       <td class=\"h\">Sell Value</td>
       <td class=\"h\">Total Sell Value</td>
       <td class=\"h\">Links</td>
   </tr>";
   $lt = "";
   while ($i = $db->fetch_row($inv))
   {
       if ($lt != $i['itmtypename'])
       {
           $lt = $i['itmtypename'];
           echo "\n<tr>
                       <td colspan='4'>
                           <b>{$lt}</b>
                       </td>
                   </tr>";
       }
       if ($i['weapon'])
       {
           $i['itmname'] =
                   "<span style='color: red;'>*</span>" . $i['itmname'];
       }
       if ($i['armor'])
       {
           $i['itmname'] =
                   "<span style='color: green;'>*</span>" . $i['itmname'];
       }
       echo "<tr>
               <td>{$i['itmname']}";
       if ($i['inv_qty'] > 1)
       {
           echo "*x{$i['inv_qty']}";
       }
       echo "</td>
             <td>" . money_formatter($i['itmsellprice'])
               . "</td>
             <td>";
       echo money_formatter($i['itmsellprice'] * $i['inv_qty']);
       echo "</td>
             <td>
                 [<a href='iteminfo.php?ID={$i['itmid']}'>Info</a>]
                 [<a href='itemsend.php?ID={$i['inv_id']}'>Send</a>]
                 [<a href='itemsell.php?ID={$i['inv_id']}'>Sell</a>]
                 [<a href='imadd.php?ID={$i['inv_id']}'>Add To Market</a>]";
       if ($i['effect1_on'] || $i['effect2_on'] || $i['effect3_on'])
       {
           if ( array_key_exists ( $i['itmtypeid'], $itemActions ) ) {
               echo ' [<a href="itemuse.php?ID='.$i['inv_id'].'">'.$itemActions[$i['itmtypeid']].'</a>]';
           } else {
               echo " [<a href='itemuse.php?ID={$i['inv_id']}'>Use</a>]";
           }
       }
       if ($i['weapon'] > 0)
       {
           echo " [<a href='equip_weapon.php?ID={$i['inv_id']}'>Equip as Weapon</a>]";
       }
       if ($i['armor'] > 0)
       {
           echo " [<a href='equip_armor.php?ID={$i['inv_id']}'>Equip as Armor</a>]";
       }
       echo "</td>
       </tr>";
   }
   echo "</table>";
   $db->free_result($inv);
   echo "<small><b>NB:</b> Items with a small red </small><span style='color: red;'>*</span><small> next to their name can be used as weapons in combat.<br />
Items with a small green </small><span style='color: green;'>*</span><small> next to their name can be used as armor in combat.</small>";
}
$h->endpage();

*Untested.

Hey Djkanna, Thank you for taking your time to try and help with this. ^_^

I looked at your code and see what you did, I thought it would work, I then tried it on my localhost, And still the "Eat/Drink" does not show.

This is turning out to be trickier than expected :X

Link to comment
Share on other sites

Hey Djkanna, Thank you for taking your time to try and help with this. ^_^

I looked at your code and see what you did, I thought it would work, I then tried it on my localhost, And still the "Eat/Drink" does not show.

This is turning out to be trickier than expected :X

Did you change $itemActions?

Link to comment
Share on other sites

Did you change $itemActions?

Yes ^_^ (Message=2short)

Thanks to Djkanna, I now have this working!

Thank you all who contributed and helped out, I appreciate it! :)

Edited by Markku
Solution found!
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...