Page 1 of 1

Trigger on Death [SOLVED]

Posted: Sat Dec 21, 2019 8:20 am
by mschoenhals
Hi,
In my game, enemies aren't destroyed or disabled on death. They lie there until the player moves into another scene. How can I trigger a counter for killing enemies if I'm not using destroy or disable for defeating enemies?

Re: Trigger on Death

Posted: Sat Dec 21, 2019 8:47 am
by Tony Li
Hi,

There are still several ways you can increment a counter. One of the easiest is to send a message using Quest Machine's message system.

1. Add a counter to your quest (e.g., "orcsKilled"). Set Value Mode to Messages. Add a message such as "Killed" + "Orc".

2. Optionally add some HUD text that shows the counter value, such as "{#orcsKilled}/{>#orcsKilled}". You can use the Quest Reference window to copy these counter tags to the clipboard so you don't have to type them manually.

3. Add a QuestControl component to your enemy. If your enemy has a UnityEvent that's invoked when it's killed, such as OnDeath(), configure this event to call QuestControl.SendToQuestMachine with the message that increments the counter, such as "Killed:Orc".

4. If you don't have a UnityEvent, you can skip #3. Instead, call MessageSystem.SendMessage() in code:

Code: Select all

PixelCrushers.MessageSystem.SendMessage(this, "Killed", "Orc");

Re: Trigger on Death

Posted: Sun Dec 22, 2019 5:04 pm
by mschoenhals
So in steps 3 and 4, is this hard coded in? Is there a way to do it where I wouldn't have to change the code every time I want to have a quest that involves killing a particular type of enemy?

Re: Trigger on Death

Posted: Sun Dec 22, 2019 5:43 pm
by Tony Li
It doesn't have to be hard-coded. If you have script that identifies the enemy type, you can pass that instead. Something like:

Code: Select all

PixelCrushers.MessageSystem.SendMessage(this, "Killed", GetComponent<Enemy>().EnemyName);
or even pass the GameObject name if that identifies the enemy type.

If you're using Quest Machine's procedural quest generation, you can define an EntityType asset, add a QuestEntity component to the enemy, and assign the EntityType asset to it. Then you can send the entity type:

Code: Select all

PixelCrushers.MessageSystem.SendMessage(this, "Killed", GetComponent<QuestEntity>().entityType.name);

Re: Trigger on Death

Posted: Sun Dec 22, 2019 6:51 pm
by mschoenhals
Got it!
Turns out that I do have an On Die() event that I could use to track the kill count. I added the Quest Control and added it to the Event and it worked perfectly!
Thanks for your help,
Mike

Re: Trigger on Death [SOLVED]

Posted: Sun Dec 22, 2019 7:39 pm
by Tony Li
Glad to help!