Hello everyone!
I want to build an inventory system with stacking limit.
My problem is that when the added item has a greater count than the limit it is not adding it correctly in the next available slot.
I tried everything that I could but no luck.
Here is my code:
I want to build an inventory system with stacking limit.
My problem is that when the added item has a greater count than the limit it is not adding it correctly in the next available slot.
I tried everything that I could but no luck.
Here is my code:
Code:
for (i = 0; i < MAX_SLOTS; i += 1)
{
//===================
// Add To New Slot
//===================
if (o_Inv_Ctrl.inv_slot[i].item = 0)
{
o_Inv_Ctrl.inv_slot[i].item = argument0;
o_Inv_Ctrl.inv_slot[i].item_count += argument1;
o_Inv_Ctrl.max_items_check += 1;
max_stack = Item_Max_Stock(argument0);
if (argument1 > max_stack)
{
var last_count = o_Inv_Ctrl.inv_slot[i].item_count-max_stack;
o_Inv_Ctrl.inv_slot[i].item_count = max_stack;
Item_Pickup(argument0,last_count);
done1 = 1;
show_message("yay")
}
return(1);
}
//================
// Add To Count
//================
if (o_Inv_Ctrl.inv_slot[i].item = argument0)
{
max_stack = o_Inv_Ctrl.inv_slot[i].max_count;
if (max_stack > o_Inv_Ctrl.inv_slot[i].item_count)
{
if (argument1+o_Inv_Ctrl.inv_slot[i].item_count > max_stack)
{
var last_count = abs(argument1-o_Inv_Ctrl.inv_slot[i].item_count);
o_Inv_Ctrl.inv_slot[i].item_count = max_stack;
Item_Pickup(argument0,last_count+1);
return(1);
}
else
{
o_Inv_Ctrl.inv_slot[i].item_count += argument1;
return(1);
}
}
}
}
return(0);