Page 1 of 1

Conversation on the event before object destruction

Posted: Sat May 21, 2016 6:10 am
by mandi
Hello Tony,
I want my bosses to have often "last words", when, dying, they would say something. How to do that in an elegant way?
I mean, I have a rough solution now. I added a DS Trigger that is enabled on a state preceding the state my character dies, and I catch OnConversationEnded, which then pushes my character from pre-death to after-death. I know I can pause my game and try this way, but I do not want to do that - right now I do not pause the game during conversations (and have animated render texture portraits thanks to that), and if my player gets hit, his health is not affected (his in a special IsTalking state).

Also, what is the order of executions of an action in a DS Trigger? I mean, I want the same trigger to first alter quest state, then run conversation. Is it possible?

Best!

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 8:51 am
by Tony Li
Hi Artur,

The order of events in Dialogue System Trigger is documented here:
  • Set Quest State
  • Run Lua Code
  • Play Sequence
  • Show Alert
  • Send Messages
  • Bark
  • Start Conversation
So the Dialogue Trigger should alter the quest state first, then run the conversation.

Is this not working the way you expect? Are you trying to do something extra, such as temporarily making all of the other enemies go into an idle state instead of continuing to attack?

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 10:11 am
by mandi
Hello Tony,
thank you for clearing that up. I inspected the DS source code and made a solution that is working (I think - I need to test it right now).

My other enemies keep attacking when the hero is talking, but he is invincible then (this is a little bit counter-intuitive, I am still wondering on pushing then into idle - if I guess right that should be pretty simple, using OnConversationStart and actor.tag == "Player" as the condition, for instance?).

Thank you!
Best
A.

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 10:32 am
by Tony Li
OnConversationStart is only sent to the Dialogue Manager and conversation participants. I suggest writing a couple scripts to inform other characters:

Add this to the player:

Code: Select all

public class IdleManager : MonoBehaviour {

    public event System.Action IdleEvent = new delegate{};
    public event System.Action ResumeEvent = new delegate();
    
    public void Idle() {
        IdleEvent();
    }
    
    public static void Resume() {
        ResumeEvent();
    }
}
Then add a Dialogue System Events component to the player. In the On Conversation Start event, call IdleManager.Idle. In the On Conversation End event, call IdleManager.Resume.

Add this script to your characters:

Code: Select all

public class IdleHandler : MonoBehaviour {

    private bool started = false;

    void Start() {
        started = true;
        Register();
    }
    
    void OnEnable() {
        if (started) Register();
    }
    
    void OnDisable() {
        Unregister();
    }
    
    void Register() {
        Unregister(); // To make sure we don't register twice.
        var idleManager.FindObjectOfType<IdleManager>();
        if (idleManager != null) {
            idleManager.IdleEvent += OnIdle;
            idleManager.ResumeEvent += OnResume;
        }
    }
    
    void Unregister() {
        var idleManager.FindObjectOfType<IdleManager>();
        if (idleManager != null) {
            idleManager.IdleEvent -= OnIdle;
            idleManager.ResumeEvent -= OnResume;
        }
    }
    
    void OnIdle() {
        // Your code here to idle. Maybe check if the character is 
        // DialogueManager.CurrentConversant and skip this if so.
    }
    
    void OnResume() {
        // Your code here to resume.
    }
}
I just typed this into the reply, so it might have typos.

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 11:13 am
by mandi
Tony,
thank you very much for the elaborate answer! I have an Enemy Manager that has all enemies registered at the start of the game - I think I could assign methods to the delegates there (I would then avoid finding IdleManager for each character). What do you think?
Best!

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 11:35 am
by Tony Li
Sounds good! The IdleManager was just an example.

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 1:00 pm
by mandi
That's what I thought. Many thanks, Tony!
Best

Re: Conversation on the event before object destruction

Posted: Sat May 21, 2016 3:06 pm
by Tony Li
Glad to help!