Add Item via script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
will_888
Posts: 26
Joined: Mon Feb 07, 2022 4:09 am

Add Item via script

Post by will_888 »

Hello!
I'm creating a Battle System with a character, and I would like to have this interact with the Dialogue System.
At the end of the Battle, I have a loot screen.

I would like to have an interaction via script where after earning an "X" loot, the Dialogue System adds an "X" Item to the Database.

How can I make my script and the Dialogue System interact to obtain this behaviour? Thank you so much in advance!
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Add Item via script

Post by Tony Li »

Hi,

Do you want to add an item to the dialogue database's Item[] table, or to your own inventory system that's separate from the Dialogue System? I'll assume the latter, since the dialogue database's Item[] table isn't much of an inventory solution.

You'll need a C# method to add an item to your inventory system. Let's say the method is:

Code: Select all

public void AddItem(string itemName)
{
    // Your code here that adds the item to your inventory system
}
Then just register that method with Lua (video tutorial) and use it in a dialogue entry's Script field.
will_888
Posts: 26
Joined: Mon Feb 07, 2022 4:09 am

Re: Add Item via script

Post by will_888 »

>Do you want to add an item to the dialogue database's Item[] table

This is my preferred solution, as I want the Battle System to drop something, and I want that something to be inserted in the Item[] table. Then, I'm using the Item as a condition for the resolution of a quest (having a dialogue that checks that you have this item and if yes, the Quest is complete).

Does this make sense? Are there better practices to do this? Thanks :)
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Add Item via script

Post by Tony Li »

Hi,

In a dialogue entry's Script field, add the item like this:

Code: Select all

Item["Maguffin"] = { Name="Maguffin", Is_Item=true }
In C#, you can use DialogueLua:

Code: Select all

DialogueLua.SetItemField("Maguffin", "Name", "Maguffin");
DialogueLua.SetItemField("Maguffin", "Is Item", true);
will_888
Posts: 26
Joined: Mon Feb 07, 2022 4:09 am

Re: Add Item via script

Post by will_888 »

I forgot to thank you in the past for this! It worked and was very useful.
Still, I've got a further question: what if instead of Items I want to manipulate Number variables?

Like this:
I'm in a turn-based battle.
At the end of the battle, the enemy is defeated.
I want the Dialogue System to increase a variable in the dialogues called DefeatedEnemies

I'm able to Set the Variable as of now, but not increasing.
Can I get any help on this? Thanks.
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Add Item via script

Post by Tony Li »

Hi,

What about:

Code: Select all

DialogueLua.SetVariable("DefeatedEnemies", 1 + DialogueLua.GetVariable("DefeatedEnemies").asInt);
Post Reply