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

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
flyingv
Posts: 6
Joined: Wed Apr 10, 2024 4:03 am

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

Post 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.
Attachments
vz62vijh0s761.jpg
vz62vijh0s761.jpg (134.78 KiB) Viewed 67 times
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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.
flyingv
Posts: 6
Joined: Wed Apr 10, 2024 4:03 am

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

Post by flyingv »

Thanks for advices. I'll try to do that)
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Glad to help! If you have questions about it, let me know.
flyingv
Posts: 6
Joined: Wed Apr 10, 2024 4:03 am

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

Post 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}]
Attachments
Screenshot_2024-02-23-13-38-46-28_60a1804e398c12353b31b7cc7cc72187.jpg
Screenshot_2024-02-23-13-38-46-28_60a1804e398c12353b31b7cc7cc72187.jpg (170.44 KiB) Viewed 11 times
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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.
}
Post Reply