Page 1 of 1
If() (NPC has available dialogue)
Posted: Mon May 21, 2018 7:00 pm
by nathanj
Hi Tony
I would like to set up my NPCs so that if they have an available dialogue (trying to think of a better way to describe this, if a node is available) they activate an IK script I have attached to the NPC - the script is a basic IK "Look At" script that is triggered through a bool.
I would like it that if a given NPC has available dialogue they look at the player, but if they do not have any available dialogue they do not look at the NPC.
You mind pointing me in where I would find this in the documentation?
Thanks again,
Nathan
Re: If() (NPC has available dialogue)
Posted: Mon May 21, 2018 8:54 pm
by Tony Li
Hi Nathan,
It'll require a little scripting or PlayMaker-ing.
The function
DialogueManager.ConversationHasValidEntry() will tell you whether any nodes linked from the START node in a conversation are currently valid.
The PlayMaker support package has an equivalent
Does Conversation Have Valid Entries action.
Here's an example scene:
LookIfHasConversation_2018-05-21.unitypackage
Since the example NPC doesn't have IK, it just rotates the NPC to face the player.
The example uses this script:
Code: Select all
using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(ConversationTrigger))]
public class LookIfHasConversation : MonoBehaviour
{
IEnumerator Start()
{
var conversationTrigger = GetComponent<ConversationTrigger>();
var player = GameObject.FindGameObjectWithTag("Player").transform;
var oneSecond = new WaitForSeconds(1);
while (true)
{
if (DialogueManager.ConversationHasValidEntry(conversationTrigger.conversation))
{
transform.LookAt(player);
}
yield return oneSecond;
}
}
}
Re: If() (NPC has available dialogue)
Posted: Mon May 21, 2018 11:14 pm
by nathanj
Totally worked!
Thanks again
Nathan
Re: If() (NPC has available dialogue)
Posted: Tue May 22, 2018 12:39 am
by nathanj
One thing, incase anyone else tries this.
I was getting this error initially:
Dialogue System: Lua code 'return CurrentQuestState("CuttingStoneMarker") ~= "success"' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'
UnityEngine.Debug:LogError(Object)
PixelCrushers.DialogueSystem.Lua:RunRaw(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Lua:Run(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.Lua:IsTrue(String, Boolean, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinksAtPriority(ConditionPriority, DialogueEntry, List`1, List`1, List`1, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinksAtPriority(ConditionPriority, DialogueEntry, List`1, List`1, List`1, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinks(DialogueEntry, List`1, List`1, List`1, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:GetState(DialogueEntry, Boolean, Boolean, Boolean)
PixelCrushers.DialogueSystem.ConversationModel:.ctor(DialogueDatabase, String, Transform, Transform, Boolean, IsDialogueEntryValidDelegate, Int32, Boolean, Boolean)
PixelCrushers.DialogueSystem.DialogueSystemController:ConversationHasValidEntry(String, Transform, Transform)
PixelCrushers.DialogueSystem.DialogueManager:ConversationHasValidEntry(String)
<Start>c__Iterator0:MoveNext() (at Assets/Dialogue System Examples/Look If Has Conversation Example/LookIfHasConversation.cs:21)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
what was happening is the NPCs were being enabled before the database was, and so their searches were turning out null.
The simple fix is to move the yield return new WaitForSeconds(); above, like:
Code: Select all
while (true)
{
yield return oneSecond;
if (DialogueManager.ConversationHasValidEntry(conversationTrigger.conversation))
{
transform.LookAt(player);
}
}
Nathan
Re: If() (NPC has available dialogue)
Posted: Tue May 22, 2018 9:24 am
by Tony Li
Good catch!