I want to make an NPC aware that I've attacked them

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
maitlanr
Posts: 2
Joined: Fri Jan 29, 2021 8:38 am

I want to make an NPC aware that I've attacked them

Post by maitlanr »

and they say something like "not cool" or "stop killing me"

I have very little coding understanding and really don't even know where to begin with this issue...

I'm fairly certain this may be something like an event? but the whole event thing I'm very not sure of what's going...

Sorry if this is an entirely worthless ask...
but all the same...thank you everyone for even the most cursory of thoughts on this issue.
User avatar
Tony Li
Posts: 22166
Joined: Thu Jul 18, 2013 1:27 pm

Re: I want to make an NPC aware that I've attacked them

Post by Tony Li »

Hi,

That's just the thing barks are for.

First, make sure your NPC is set up to show barks -- that is, it has a bark UI.

Then the NPC needs a way to know when it has been attacked. That's outside the scope of the Dialogue System. It may require scripting. For example, say your NPC has a Health script with a method named "TakeDamage". Example:

Code: Select all

public class Health : MonoBehaviour
{
    public int hp;
    
    public void TakeDamage(int damage)
    {
        hp -= damage;
    }
}
You could expand the TakeDamage method to also bark a string:

Code: Select all

    public void TakeDamage(int damage)
    {
        hp -= damage;
        DialogueManager.BarkString("stop killing me", this.transform);
    }
(Or use the DialogueManager.Bark method to bark a randomly-chosen line from a conversation.)

Sorry I can't be more specific, but it depends on the specifics of your attack system.
maitlanr
Posts: 2
Joined: Fri Jan 29, 2021 8:38 am

Re: I want to make an NPC aware that I've attacked them

Post by maitlanr »

thank you so much for the reply and this seems like i could easily do it....but am about to go walk the dog...

and this may be really obvious but can you load a lot of different statement options into a single barkstring or how would i make the script call barks that come from a conversation? or is that just how it works....


i should probably try this out before asking but i'm just so thrilled you responded

i sorta left this topic as a cry for help not thinking it would garner a response...

your product is absolutely fantastic and has allowed me to figure out the nature of some of this stuff in unity / scripting through the commands and sequencers and i have a damn blast with the variables and conditions


I will follow up with how this goes.
User avatar
Tony Li
Posts: 22166
Joined: Thu Jul 18, 2013 1:27 pm

Re: I want to make an NPC aware that I've attacked them

Post by Tony Li »

Hi,

Glad to help!

You can bark from a conversation or a string.

To bark from a string, use DialogueManager.BarkString().

To bark from a conversation, use DialogueManager.Bark(). Example:

Code: Select all

DialogueManager.Bark("Combat Barks", someNPC);
Say your Combat Barks conversation looks like this:

combatBarks.png
combatBarks.png (19.16 KiB) Viewed 57 times

where "What a weak shot!" checks if the NPC's HP is 90%+ and the other two check if the HP is < 90%.

If the NPC's HP is < 90%, DialogueManager.Bark() will choose randomly between the second or third nodes.
Post Reply