Skip to content

Creating Inventory Items

Hannele Ruiz edited this page Jan 2, 2021 · 1 revision

Creating new Items is very easy! You just need to inherit the PlayerCompanion.Item or PlayerCompanion.StackableItem classes.

The difference between the two is that you can have multiple Item's with different values, but you can only have a single Stackableitem with a count property.

Creating Items

To create an Item, you need to create a class that inherits from PlayerCompanion.Item or PlayerCompanion.StackableItem. Then, you need to override the Name and Icon properties with the Name of the Item and a Squared Icon.

public class MyCustomItem : Item  // or StackableItem
{
    public override string Name => "Name of the Item";
    public override ScaledTexture Icon => new ScaledTexture("my_ytd", "my_texture");
}

If you don't have an icon to use, you can just set the ytd and texture to empty strings, like this:

    public override ScaledTexture Icon => new ScaledTexture("", "");

Now you have a new item ready to be used!

Events

Used

The Used event allows you to detect when an Item is used from the inventory. This can be used to make effects related to the consumption/usage of the Inventory Items.

WARNING: Not all of the 3rd party inventory systems will allow you to use/consume the Inventory Items. If this is the case, then the Inventory Menu can be used as a fallback.

CountChanged

This event will be triggered when the Count of a stackable item changes.

Clone this wiki locally