Page 1 of 1

Add Item via script

Posted: Sat Oct 15, 2022 3:12 pm
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!

Re: Add Item via script

Posted: Sat Oct 15, 2022 4:20 pm
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.

Re: Add Item via script

Posted: Sun Oct 16, 2022 7:12 am
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 :)

Re: Add Item via script

Posted: Sun Oct 16, 2022 11:01 am
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);

Re: Add Item via script

Posted: Sun Feb 12, 2023 12:20 pm
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.

Re: Add Item via script

Posted: Sun Feb 12, 2023 1:09 pm
by Tony Li
Hi,

What about:

Code: Select all

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