S-Inventory

This page describes how to set up the Dialogue System with SoumiDelRio's S-Inventory and how to use them together. (S-Inventory v1.31+ is required.)

S-Inventory copyright © SoumiDelRio.

There is a separate page for Realistic FPS Prefab / S-Inventory integration. Before incorporating Realistic FPS Prefab, you should familiarize yourself with the basic S-Inventory integration described on this page first.


S-Inventory Setup

Follow these steps to set up the Dialogue System with S-Inventory.

Import Files

The Dialogue System works with the C# version of S-Inventory. Build your game using the C# version.

  • Import the package Third Party Support/S-Inventory Support. This will unpack files into the folder Third Party Support/S-Inventory.

Setup Actors

Follow these steps to set up an actor (e.g., Player) that has an inventory:

  1. Add the prefab S-Inventory/C#/Prefabs/S-InventoryC# to your scene as a root object – in other words, it shouldn't be the child of any other GameObjects. NOTE: This step was changed for S-Inventory 1.25+. In earlier versions, the S-InventoryC# prefab was added as a child of your Player GameObject.
  2. Expand S-InventoryC#/S-InventoryC#.
    • Assign the player GameObject to these components:
      • InventoryManagerC#
    • Untick Save and Load on these GameObjects (since you can save and load more flexibly with the Dialogue System):
      • InventoryManagerC#
      • EquipmentC#
      • SkillBarC#
    • On SkillBarC#, tick Destroy On Use for any slots that should destroy consumables, such as slot 0 for Health Potions.
    • If upgrading from S-Inventory v1.24 or earlier, reassign VendorC# to your vendors and ItemGroupC# to your item groups.
  3. Add an SInventory Dialogue Actor component to the actor. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Dialogue Actor)
    • If you want to save the actor's inventory in Dialogue System saved games, tick Save Inventory.
    • If you want to hide S-Inventory's GUI during conversations, tick Hide Inventory In Conversations. For this to work, the SInventory Dialogue Actor component must be on the main GameObject that is involved in the conversation.
  4. (Optional:) Add an SInventory Treat As Conversation component if you want vendors and item groups to send OnConversationStart and OnConversationEnd messages to the player when used. You can use this to trigger Set Component Enabled On Dialogue Event to disable player controls for the duration of the interaction. (Component > Dialogue System > Third Party > S-Inventory > Treat As Conversation) (Do not add this if you're using Realistic FPS Prefab.)
  5. (Optional:) Add an Override Actor Name component if you want to use a different name from the GameObject name for the actor's entry in the Lua environment and in conversations. (Component > Dialogue System > Actor > Override Actor Name)

Setup Item Prefabs

To save and load items, they must be prefabs in a Resources folder. They cannot be in a subfolder of Resources. You can have any number of Resources folders, and they can be located anywhere in your project. When loading a saved game, the Dialogue System will look for prefabs in Resources whose asset names match the item names of the saved items. The Item name in the Item script must exactly match the name of the GameObject and prefab.

S-Inventory ships with some example prefabs (Health Potion, Sword, etc.) in S-Inventory/C#/Prefabs. You can copy them into a Resources folder if you want to use them. The prefab's name must match the name of the item. This support package's example scene also contains some prefabs in the Example/Resources folder.

When you place an item in the scene that the player can pick up, add an S-Inventory Persistent Item Pickup component if you want saved games to remember whether the item has been picked up. Set Save Name to a unique name. If you leave it blank, it will use the GameObject's name. If you need to debug its persistent state when changing scenes or saving/loading games, tick Debug; this will log to the console what's being saved and loaded.

Setup Containers

Follow these steps to configure a container (e.g., chest that starts empty):

  1. Add an S-Inventory Container component to the item group.
    • Assign S-InventoryC#/S-InventoryC#/ContainerC# to the component.
    • If you will use the Dialogue System's trigger system, set Min Distance to 0.
  2. Add an SInventory Container Trigger to the container. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Container Trigger) This trigger starts the S-Inventory container GUI when the game object receives a specified trigger event. For example, you can add this and a static trigger collider to an area, and set the trigger to OnTriggerEnter. When the player enters the trigger area, it will open the container. Or add a collider and a Usable component, and set the trigger to OnUse. The SInventory Container Trigger also sends OnContainerStart(container) and OnContainerEnd(container) messages, and shows the cursor.
  3. If you want saved games to remember the contents of the container, add an SInventory Persistent Container to the item group. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Persistent Container) The items must be associated with item prefabs in a Resources folder, and the names cannot contain colons (':'). If you leave the Save Name field blank, it will use the container's GameObject name. If you need to debug persistent states when changing scenes or saving/loading games, tick Debug.

Setup Item Groups

Follow these steps to configure an item group (e.g., chest):

  1. Add an S-Inventory Item Group component to the item group.
    • Assign S-InventoryC#/S-InventoryC#/ItemGroupC# to the component.
    • If you will use the Dialogue System's trigger system, set Min Distance to 0.
    • Configure the items in Content with instances of prefabs from a Resources folder. Do not assign the prefabs directly. Instead, add them as child GameObjects of the item group, and assign those children. You can set them inactive.
  2. Add an SInventory Item Group Trigger to the item group. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Item Group Trigger) This trigger starts the S-Inventory item group GUI when the game object receives a specified trigger event. For example, you can add this and a static trigger collider to an area, and set the trigger to OnTriggerEnter. When the player enters the trigger area, it will open the item group. Or add a collider and a Usable component, and set the trigger to OnUse. The SInventory Item Group Trigger also sends OnItemGroupStart(itemGroup) and OnItemGroupEnd(itemGroup) messages, and shows the cursor.
  3. If you want saved games to remember the contents of the item group, add an SInventory Persistent Item Group to the item group. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Persistent Item Group) The items must be associated with item prefabs in a Resources folder, and the names cannot contain colons (':'). If you leave the Save Name field blank, it will use the item group's GameObject name. If you need to debug persistent states when changing scenes or saving/loading games, tick Debug.

Setup Vendors

Follow these steps to configure a vendor:

  1. Add an S-Inventory Vendor component to the vendor.
    • Assign S-InventoryC#/S-InventoryC#/VendorC# to the component.
    • If you will use the Dialogue System's trigger system, set Min Distance to 0.
    • Configure the items in For Sale with instances of prefabs from a Resources folder. Do not assign the prefabs directly. Instead, add them as child GameObjects of the item group, and assign those children. You can set them inactive.
    • Configure the Accepted Items with the names of items that the vendor will buy, such as "Health Potion".
  2. Add an SInventory Vendor Trigger to the vendor. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Vendor Trigger) This trigger starts the S-Inventory vendor when the game object receives a specified trigger event. For example, you can add this and a static trigger collider to an area, and set the trigger to OnTriggerEnter. When the player enters the trigger area, it will open the vendor. Or add a collider and a Usable component, and set the trigger to OnUse. The SInventory Vendor Trigger also sends OnVendorStart(vendor) and OnVendorEnd(vendor) messages, shows the cursor, and temporarily disables Bark On Idle if it exists on the actor.
  3. If you want saved games to remember the items the vendor has for sale, add an SInventory Persistent Vendor to the vendor. (Component > Dialogue System > Third Party > S-Inventory > S-Inventory Persistent Vendor) The items must be associated with item prefabs in a Resources folder, and the names cannot contain colons (':'). If you leave the Save Name field blank, it will use the vendor's GameObject name. If you need to debug persistent states when changing scenes or saving/loading games, tick Debug.

Setup Item Events

The SInventory Item Events component lets you hook up events to items. To run an item's events, call RunItemEvent, passing it the item type.

A typical configuration for running events on items on the skill bar is:

  1. Add SInventory Item Events to the player GameObject.
  2. Add elements for each item that you want to associate with an event.
    • Assign the item prefab to the element's Item field.
    • Assign events to the element's Item Event() event handler.
  3. Add an SInventory Dialogue Events component to the player GameObject.
  4. Assign SInventoryItemEvents.RunItemEvent to the On Used Skill Bar Item (Item) event handler.

Example Scene

The Example folder contains an example scene.

  • If you interact with the Dead Guard, you'll find a random amount of gold and a health potion. In the dialogue database, the gold is added with a Lua command while the health potion is added with a sequencer command. This is simply to demonstrate both methods. You will probably prefer to just choose one method, Lua or sequencer command, for consistency.
  • There is a chest that acts as an Item Group.
  • Sergeant Graves serves as a Vendor.

SInventory Dialogue Events

To add inspector-based Unity Events to S-Inventory activity, add an SInventory Dialogue Actor component to the scene (Dialogue System > Third Party > S-Inventory > S-Inventory Dialogue Events). You'll often put this on your player, but it can be on any GameObject in the scene.

This component also adds:

  • A SendSequencerMessage method that you can use to send a message to the sequencer if you want to make the sequencer wait for a specific S-Inventory event.
  • Sets a Dialogue System variable named "LastItem" to the name of the last item touched by S-Inventory.

Lua Functions

You can use these Lua functions in your dialogue entry Scripts and Conditions (or anywhere you use Lua):

Function Returns Description
GetCurrency(actor, currency) Number Gets the amount of a specified currency owned by an actor
SetCurrency(actor, currency, amount) (nothing) Sets the amount of a specified currency owned by an actor
AdjustCurrency(actor, currency, amount) (nothing) Increments/decrements the amount of a specified currency owned by an actor
GetItemAmount(actor, item) Number Gets the amount of a specified item owned by an actor in inventory or equipment
AddItem(actor, item, amount) (nothing) Adds an amount of items to an actor's inventory
RemoveItem(actor, item, amount) (nothing) Removes an amount of items from an actor's inventory or equipment.

Lua Examples

AdjustCurrency("Player", "Gold", 50);
numPotions = GetItemAmount("Player", "Health Potion");
RemoveItem("Player", "Wolf Skin", 5)

Sequencer Commands

You can use the following sequencer commands in your dialogue entries' Sequence fields to interface with S-Inventory.

AdjustCurrency()

Syntax: AdjustCurrency(subject, currency, amount)

Description: Adjusts an actor's currency.

Parameters:

  • subject: The name of a GameObject that has an Inventory Manager. You can also use 'this' or 'speaker' for the speaker, or 'listener' for the listener. Default: speaker
  • currency: The name of the currency.
  • amount: The amount to add (or subtract if negative).

Example:

  • AdjustCurrency(Player, Dollars, -20) (Remove 20 dollars from the player)

AddItem()

Syntax: AddItem(subject, item, amount)

Description: Adds an amount of items to an actor.

Parameters:

  • subject: The name of a GameObject that has an Inventory Manager. You can also use 'this' or 'speaker' for the speaker, or 'listener' for the listener. Default: speaker
  • item: The name of the item. This must be a prefab, and the prefab name must match the item name.
  • amount: The amount to add. If omitted, defaults to 1.

Example:

  • AddItem(Player, Health Potion, 1) (Give the player a health potion)

RemoveItem()

Syntax: RemoveItem(subject, item, [amount])

Description: Removes an amount of items to an actor.

Parameters:

  • subject: The name of a GameObject that has an Inventory Manager. You can also use 'this' or 'speaker' for the speaker, or 'listener' for the listener. Default: speaker
  • item: The name of the item. This must be a prefab, and the prefab name must match the item name.
  • amount: The amount to remove. If omitted, defaults to 1.

Example:

  • RemoveItem(Player, Health Potion, 3) (Takes away 3 health potions from the player)

More info: Sequences


<< Third Party Support | Realistic FPS Prefab / S-Inventory >>