Jump to content
MakeWebGames

Recommended Posts

Posted

I want it so if you have a tomato (ID 32), cheese (ID 33), and crust (ID 34), you can make a pizza (ID 35)

I'm not really sure on how to do it, I know how to

$db->query("INSERT INTO inventory VALUES('',35,$userid,1)");

but I'm stuck on how to make it so if they have the ingredients, they can make the food, but if they don't, it tells them they need the ingredients.

Posted

Re: If you have an item, you can create another?

could probably do it one of several ways. select those items like.. maybe..

$pizza=$db->query("SELECT * FROM inventory WHERE inv_itemid=32 && inv_itemid=33 && inv_itemid=34 AND inv_userid=$userid");
if($db->num_rows($pizza)){
$db->query("INSERT INTO inventory VALUES('',35,$userid,1)");
print"You made a pizza with all the required ingredients";
}
else
{
print"You do not have all the required ingredients to create a pizza. You need Tomato, Cheese, and a Crust";
}

that is one way possible. Course I am a rusty old sot.. others probably have a far better way.

Posted

Re: If you have an item, you can create another?

ok.. I will really honestly work on this. as I said.. that was one possible. another way would be to select all from a users inventory, then look for those particular items, 32, 33, and 34.. and if present, they can make the pizza.

v2 code is not much different to write.. my game is still "v1".. if I had to version, prob v1.8 by now.. so much rewrite has gone on.. give me a bit.. I will find a workable solution for you.

Posted

Re: If you have an item, you can create another?

 

$stuff = mysql_query("SELECT inv_id FROM `inventory` WHERE `inv_itemid` = 32 AND `inv_itemid` = 33 AND `inv_itemid` = 34");
if(mysql_num_rows($stuff))	{
echo TRUE;
}
else	{
echo FALSE;
}
Posted

Re: If you have an item, you can create another?

he does not want it to just echo true or false though. he wants the system to give another item. Then, be sure to take that new item into account and be sure to wipe the ingredients, or you will find a whole ton of pizzas made on just one set of ingredients. Maybe this scenario.

$pizza=$db->query("SELECT * FROM inventory WHERE inv_userid=$userid");
while($p=$db_fetch_row($pizza))
{
if($p['inv_itemid']==32 && $p['inv_itemid']==33 && $p['inv_itemid']==34)
{
 $db->query("INSERT INTO inventory VALUES('',35,$userid,1)");
 $db->query("DELETE FROM inventory WHERE inv_itemid=32 and inv_userid=$userid LIMIT 1");
 $db->query("DELETE FROM inventory WHERE inv_itemid=33 AND inv_userid=$userid LIMIT 1");
 $db->query("DELETE FROM inventory WHERE inv_itemid=34 AND inv_userid=$userid LIMIT 1");
 print"You have made a Pizza using all the need ingredients";
 }

else
{
 print"You do not have the required ingredients to make pizza. You need to have Tomato, Cheese, and Crust.";
 }
}
Posted

Re: If you have an item, you can create another?

but I dont have all your file man.. you were asking about a query to give an item.. I am really trying to help you.. its not often I even speak on here..

Posted

Re: If you have an item, you can create another?

 

$stuff = mysql_query("SELECT inv_id FROM `inventory` WHERE `inv_itemid` = 32 AND `inv_itemid` = 33 AND `inv_itemid` = 34 AND `inv_userid` = ".$ir['userid']);
if(mysql_num_rows($stuff))    {
   item_add($ir['userid'], 35, 1);
   item_remove($ir['userid'], 32, 1);
   item_remove($ir['userid'], 33, 1);
   item_remove($ir['userid'], 34, 1);
   echo 'You successfuly made a pizza!';
}
else    {
   echo 'You do not have the sufficient ingredients yet.';
}

 

_Eagle, why select the entire inventory when only certain required?

The above should work :)

Posted

Re: If you have an item, you can create another?

 

that is one way possible. Course I am a rusty old sot.. others probably have a far better way.

Told ya. I am rusty.. not up to speed..

Posted

Re: If you have an item, you can create another?

As i said:

 

<?php
include_once('globals.php');
echo '<h2>Lets Make Pizza!</h2>';


$stuff = mysql_query("SELECT inv_id FROM `inventory` WHERE `inv_itemid` = 32 AND `inv_itemid` = 33 AND `inv_itemid` = 34 AND `inv_userid` = ".$ir['userid']);
if(mysql_num_rows($stuff))	{
item_add($ir['userid'], 35, 1);
item_remove($ir['userid'], 32, 1);
item_remove($ir['userid'], 33, 1);
item_remove($ir['userid'], 34, 1);
echo 'You successfuly made a pizza!';
}
else	{
echo 'You do not have the sufficient ingredients yet.';
}

$h->endpage();
?>

 

Post any error's.

Posted

Re: If you have an item, you can create another?

I just don't know why, but it still says I don't have the sufficient ingredients. It's probably my fault, but I'm 100% sure they are the correct IDs, because I checked PHPMyAdmin and the game itself.

Posted

Re: If you have an item, you can create another?

Something along these lines... (using HD's code changing only the SQL statement

 

<?php
include_once('globals.php');
echo '<h2>Lets Make Pizza!</h2>';

$stuff = $db->query("SELECT `inv_id` FROM `inventory` WHERE `inv_id` IN (32, 33, 34) AND `inv_userid` = '{$ir['userid']}'");
if(mysql_num_rows($stuff))   {
  item_add($ir['userid'], 35, 1);
  item_remove($ir['userid'], 32, 1);
  item_remove($ir['userid'], 33, 1);
  item_remove($ir['userid'], 34, 1);
  echo 'You successfuly made a pizza!';
}
else   {
  echo 'You do not have the sufficient ingredients yet.';
}

$h->endpage();
?>
Posted

Re: If you have an item, you can create another?

HD: quite right on there... as he needs to have the items id's 32,33,34 to be able to create the item id 35... if one of those is missing... it'll return 0 rows otherwise it'll go just to a successfull pizza ;)

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