Page 1 of 1

Using a Dialogue System Trigger to switch player components on/off

Posted: Sat Aug 31, 2019 9:38 am
by lostmushroom
Hey, I'm trying to figure something out.

I have a Corgi character with 2 "Jump" components - one is a single jump and the other a double jump. I also have a "Double Jump Item", which is actually just an NPC.

I would like to use a Dialogue System Trigger (on conversation end) to Enable/Disable the jump components. But I'm aware that it won't work to have the trigger pointing to the player prefab, since it instantiates a copy of the prefab.

I guess the solution would be to have the trigger within the player prefab. But I'm not quite sure the best way to set this up, since it needs to only work with this particular NPC. Any help is appreciated (:

Re: Using a Dialogue System Trigger to switch player components on/off

Posted: Sat Aug 31, 2019 11:48 am
by Tony Li
Please correct me if I'm misunderstanding you. Do you want to enable the character's double jump ability after talking to the actor "Double Jump Item"?

If so, then since the player is instantiated at runtime, a good solution would be to use a sequencer command. Try this: In your player prefab, disable the double jump ability component. In the conversation, use this Sequence on the one of the NPC's nodes:

Code: Select all

SetEnabled(CharacterDoubleJump,true,listener); {{default}}
where CharacterDoubleJump is the name of the ability. I'm assuming that, since the NPC is the speaker (i.e., node's actor), the player is the listener (i.e., node's conversant). I included {{default}} to make sure the node also plays the default sequence. This is optional.

Alternatively, keep the double jump ability component enabled, but keep the Ability Permitted checkbox unticked. Write a custom sequencer command -- perhaps called PermitAbility() -- to call the ability's PermitAbility() method. Then you'd set the node's Sequence to something like:

Code: Select all

PermitAbility(CharacterDoubleJump,true,listener); {{default}}
If you're using the save system, you might also want to save the fact that the player has talked to the NPC and acquired double jump. Save this in a Dialogue System variable. Add a Dialogue System Trigger to the player prefab. Set it to OnStart. Set the Condition to check the variable. Set Actions > OnExecute() event to tick the AbilityPermitted checkbox.

Re: Using a Dialogue System Trigger to switch player components on/off

Posted: Sat Aug 31, 2019 11:57 am
by Tony Li
Here's the PermitAbility() sequencer command. I'll also include it in the next Corgi integration package.

SequencerCommandPermitAbility.cs

Code: Select all

using UnityEngine;
using MoreMountains.CorgiEngine;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    public class SequencerCommandPermitAbility : SequencerCommand
    { 

        public void Awake()
        {
            var abilityName = GetParameter(0);
            var value = GetParameterAsBool(1);
            var subject = GetSubject(2, speaker);
            var character = (subject != null) ? subject.GetComponent<Character>() : null;
            var ability = (character != null) ? subject.GetComponent(abilityName) as CharacterAbility : null;
            if (character == null)
            {
                if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Sequencer: PermitAbility(" + GetParameters() + "): Can't find subject or Character on subject.");
            }
            else if (ability == null)
            {
                if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Sequencer: PermitAbility(" + GetParameters() + "): Can't find ability " + abilityName + " on " + subject + ".", subject);
            }
            else
            {
                if (DialogueDebug.logInfo) Debug.Log("Dialogue System: Sequencer: PermitAbility(" + ability + ", " + value + ", " + subject + ")", subject);
                ability.PermitAbility(value);
            }
            Stop();
        }
    }
}

Re: Using a Dialogue System Trigger to switch player components on/off

Posted: Sat Aug 31, 2019 1:51 pm
by lostmushroom
Thanks so much, this looks like exactly what I need.

Re: Using a Dialogue System Trigger to switch player components on/off

Posted: Sat Aug 31, 2019 2:06 pm
by Tony Li
Happy to help!