Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: Stranga on Thu 25/01/2018 13:03:58

Title: How to give player all items without debug [SOLVED]
Post by: Stranga on Thu 25/01/2018 13:03:58
Hello everyone!

I want to know is there a way to give the player all inventory items they don't have? I'm making my own debug system because I will be using it as a cheats mechanic later on after the game is finished.

Any help would be greatly appreciated!
Title: Re: How to give player all items without debug
Post by: Crimson Wizard on Thu 25/01/2018 13:17:52
Whenever you want to process all entities of category at once, you need two things: find an array these entities are stored in, and use the loop operator.

For example, character has InventoryQuantity array that stores how many of each item does he has:
Code (ags) Select

for (int i = 0; i < Game.InventoryItemCount; i++)
{
    if (player.InventoryQuantity[i] == 0)
        player.InventoryQuantity[i] = 1;
}
UpdateInventory();


Alternate variant, but I think it may be slower. I am posting it for the sake of mentioning "inventory" array only. "inventory" array holds all inventory item references existing in game.
Code (ags) Select

for (int i = 0; i < Game.InventoryItemCount; i++)
{
    InventoryItem *inv = inventory[i];
    if (!player.HasInventory(inv))
        player.AddInventory(inv);
}
Title: Re: How to give player all items without debug
Post by: Stranga on Thu 25/01/2018 13:25:57
Thanks CW! The alternative worked for me.
Title: Re: How to give player all items without debug [SOLVED]
Post by: Stupot on Fri 26/01/2018 00:42:13
I actually asked this exact question on Discord a few weeks ago. I ended up making a pigs ear of my attempt. I'll try this method, CW.

My plan is to have a separate ‘debug' inventory filled with all items in it which I can bring up anywhere in the game and give the player character only specific items he needs rather than everything.