Inventory & Dialogue System Integration

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Inventory & Dialogue System Integration

Post by rloft123 »

So part of my planned game design is to pick up items in my game, and have that interact with my dialogue system. For example: Dog NPC wants a bone (have a conversation check to see if player.hasBone == true), give the dog the bone if you have it and the quest completes. That part is simple enough in theory, but I would like the ability for the dialogue system to interact with my inventory. The simple solution is the OnUse just set through lua the player boolean hasBone to true, and destroy the bone object on interaction, but that doesn't play well with an inventory system.

That solution doesn't add the bone to my existing inventory system where before it would add any item on trigger when I walked over it, however I want to change over to using a button interaction when clicking the object to add it to my inventory using the Proximity Selector instead (it'll be a detective game where I want to intentionally pick things up, not just run over them)

I have a script for item pick up using OnTriggerEnter2D from before, and I'd like to reuse that code, could this be done via lua or something when I interact with the object? Thanks.
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Inventory & Dialogue System Integration

Post by Tony Li »

Hi,

It's probably better to allow your Dialogue System conversations to directly access the player's inventory. That way if the player picks up a bone and later drops it, the conversation will know that the player doesn't have a bone.

If you're using one of the inventory system assets for which the Dialogue System has an integration, such as Ultimate Inventory System or Inventory Engine, you can use the integration's built-in Lua functions.

Otherwise you can expose your own inventory system's C# methods to Lua so you can use them in your conversation's Conditions and Script fields. See: Connect Your Own Code to Lua.
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Re: Inventory & Dialogue System Integration

Post by rloft123 »

So what I have in my Item class is a PickUp function, and I know you can trigger a function with that link you sent, but I was curious if there was a way to go the opposite direction, where my code calls the DialogueManager lua environment to change a variable in there instead.

For example in some pseudocode:

//this method called when player is in the box collider of the item on the ground and hits 'E'
pickup(){

//code that picks up the item and adds it to the inventory

//Here I want to call the Lua environment to say that the item is now in the player inventory, and to set the player.hasDogBone variable to true

//destroy the object

}
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Inventory & Dialogue System Integration

Post by Tony Li »

Hi,

Sure! You can use DialogueLua.SetVariable().
rloft123
Posts: 22
Joined: Wed May 25, 2022 8:11 pm

Re: Inventory & Dialogue System Integration

Post by rloft123 »

Awesome, I'll look at that. Thank you for all the help you've given me. Glad to see Pixel Crushers have solid support
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Inventory & Dialogue System Integration

Post by Tony Li »

Happy to help!
Post Reply