How to make Converstation dialque link to player health

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Niozdude
Posts: 2
Joined: Fri Feb 21, 2025 6:22 am

How to make Converstation dialque link to player health

Post by Niozdude »

It's my first time using the tool I think I have some of the basic stuff figured out im trying to make a system
where a dialogue conversation triggers based on the player's hp

the database right now is set so that it's just a basic conversation the player doesn't have dialogue options or anything like a notification window with an NPC going , " hey be careful your hp is low " dialogue box appearing on the screen when the player touches a trigger.

I want to set it so the conversation automatically pops up based on reading the player's hp , but I don't know how to go about doing it anyone can please help I've been stuck on this for a while :oops:
User avatar
Tony Li
Posts: 23256
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to make Converstation dialque link to player health

Post by Tony Li »

Hi,

It's probably best to start the conversation from C# code using DialogueManager.StartConversation() in this case. Here are three example ways you could do it:

1. In a TakeDamage() method:

Code: Select all

public void TakeDamage(int damage)
{
    bool hpBecameLow = (hp > Threshold) && (hp - damage <= Threshold);
    hp -= damage;
    if (hpBecameLow) DialogueManager.StartConversation("Low HP Conversation");
}
Then cause damage to the player by calling the TakeDamage() method. I glossed over some values such as Threshold, but you should get the idea.


2. Or make HP a C# property:

Code: Select all

private int hp;
public int HP
{
    get 
    {
        return hp;
    }
    set
    {
        bool hpBecameLow = (hp > Threshold) && (value <= Threshold);
        hp = value;
        if (hpBecameLow) DialogueManager.StartConversation("Low HP Conversation");
    }
}
3. Or a C# method property that invokes a C# event:

2. Or make HP a C# property:

Code: Select all

public System.Action<int, int> HPChanged = null;

private int hp;
public int HP
{
    get 
    {
        return hp;
    }
    set
    {
        int oldValue = hp;
        hp = value;
        HPChanged?.Invoke(oldValue, value);
    }
}

...

void OnEnable() => HPChanged += OnHPChanged;
void OnDisable() => HPChanged -= OnHPChanged;

void OnHPChanged(int oldHP, int newHP)
{
    bool hpBecameLow = (oldHP > Threshold) && (newHP <= Threshold);
    if (hpBecameLow) DialogueManager.StartConversation("Low HP Conversation");
}
Niozdude
Posts: 2
Joined: Fri Feb 21, 2025 6:22 am

Re: How to make Converstation dialque link to player health

Post by Niozdude »

thank you for the reply ill test this out
User avatar
Tony Li
Posts: 23256
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to make Converstation dialque link to player health

Post by Tony Li »

Glad to help!
Post Reply