Oks, since Im nice today, I will post here my script to put item in the first empty slot of the char, just credit me <3
little explanation:
it selects from inventory table, using charid = to the id of the char and backpack_number = -1(no backpack, the inventory itself), it orders by inventory slot, so, it will be on a sequence ascending, meaning that the first number from 0 to 41 that is free is an empty place to put the item.
the for makes that check, it keep adding 1 to the count variable and takes each line of the reg, from the begining to the end. When the numbers arent the same, that means that the COUNT number is the empty slot. Then it inserts or shows a warning of full inventory.
I hope you understand, also, you can modify it to a backpack or even bank so it goes into a logical order(inventory, backpack, bank).
Here it goes:
Code:
$select = mysql_query("select inventoryslot from inventory where charid = $id and backpack_number = -1 order by inventoryslot asc");
$found = 'false';
for ($cont = 0; $cont <= 41; $cont++)
{
$reg = mysql_fetch_row($select);
if ($reg[0] != $cont)
{
$found = 'true';
break;
}
}
if ($found == 'true')
{
$insere = mysql_query("insert into inventory(itemid, charid, inventoryslot, count, addedByQuestID, backpack_number) values($itemId, $charId, $cont, $quantity, -1, -1)");
$update = mysql_query("update characters set penya = $penya where id = $charid");
if (mysql_affected_rows() != 0)
{
echo "<h3>Successfull bought the item.</h3>";
}
else
{
echo "<h3><font color='#FF0000'>Error</font>: Error trying to buy.</h3>";
}
}
else
{
echo "<h3><font color='#FF0000'>Warning</font>: Your inventory is full.</h3>";
}
also, please check if the '<= 41' in the for is right or if is just '< 41'.