Jump to content

[SOLVED] Random Item Deletion


Sinikka

Recommended Posts

I'm trying to code in a random event that pulls a random item from a users inventory and removes it. Currently we have random events that add in items from a specific list of pre-set items but I want this to pull from the users inventory and not a pre-set list. I think the problem I'm having is getting it to pull the inventory and randomize but I can't see what I'm doing wrong.

 

if ($username)
{
$getRandomEventSteal = fetch("SELECT * FROM useritems2 WHERE game = '$game'");

$getitemSteal = rand(1,5);
if ($getitemSteal == "5")
{
	$getPrize = $getRandomEventSteal[item_id];

	$randPrize = rand(0,$getRandomEventSteal[item_id]);
	$getPrize2 = $getPrize[$randPrize];

	$find_item3 = fetch("SELECT * FROM items2 WHERE id = '$getPrize2'");

	if ($find_item3[id])
	{
		$randomEvent .= "
<center><br><table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td>
<img src=$base_url/images/user_images/opg_$game/items/item_$find_item3[id].gif width=90 height=90 hspace=10 align=left>
<font color=#000000 size=3 face=verdana><b>X</b> appears and steals a $getPrize2 from you!</font></td></tr></table></center>
		";

mysql_query("DELETE FROM usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$find_item3[id]','$find_item3[parts]','$game')");

mysql_query("INSERT INTO random_events2 (item_id,item_name,owner,owner_name,date,timestamp,game) 
VALUES ('$find_item3[id]','$find_item3[item_name]','$userid','$username','$datestamp','$timestamp','$game')");
	}
}

}

Link to comment
https://forums.phpfreaks.com/topic/181173-solved-random-item-deletion/
Share on other sites

I just noticed that and another mistake I made in the original code. I've gotten it to pull up the item and remove it with inserting the record but it's also taking all of the items if you have more then one.

 

if ($username)
{
$getRandomEventSteal = fetch("SELECT * FROM usersitems2 WHERE owner = '$userid' AND game = '$game'");

$getitemSteal = rand(1,5);
if ($getitemSteal == "5")
{
	$getPrize = explode(" ", $getRandomEventSteal[item_id]);

	$randPrize = rand(0, count($getPrize) - 1);
	$getPrize2 = $getPrize[$randPrize];

	$find_item3 = fetch("SELECT * FROM items2 WHERE id = '$getPrize2'");

	if ($find_item3[id])
	{
		$randomEvent .= "
<center><br><table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td>
<img src=$base_url/images/user_images/opg_$game/items/item_$find_item3[id].gif width=90 height=90 hspace=10 align=left>
<font color=#000000 size=3 face=verdana><b>X</b> appears and steals a $find_item3[item_name] from you!</font></td></tr></table></center>
		";

mysql_query("DELETE FROM usersitems2 WHERE item_id = '$find_item3[id]' AND owner = '$userid' AND game = '$game'");

mysql_query("INSERT INTO random_events2 (item_id,item_name,owner,owner_name,date,timestamp,game) 
VALUES ('$find_item3[id]','$find_item3[item_name]','$userid','$username','$datestamp','$timestamp','$game')");
	}
}

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.