www.mygunwars.com Posted October 2, 2008 Posted October 2, 2008 A friend of mine coded this for me and i dont know if it right. { $iq=$db->query("SELECT * FROM items WHERE itmbuyable=1 ORDER BY rand() LIMIT 1",$c); $r=mysql_fetch_array($iq); $item=$r['itmid']; $userid=$ir['userid']; $db->query("INSERT INTO inventory VALUES ('', $item, $userid, 1)",$c); event_add($userid,"You found a {$r['itmname']} While Walking Around the city.",$c); } Users have been geting items that dont exist. Quote
hobbes Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Have you deleted items in the past? If so, then users are getting an 'itmid' that is no longer valid. Example, ITEM ID 1 - GUN 2 - ARMOUR 3 - DRUGS 4 - CAT 5 - HAT You decide you don't want cats in the game, delete itemid 4, now itemid 4 is blank, so rand(['itmid'] can include items that do not exist any longer. Solution? TRUNCATE your table and reinsert all items, otherwise create items in deleted itemid's. Or.. use killah's script?? Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city You can try this: $rand = rand(1,5); //Rand to check if he get's the item or not. if($rand == 3) //Now if it is rand 3 continue { $data = mysql_query("SELECT itmid,itmname FROM items WHERE itmbuyable=1 ORDER BY itmid rand() LIMIT 1"); //Query the item $soc = mysql_fetch_assoc($data); //Fetch variable $data $item = $soc['itmid']; //Item ID //Check if item exists and etc if(!$item) //Give false event { event_add($ir['userid'],"You thought you saw something lying on the ground while walking the city, but it was nothing."); //Event false event } else //Else give item { //Now we check if the user has already got this item. $while = mysql_query("SELECT * FROM inventory WHERE inv_userid=".$ir['userid']." AND inv_itmid=".$item); if(mysql_num_rows($while) > 0) //If he has the item just plus up the qty { mysql_query("UPDATE inventory SET inv_qty=inv_qty+1 WHERE inv_userid=".$ir['userid']." AND inv_itmid=".$item); //Plusing the QTY } else //Else insert the item { mysql_query("INSERT INTO inventory (inv_itmid,inv_userid,inv_qty) VALUES(".$item.",".$ir['userid'].",1)"); //Inserting the item } event_add($ir['userid'],"You found ".$soc['itmname']." while walking the street\'s"); //Event user that he got item name blah. } } UNTESTED! Quote
Zero-Affect Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city $while = mysql_query("SELECT * FROM inventory WHERE inv_userid=".$ir['userid']." AND inv_itmid=".$item); i won't even comment, take another look Kyle * Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city As far as i can see there is nothing wrong with that query. Quote
Zero-Affect Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city ah right ill let someone else comment since we are ok now and i don't want to get in a argument but * Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city No No No, please tell me what's wrong with that query. Quote
Guest Anonymous Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Just what is the point of SELECT * FROM inventory WHERE ... here ? Totally unnecessary IMO Quote
Zero-Affect Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Just what is the point of SELECT * FROM inventory WHERE ... here ? Totally unnecessary IMO whats IMO? and she pointed it out mate Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Nyna, did you read over the code? It check's if the user has the item, and if he does then it add's up if not it inserts. Quote
Guest Anonymous Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Nyna, did you read over the code? It check's if the user has the item, and if he does then it add's up if not it inserts. Did you read my question? For reference, in case your scroll bar is faulty... Just what is the point of SELECT * FROM inventory WHERE ... here ? whats IMO? In My Opinion I'd use IMHO (In My Humble Opinion) but I'm not feeling humble. Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city The use of that query: $while = mysql_query("SELECT * FROM inventory WHERE inv_userid=".$ir['userid']." AND inv_itmid=".$item); It is selecting from inventory where inv_userid is my id & itm id is the item. If the user has the item, we adjust the inv_qty=inv_qty+1 ELSE it inserts into the inventory. Does that answer your question? Quote
Guest Anonymous Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Nope... Why are you running it? It's redundant. Quote
Zero-Affect Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city fyi: there is a item add function in globals func Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Mmmm, i never knew the item_add() function check's if the user has the item or not. My mistake. $rand = rand(1,5); //Rand to check if he get's the item or not. if($rand == 3) //Now if it is rand 3 continue { $data = mysql_query("SELECT itmid,itmname FROM items WHERE itmbuyable=1 ORDER BY itmid rand() LIMIT 1"); //Query the item $soc = mysql_fetch_assoc($data); //Fetch variable $data $item = $soc['itmid']; //Item ID //Check if item exists and etc if(!$item) //Give false event { event_add($ir['userid'],"You thought you saw something lying on the ground while walking the city, but it was nothing."); //Event false event } else //Else give item { //Credit item and event user. item_add($ir['userid'],$item,1); event_add($ir['userid'],"You found ".$soc['itmname']." item while walking the city"); //Event user that he got item name blah. } } Quote
Zero-Affect Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Mmmm, i never knew the item_add() function check's if the user has the item or not. My mistake. $rand = rand(1,5); //Rand to check if he get's the item or not. if($rand == 3) //Now if it is rand 3 continue { $data = mysql_query("SELECT itmid,itmname FROM items WHERE itmbuyable=1 ORDER BY itmid rand() LIMIT 1"); //Query the item $soc = mysql_fetch_assoc($data); //Fetch variable $data $item = $soc['itmid']; //Item ID //Check if item exists and etc if(!$item) //Give false event { event_add($ir['userid'],"You thought you saw something lying on the ground while walking the city, but it was nothing."); //Event false event } else //Else give item { //Credit item and event user. item_add($ir['userid'],$item,1); event_add($ir['userid'],"You found ".$soc['itmname']." item while walking the city"); //Event user that he got item name blah. } } learn something new everyday mate :-D Quote
Haunted Dawg Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Well ok, i really do not work on the global_func.php file. I work on my own coding. As i know it should work good. Quote
Zero-Affect Posted October 3, 2008 Posted October 3, 2008 Re: Finding Items in the city Well ok, i really do not work on the global_func.php file. I work on my own coding. As i know it should work good. i only know from recoding some of it so i know how ya feel no biggy really mate Quote
www.mygunwars.com Posted October 4, 2008 Author Posted October 4, 2008 Re: Finding Items in the city Thanks I will add it killah Quote
avguste Posted October 12, 2008 Posted October 12, 2008 Re: Finding Items in the city So what is this doing exactly? Quote
TrolEsq Posted September 3, 2013 Posted September 3, 2013 So what is this doing exactly? Looks like this script gives the user an item, based on 1:5 odds, it runs checks to see if the user has the item and gives it to them whether or not the user has the item already. Quote
Dayo Posted September 4, 2013 Posted September 4, 2013 looks like they needed your answer 5 years ago ... Quote
DeathsAlive Posted September 4, 2013 Posted September 4, 2013 looks like they needed your answer 5 years ago ... Necro'ed the thread! >.< Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.