How to limit my inventory to exact amount of items?

Started by WiseFrog, Thu 13/05/2021 02:51:13

Previous topic - Next topic

WiseFrog

Hi, in my game you will have 2 inventories, one (the main) only show 10 item spaces, and the other one (will show the items that you have in the main inventory and the rest of items) have more space (but will be restringed at first, something like resident evil that you can upgrade more space).

What I need to do is when you have your first 10 items, "block" in some way the inventory windows and start adding new items in the secondary one. Exist some way to know if you have the 10 inventory items spaces full? (Or know if more spaces are full, to implement the blocking inventory until upgrade like resident evil in the secondary inventory window)

I was reading the manual and tried to make my own function to add items, but I don't know why when you get the item number 11 the main and the second inventory suddenly have all the items sprites invisible.

My code is:

Code: ags
void AddInventoryExtend(InventoryItem *item, int addAtIndex) {
  if (PlayerMainShow.ItemCount >= (PlayerMainShow.ItemsPerRow * PlayerMainShow.RowCount)) {
    player.Say("Inventory full, will be added to the bag.");
    cSInventory.AddInventory(item, addAtIndex);
  }
  else if (PlayerMainShow.ItemCount < (PlayerMainShow.ItemsPerRow * PlayerMainShow.RowCount)) {
    player.AddInventory(item, addAtIndex);
  }
}


The code in some way work because the items are added to my inventory and the player says the message when I try to add the item number 11 but after that suddenly happen what I said above.

The other problem is that I will use the Khris script Stacking Inv (To stack the items and show the amount number), his code only works if I use with the global setting "display multiple icons for multiple items" deactivated, I delete the Krhis script and activated that option only to test my code because I read that the script ItemCount only works with that option activated. So exist some way to "fix" my code or do what I want (what I explained in the top of the post) and without using the itemcount (so I can use the Khris stacking inv too)?

Thanks in advance to whoever can help me

WiseFrog

Well I was able to fix the problem, apparently it was caused by an item that was one pixel wider, now if the inventory have 10 objects will start to adding the rest of items in the other inventory. But I have a new problem, I don't know why the Khris's "Stacking Inventory" module doesn't update correctly the numbers (quantity of the object). If, for example, I talk to a character and he gives me 10 cookies, 3 stones and 2 diamonds, only the number of the amount of objects I have appears in the cookies and the diamond, not in the stones. Now if you add after the diamond one stone more it will shows the cookies and the stones but no longer shows the number of diamonds. I do not know if it is a problem in the module code or something, the module is the following: https://www.adventuregamestudio.co.uk/forums/index.php?topic=56481.msg636595239#msg636595239

Thanks.

WiseFrog

Well as I didn't find a way to fix it, I tried to create my own function, after many errors and tests to get my function work I succeeded. It works perfectly, the problem is I believe that it's not the properly way to do it, since for example if I want an inventory of 40 objects, it would be crazy to make an InventoryItem for 40 checks, there is a way to improve my code to make it "simpler" or more accesible the way to implement it. The script is the follow (the number of objects of the same item is applied to a label):

Code: ags

int itemcount[10];

void UpdateInvNumber() {
  InventoryItem *CountItem1 = PlayerMainShow.ItemAtIndex[0];
  InventoryItem *CountItem2 = PlayerMainShow.ItemAtIndex[1];
  InventoryItem *CountItem3 = PlayerMainShow.ItemAtIndex[2];
  InventoryItem *CountItem4 = PlayerMainShow.ItemAtIndex[3];
  InventoryItem *CountItem5 = PlayerMainShow.ItemAtIndex[4];
  InventoryItem *CountItem6 = PlayerMainShow.ItemAtIndex[5];
  InventoryItem *CountItem7 = PlayerMainShow.ItemAtIndex[6];
  InventoryItem *CountItem8 = PlayerMainShow.ItemAtIndex[7];
  InventoryItem *CountItem9 = PlayerMainShow.ItemAtIndex[8];
  InventoryItem *CountItem10 = PlayerMainShow.ItemAtIndex[9];
  if (CountItem1 != null) {
    lInv1.Visible = true;
    itemcount[1] = player.InventoryQuantity[CountItem1.ID];
    lInv1.Text = String.Format("%d", itemcount[1]);
  }
  else {
    lInv1.Visible = false;
  }
  if (CountItem2 != null) {
    lInv2.Visible = true;
    itemcount[2] = player.InventoryQuantity[CountItem2.ID];
    lInv2.Text = String.Format("%d", itemcount[2]);
  }
  else {
    lInv2.Visible = false;
  }
  if (CountItem3 != null) {
    lInv3.Visible = true;
    itemcount[3] = player.InventoryQuantity[CountItem3.ID];
    lInv3.Text = String.Format("%d", itemcount[3]);
  }
  else {
    lInv3.Visible = false;
  }
  if (CountItem4 != null) {
    lInv4.Visible = true;
    itemcount[4] = player.InventoryQuantity[CountItem4.ID];
    lInv4.Text = String.Format("%d", itemcount[4]);
  }
  else {
    lInv4.Visible = false;
  }
  if (CountItem5 != null) {
    lInv5.Visible = true;
    itemcount[5] = player.InventoryQuantity[CountItem5.ID];
    lInv5.Text = String.Format("%d", itemcount[5]);
  }
  else {
    lInv5.Visible = false;
  }
  if (CountItem6 != null) {
    lInv6.Visible = true;
    itemcount[6] = player.InventoryQuantity[CountItem6.ID];
    lInv6.Text = String.Format("%d", itemcount[6]);
  }
  else {
    lInv6.Visible = false;
  }
  if (CountItem7 != null) {
    lInv7.Visible = true;
    itemcount[7] = player.InventoryQuantity[CountItem7.ID];
    lInv7.Text = String.Format("%d", itemcount[7]);
  }
  else {
    lInv7.Visible = false;
  }
  if (CountItem8 != null) {
    lInv8.Visible = true;
    itemcount[8] = player.InventoryQuantity[CountItem8.ID];
    lInv8.Text = String.Format("%d", itemcount[8]);
  }
  else {
    lInv8.Visible = false;
  }
  if (CountItem9 != null) {
    lInv9.Visible = true;
    itemcount[9] = player.InventoryQuantity[CountItem9.ID];
    lInv9.Text = String.Format("%d", itemcount[9]);
  }
  else {
    lInv9.Visible = false;
  }
  if (CountItem10 != null) {
    lInv10.Visible = true;
    itemcount[10] = player.InventoryQuantity[CountItem10.ID];
    lInv10.Text = String.Format("%d", itemcount[10]);
  }
  else {
    lInv10.Visible = false;
  }
}

function repeatedly_execute_always() {
  UpdateInvNumber();
}

SMF spam blocked by CleanTalk