How to block player's path?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Mastodon
Posts: 3
Joined: Fri Jan 05, 2024 8:24 pm

How to block player's path?

Post by Mastodon »

Hello, I was curious if anyone could help me. I wanted to know how to block the player from going to any scene if they have to do something first. Like talking to an NPC.

For example, if the player tries to go to that area a conversation will show up saying "I should talk to X first". I have all of the scene portals set up for my game so far so now it's just about setting restrictions.
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to block player's path?

Post by Tony Li »

Hi,

You could use a subclass of ScenePortal like this:

ConditionalScenePortal.cs

Code: Select all

using PixelCrushers;
using PixelCrushers.DialogueSystem;

public class ConditionalScenePortal : ScenePortal
{
    public Condition condition;
    [ConversationPopup(true)] public string conditionsUnmetConversation;

    public override void UsePortal()
    {
        if (condition.IsTrue(null))
        {
            base.UsePortal();
        }
        else
        {
            DialogueManager.StartConversation(conditionsUnmetConversation);
        }
    }
}
It adds a Condition section and a Conditions Umnet Conversation.

Then set the Condition section. For example, use the Lua Conditions subsection to check if a variable is true:

Code: Select all

Variable["Talked_To_NPC_X"] == true
In the conversation with NPC X, set the variable true.

If the variable is true when the player enters the Scene Portal, it will go to the next scene. Otherwise it will play the Conditions Unmet Conversation.
Mastodon
Posts: 3
Joined: Fri Jan 05, 2024 8:24 pm

Re: How to block player's path?

Post by Mastodon »

Awesome it works perfectly! Thank you so much for the help! :D
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to block player's path?

Post by Tony Li »

Glad to help!
Post Reply