Page 1 of 1

Dialogue Response Item with dynamic labels (XP, Reward, New weapon)

Posted: Fri Apr 26, 2024 5:26 am
by flyingv
Hi!

I need a similar response system as in the attachment below (+5000 money, +1 weapon). Is there any built-in functionality?
Thanks.

Re: Dialogue Response Item with dynamic labels (XP, Reward, New weapon)

Posted: Fri Apr 26, 2024 8:33 am
by Tony Li
Hi,

There's built-in functionality for everything except the reward images. This includes Ruby's portrait, name, and text at the top, the choices at the bottom, and the ability to add the reward to the player using each choice's Script field. However, the Dialogue System is designed to let you extend its functionality. Here are my recommendations:

1. Add two new fields to the dialogue entry template (see Templates): reward amount and reward icon.

2. In your reward dialogue entries, set the reward amount (e.g., "1x") and reward icon as an image name (e.g., "kevlar_vest").

3. Make a subclass of StandardUIResponseButton that also supports two extra UI elements: reward amount and reward image. Override the SetFormattedText method to look up the dialogue entry's reward amount and reward icon, and set the UI elements accordingly.

Re: Dialogue Response Item with dynamic labels (XP, Reward, New weapon)

Posted: Fri Apr 26, 2024 2:56 pm
by flyingv
Thanks for advices. I'll try to do that)

Re: Dialogue Response Item with dynamic labels (XP, Reward, New weapon)

Posted: Fri Apr 26, 2024 3:08 pm
by Tony Li
Glad to help! If you have questions about it, let me know.

Re: Dialogue Response Item with dynamic labels (XP, Reward, New weapon)

Posted: Wed May 08, 2024 3:48 am
by flyingv
What if I need to output several reward items on response item? For example, 15 XP AND 100 amount of ammo? (See attachment)

Is it possible to create a new array or list field? Something like this: [{RewardName: "Money", RewardAmount: 100}, [{RewardName: "XP", RewardAmount: 15}]

Re: Dialogue Response Item with dynamic labels (XP, Reward, New weapon)

Posted: Wed May 08, 2024 7:56 am
by Tony Li
Hi,

You can do that, but you'd need to parse it yourself.

If you can separate the info with semicolons or some other unique character, you can use string.Split(';') to split the info on that character. Otherwise you could write it in JSON format such as:

Code: Select all

{Rewards:[ {Name:"Money", Amount:100}, {Name:"XP", Amount:15} ]}
and then use JsonUtility:

Code: Select all

[System.Serializable]
public class Reward
{
    public string Name;
    public int Amount;
}

[System.Serializable]
public class Rewards
{
    public List<Reward> Rewards;
}

void OnConversationLine(Subtitle subtitle)
{
    var s = Field.LookupValue(subtitle.fields, "Rewards");
    if (string.IsNullOrEmpty(s)) return;
    Rewards rewards = JsonUtility.FromJson<Rewards>(s);
    // Show rewards here.
}