Jump to content
MakeWebGames

Recommended Posts

Posted

I made a mod on my game and I used this code to insert items into an inventory:

mysql_query("INSERT INTO inventory VALUES ('', $item, $userid, 1)",$c);

But doing that doesn't automatically quantify items together, what should I add to make it do so? Thanks :-D

Posted

Re: Auto quantify

Im pretty sure the "item_add" function can be used here.

If you look in your global_funcs.php it's in there.

I believe thats what it should be for your query.

NOTE: untested.

item_add($userid,$item,1)

Posted

Re: Auto quantify

 

Im pretty sure the "item_add" function can be used here.

If you look in your global_funcs.php it's in there.

I believe thats what it should be for your query.

NOTE: untested.

item_add($userid,$item,1)

This only applies if V2

Posted

Re: Auto quantify

 

function item_give($user, $itemid, $qty, $notid=0)
{
 if($notid > 0)
 {
   $q=mysql_query("SELECT * FROM inventory WHERE inv_userid={$user} and inv_itemid={$itemid} AND inv_id != {$notid}");
 }
 else
 {
   $q=mysql_query("SELECT * FROM inventory WHERE inv_userid={$user} and inv_itemid={$itemid}");
 }
 if(mysql_num_rows($q) > 0)
 {
   $r=mysql_fetch_array($q);
   mysql_query("UPDATE inventory SET inv_qty=inv_qty+{$qty} WHERE inv_id={$r['inv_id']}");
 }
 else
 {
   mysql_query("INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES ({$itemid}, {$user}, {$qty})");
 }
}

 

You use it like

item_give(USERID, ITEMID, QTY);

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