Jump to content
MakeWebGames

Inventroy help


SHAD

Recommended Posts

OK i have a problem with my inventry,when i buy two of the same items at different times,it does not stack them up.

How can it be prevented,please help.

 

<?php

include "globals.php";
if(isset($_SESSION['timer']) && time() < $_SESSION['timer'] + 10)
{
$time_left = ((time() - $_SESSION['timer']) - 10);
echo sprintf("You cannot buy yet, please wait for %s more second%s", str_replace('-', '', $time_left), ($time_left == -1) ? '' : 's');
$h->endpage();
exit;
}
if(isset($_SESSION['timer']) && time() > $_SESSION['timer'] + 9) { unset($_SESSION['timer']); }
$_SESSION['timer'] = time();
if($ir[hospital]>0)
die("You are in the hospital for {$ir[hospital]} minutes.");
if($ir[jail]>0)
die("You are in jail for {$ir[jail]} minutes.");

$_GET['ID']= abs((int) $_GET['ID']);
$_POST['qty']= abs((int) $_POST['qty']);
if(!$_GET['ID'] || !$_POST['qty'])
{
print "Invalid use of file";
}
else if($_POST['qty'] <= 0)
{
print "You have been added to the delete list for trying to cheat the game.";
}
else
{
$q=mysql_query("SELECT * FROM items WHERE itmid={$_GET['ID']}",$c);
if(mysql_num_rows($q) == 0)
{
print "Invalid item ID";
}
else
{
$itemd=mysql_fetch_array($q);
if($ir['money'] < $itemd['itmbuyprice']*$_POST['qty'])
{
print "You don't have enough money to buy this item!";
$h->endpage();
exit;
}
if($itemd['itmbuyable'] == 0)
{
print "This item can't be bought!";
$h->endpage();
exit;
}
$price=($itemd['itmbuyprice']*$_POST['qty']);
mysql_query("INSERT INTO inventory VALUES('',{$_GET['ID']},$userid,{$_POST['qty']},0);",$c);
mysql_query("UPDATE users SET money=money-$price WHERE userid=$userid",$c);
mysql_query("INSERT INTO itembuylogs VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')", $c);
print "You bought {$_POST['qty']} {$itemd['itmname']}(s) for \$$price";
}
}
$h->endpage();
?> 
Link to comment
Share on other sites

Item_Add

Hello, maybe i could direct your attention to a function in global_func.php

 

item_add($user, $itemid, $qty);

 

so where you have

mysql_query("INSERT INTO inventory VALUES('',{$_GET['ID']},$userid,{$_POST['qty']},0);",$c);
mysql_query("UPDATE users SET money=money-$price WHERE userid=$userid",$c);
mysql_query("INSERT INTO itembuylogs VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')", $c);

you could add

item_add($userid, $_GET['ID'], $_POST['qty']);
$db->query("UPDATE `users` SET `money` = `money` - $price WHERE `userid` = $userid");
$db->query("INSERT INTO `itembuylogs` VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')");
Link to comment
Share on other sites

Doh. Crimgame, after seeing your response I actually went up and checked the code he posted. I assumed it had just been his inventory script, but now see it did have his itembuy code... Glad you're not as lazy as me.

Ya SHAD, crimgame nailed your problem. The function he pointed out combines like items when it adds them, getting rid of your problem.

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