Opsive Ultimate Inventory System Support

This page describes how to set up the Dialogue System with Opsive's Ultimate Inventory System. (Ultimate Inventory System is required.)

Ultimate Inventory System copyright © Opsive.

Overview

This integration for Opsive's Ultimate Inventory System (UIS):

  • Gives you the ability to check and manipulate inventories and currency owners.
  • Allows you to open a vendor's shop during conversations.
  • Saves inventory and currency data in saved games and across scene changes.

Setup

Enable Integration

To enable Dialogue System integration, select menu item Tools → Opsive → Ultimate Inventory System → Integrations Manager. Scroll down to Dialogue System for Unity, and click the Integration button. This page will then contain the link for the Dialogue System integration package. Download the package and import it.

Demo Scene

The demo scene is in Pixel Crushers ► Dialogue System ► Third Party Support ► Opsive UIS Support ► UIS DS Demo. It is a copy of the original UIS demo with these changes:

  • The Guide NPC plays a Dialogue System conversation in which the player can obtain a weapon.
  • The ShopKeeper NPC plays a Dialogue System conversation that offers an option to show his shop interface.
  • The Demo uses the Dialogue System's Save System, which ties into UIS's save system to get and set inventory and currency data.

Setup

  1. On the UIS Game GameObject, Untick the Inventory System Manager component's Dont Destroy On Load checkbox. This will prevent duplicate copies when loading saved games.
  2. On your player inventory GameObject, untick the Inventory Saver component's Load On Start. Make sure the player GameObject has the exact same name in all scenes, as the Inventory Saver's unique expanded key value is partially based on the GameObject name. If you specify a Key value, make sure it's the same value on all instances of the player in all scenes.
    • If you want to save the slot positions of items, add an Inventory Grid Saver to the Inventory Grid component in the UI.
  3. Add a Dialogue Manager GameObject by adding the prefab in Plugins ► Pixel Crushers ► Dialogue System ► Prefabs.
    • Add a UIS Lua component.
  4. Set up the Dialogue System's Save System. Then add a UIS Saver component. If you want to use an AutoSaveLoad component, see Auto Save Load Note.
    • Alternative: If you want to use UIS's save system as the primary save system, do not add a UIS Saver component. Instead, add a Pixel Crushers To UIS Saver component.
  5. Optional (for testing only): If you want to connect to the Pixel Crushers Save System's test menu script, add a Redirect Save Load Button To Test Menu component to the UIS Inventory System Canvas > Main Menu > Save/Load button GameObject. Then assign the UIS Save Menu GameObject to it. Note: This script is not intended for release builds. Use it only for quick testing.

Auto Save Load Note

If you want to use the save system's Auto Save Load component: UIS's Savers can take one frame to register themselves. To prevent Auto Save Load from trying to load before UIS's Savers have registered themselves, keep the Auto Save Load component disabled at design time, and enable it after one frame. If you don't want to do any scripting, you can use a Timed Event component to enable it after 1 frame.

Setup

If you are also using an Opsive Character Controller asset:

  1. Add UIS to Scripting Define Symbols. (See Opsive Character Controllers Support.)
  2. Import and set up the Opsive Character Controllers Support integration package (available on Opsive's website).
  3. Add a UCC Saver component to your player GameObject, and untick Save Inventory. The UIS integration will take care of saving inventory, so UCC Saver shouldn't also save inventory.
  4. Make sure your player or inventory GameObject has an Inventory Bridge Saver component but do not add an Inventory Saver.

Using the Integration

  • To work with inventories and currencies in conversations, use the integration's Lua Functions.
  • To open a vendor's shop interface in a conversation, use the integration's OpenShop() Sequencer Commands.

Lua Functions

You can use the Lua functions below in your dialogue entry Scripts and Conditions, or anywhere you use Lua. Note the exact number and type of parameters required for each function. To enable these Lua functions, add a UIS Lua component to your Dialogue Manager. In the '...' Lua wizard dropdowns, these functions are available in Custom > UIS.

uisGetItemAmount( itemName:string, inventoryName:string )

  • Returns amount of an item in a specified inventory. If inventoryName is blank, use the player's inventory.
  • Example: Variable["Num_Iron_Swords"] = uisGetItemAmount("Iron Sword", "")

uisAddItem( itemName:string, amount:number, inventoryName:string, itemCollectionName:string )

  • Adds an amount of an item to an inventory, optionally specifying an item collection in that inventory. If inventoryName is blank, use the player's inventory. If itemCollectionName is blank, don't add to a specific item collection.
  • Example: uisAddItem("Iron Sword", 1, "", "")

uisRemoveItem( itemName:string, amount:number, inventoryName:string, itemCollectionName:string )

  • Removes an amount of an item from an inventory, optionally specifying an item collection in that inventory. If inventoryName is blank, use the player's inventory. If itemCollectionName is blank, don't remove from a specific item collection.
  • Example: uisRemoveItem("Iron Sword", 1, "", "")

uisGetCurrencyAmount( currencyName:string, currencyOwnerName:string )

  • Returns amount of a currency in a specified currency owner. If currencyOwnerName is blank, use the player's inventory.
  • Example: Variable["Gold"] = uisGetCurrencyAmount("Gold", "")

uisAddCurrency( currencyName:string, amount:number, currencyOwnerName:string )

  • Adds an amount of currency to a currency owner. If currencyOwnerName is blank, use the player's inventory.
  • Example: uisAddCurrency("Gold", 50, "")

uisRemoveCurrency( currencyName:string, amount:number, currencyOwnerName:string )

  • Removes an amount of currency from a currency owner. If currencyOwnerName is blank, use the player's inventory.
  • Example: uisRemoveCurrency("Gold", 50, "")

Sequencer Commands

The integration adds these sequencer commands:

OpenShop([shop], [shopMenu], [playerInventory])

Typically used in NPC's Sequence. Opens shop.

Parameters:

  • shop: GameObject with ShopBase and ShopMenuOpener components. Default: speaker.
  • shopMenu: GameObject with ShopMenu. Default: ShopMenu assigned to shop GameObject.
  • playerInventory: GameObject with player's Inventory. Default: listener.

Example: OpenShop()

OpenCrafting([crafter], [craftMenu], [playerInventory])

Typically used in NPC's Sequence. Opens crafting menu.

Parameters:

  • crafter: GameObject with Crafter component. Default: speaker.
  • shopMenu: GameObject with CraftingMenu. Default: CraftingMenu assigned to crafter GameObject.
  • playerInventory: GameObject with player's Inventory. Default: listener.

Example: OpenCrafting()

Save System

There are two ways to connect the UIS and Dialogue System save systems:

  1. Allow the Pixel Crushers Dialogue System Save System to control saves. This lets you use your choice of saved game data storer (e.g., Disk Saved Game Data Storer, Player Prefs Saved Game Data Storer, etc.) to store saved game data wherever you want. This is the method described above in Setup.
  2. Or allow UIS's Save System Manager to control saves.

To tie UIS into the Pixel Crushers Save System:

  • Set up the Dialogue System's Save System.
  • Add a UIS Saver component to the same GameObject as the Pixel Crushers Save System component.
  • Untick the Inventory System Manager's Dont Destroy On Load Checkbox. This will prevent it from creating a duplicate when loading new scenes.

Alternatively, to tie the Pixel Crushers Save System into UIS's Save System Manager:

  • Set up the Dialogue System's Save System.
  • Add a Pixel Crushers To UIS Saver component to the same GameObject as the Pixel Crushers Save System component.

<< Third Party Integration