Hello everybody!

UPDATE [2]:

- added inventory limit

- fixed alphabetic sorting

- little issues and better coding

Upon request, I have developed a simple item system that gives the items random values based on a base value. In addition, it is now possible to equip items to make the player stronger. For reasons I had to do this in Construct 3. Nevertheless, it should be possible for anyone to open the c3p file and view all changes. Since you can not upload any c3p files in the tutorials, here is the link:

c3p-file: 1drv.ms/u/s!Ap_-qxoGKbDcdp-nbqSBulYC1oE

Note: I tried to bookmark all changes. This version has not been thoroughly tested. Bugs can occur.

Original:

I've tried a more complex inventory that can be used well in larger RPGs and can be easily customized. I would like to share my results with you. (Please excuse my language errors. English is not my mother tongue)

On this page I will briefly explain the theory. The code with comments can be found in the .capx.

Items

Before we build an inventory, we need items. How you create them and give them properties is up to you. However, some properties (object variables) are important for the placement in the inventory. I distinguish between World Items and Inventory Items.

Essential Variables for World Items:

• Name - Ingame name for sorting by alphabet

• Type - Item type for classification into a category (e.g. weapons, armor ...)

• Main property - property to be sorted (e.g., damage, defense ...)

• Priority - If you want to separate items within a category (e.g. melee weapons from ranged weapons)

• Letter - current letter index to compare while alphabetical sorting

• Quantity - The number of items in a stack

For Inventory Items there is also:

• Slot ID - Indicates the slot on which the item was placed

I have grouped items of a category in a sprite with different animations that relate their values from a dictionary. After the world items were ready, I cloned them and adjusted the variables for the inventory items. This should not be the content of this tutorial. You can proceed differently in your own game.

Inventory

The inventory consists mainly of the slots. For this, we use a sprite and give it the variable "Slot_ID". Then we copy this slot as often as we want to have slots and arrange them in order. When this is done, we give each slot the corresponding ID, starting with Slot 1 to Slot X. Since I refer to the sorting and placing of items on the slot, all relevant values of the looted item are packed into variables of the slot.

The slots require the following variables:

• Slot_ID

• Name of the item

• Number of items / size of the stack

• Priority of the item

• Main property of the item

• Letter of the item

The variables are always transferred from the corresponding item to the slot.

A small difficulty is that a slot takes all categories. If you have 5 categories, there can be 5 different items on Slot 1. Therefore, it is important to always save the currently active category in a variable (for me a global variable) and to assign all items to a category. So you can only select and display the items that match to the active category.

Looting

Each time you move the cursor over an item, you must make a unique selection, otherwise you will pick up several overlapping items with one click. For this purpose, we use a variable which always stores the UID of the targeted item. If we click on some overlapping items, we only want to pick up that one whose UID corresponds to the variable.

The following steps are performed for sorting into the inventory. For this I use a "For each" loop, which begins with the first slot and then ascending by Slot ID.

1. Is this item already in inventory?