Jump to content
MakeWebGames

Recommended Posts

Posted

Hi

I would like the ability to be able to use an item multiple times instead of only being able to use an item 1 at a time even if I own like 100 of an item

thanks

Posted

You'd need to add a quantity to the Items table, then on the item use, make a form for how many they want to use

Then just do some checks

 

if((isset($_POST['Amount'])) && ctype_digit($_POST['Amount'])) {
mysql_query("UPDATE `inventory` SET `Quantity` = `Quantity` - ".$_POST['Amount']." WHERE (`userid` = ".$_SESSION['userid'].") AND (`inv_id` = ".$r['inv_id'].")");
echo 'You used '.number_format($_POST['Amount']).' of the '.htmlentities($Item['ItemName']).''; // I'm sure something like $Item was defined elsewhere
}

 

I don't care if you would do this differently, do it your way if that's the case

This may not be 100% accurate, I've forgotten a lot of the McCodes setup, and this is just a quick idea of how it can be done.

That's the way I'd do it

Posted
Wrong.

Itemuse works by the "inv_id", as each one is different, you'd get the error "You don't own this item" after a refresh.

f5 works on mcc and still takes down the amount of that item if you have none of that item left then it tells you that

Posted
$_GET['spend'] = isset($_GET['spend']) && is_string($_GET['spend']) ? strtolower(trim($_GET['spend'])) : "";
$quantity = mysql_query("SELECT i.* , u.userid from inventory i users uLEFT JOIN i.inv_userid=u.userid"); //This query probably fails, I suck at queries
if(!$_GET['spend'])
{
echo "All of your itemuse stuff goes here except the qunatity actions";

}
else if($_GET['spend'] == 'quantity')
{
echo "Type in the amount of {$r['itmname']} you wish to use.
";
echo "<form action='itemuse.php?action=quantity2' method='post'>";
echo "<input type='text' name='quantity' />
";
echo "<input type='submit' value='Submit' />";
echo "</form>";
}
else if($_GET['spend'] == 'crystals2')
{

$_POST['quantity'] = (float) $_POST['quantity'];
if($_POST['quantity'] <= 0 || $_POST['quantity'] > {$ir['inv_qty']} //Once again, the {$r['inv_qty']} bit is probably wrong.
{
echo "Error, you either do not have enough {$r['itmname']}s or did not fill out the form.

[url='itemuse.php?action=quantity']Back[/url]";
$h->endpage();
exit;
}

$TakeVotePoints = sprintf("UPDATE inventory SET inv_qty - inv_qty - %s WHERE (userid = %u)", $_POST['quantity'], $userid);

$db->query($TakeVotePoints);
echo "You have used {$_POST['quantity']} {$r['itmname']}(s). 
//Add in your itemuse codes here, I can't think atm :P
}

 

Untested and most likely won't work, but thats the basic outline. The queries are probably wrong as I'm not good using 2+ tables at once. Hope a better coder can brush this up (or recode it better lol)

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