Trying to make a password puzzle

My goal is to make a script that can check when a PC speaks a specific phrase or password to gain entry to a hidden area. I’m not very good at scripting, but my research suggests I should be using the OnPlayerChat event, is that correct?

My process was to set a trigger that would set a local int on the player upon entering the trigger, signaling that the player was in the right spot to speak the password. If the player speaks the password while the int is equal to 1, teleport the player to the waypoint. If the int is equal to 0 (meaning the player is not in the correct area), do nothing.]

Since I am not a coder I tried to use the script generator to build the basic structure and then copy/paste in the right functions, but the script does not work so obviously I haven’t set it up right. This script also needs to cover multiple different passwords for different areas throughout the module since the only way I know how to perform such a puzzle is with the single OnPlayerChat event, so I tried to do an else if statement for a second puzzle to test with.

// Put this script OnPlayerChat event under module properties.


// Clears all actions and jumps the caller to the provided object.
// (Useful when this needs to be delayed.)
void ClearAndJumpToObject(object oDestination);
void ClearAndJumpToObject(object oDestination)
{
    ClearAllActions();
    JumpToObject(oDestination);
}


void main()
{
    int nHench;
    object oHench;
    object oTarget;
    effect eVFX;

    object oPC = GetPCChatSpeaker();
    if(!GetIsPC(oPC))
        {   return;   }

    // Brotherhood Puzzle
    if (GetPCChatMessage() != "My Blood for my Brothers" )
        return;

        if ( GetLocalInt(oPC, "bhpuzzle") == 1 )
    {
    // Apply a visual effect.
    eVFX = EffectVisualEffect(VFX_FNF_IMPLOSION);
    oTarget = GetPCChatSpeaker();
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oTarget);

    // Find the location to which to teleport.
    oTarget = GetWaypointByTag("wp_bhpuzzle");

    // Teleport the PC.
    DelayCommand(1.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));

    // Also teleport associates.
    oHench = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
    oHench = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
    oHench = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
    oHench = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));

    // Support for multiple henchmen (includes horses).
    nHench = 1;
    oHench = GetHenchman(oPC, 1);
    while ( oHench != OBJECT_INVALID )
    {
        DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
        // Next henchman.
        oHench = GetHenchman(oPC, ++nHench);
    }
    }
        //Secret Tunnel Puzzle
    else if (GetPCChatMessage() != "Truth" )
        return;
        // If the local int is exactly 1.
    if ( GetLocalInt(oPC, "sectunpuzzle") == 1 )
    {
    // Apply a visual effect.
    eVFX = EffectVisualEffect(VFX_FNF_IMPLOSION);
    oTarget = GetPCChatSpeaker();
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oTarget);

    // Find the location to which to teleport.
    oTarget = GetWaypointByTag("wp_sectunstat");

    // Teleport the PC.
    DelayCommand(1.0, AssignCommand(oPC, ClearAndJumpToObject(oTarget)));

    // Also teleport associates.
    oHench = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
    oHench = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
    oHench = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
    oHench = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC);
    DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));

    // Support for multiple henchmen (includes horses).
    nHench = 1;
    oHench = GetHenchman(oPC, 1);
    while ( oHench != OBJECT_INVALID )
    {
        DelayCommand(1.0, AssignCommand(oHench, ClearAndJumpToObject(oTarget)));
        // Next henchman.
        oHench = GetHenchman(oPC, ++nHench);
    }
    }
}

The usual way is to use a listener creature. This is some NPC nearby or an invisible “rat”, if you “talk” with a placeable.

Lets assume you talk to a sphinx, which offers the riddle.

the on_spawn event has the line:
SetListening (OBJECT_SELF, FALSE);

in the initiating dialog, you have a script at the end which
SetListening (OBJECT_SELF, TRUE);

In the onconversation-event is the following

  if (GetIsListening(OBJECT_SELF))
    {
      SetListening (OBJECT_SELF, FALSE);
      s = GetStringLowerCase (GetMatchedSubstring(0));
//  SendMessageToPC (GetFirstPC(), s;

      if (s == "password")
        SetLocalInt (auditor, "Topic2", 1); //correct
      else
        SetLocalInt (auditor, "Topic4", 1); //false
    }

  ActionStartConversation (GetLastSpeaker()); //this dialog branches according to the Topic variables.

That’s all. Find the whole figure in my module “TRoQ5 - by order of the King” in the “North - Northern Glacier - Caves” area

Thank you so much! I will have a look at your module right away.

OnPlayerChat is a good method - see the script in Enigma Island 3 for a working example of a password in a specific context.

1 Like

Thing is a lot of the people on here have been around since before the original Bioware forums disappeared. Then there’s all the people who made stellar contributions before leaving never to be seen again. This means there’s loads and loads of prewritten scripts on here which were meant to help people not have to “re-invent the wheel”. The script you are trying to create here is a case in point. For example back, too long ago to bear thinking about, I wrote a set of things for module creators designed to give consequences to players who insisted on trying to destroy locked doors. Mostly traps. It is called
Fun Doors and includes a door that needs a password in order to open it (there are another 42 doors in the download). As part of that package I included a table of what script needed which creature, door, etc. so that you can extract just what you need from the package.

Now if you are interested in the whole invisible listener thingy, a good place to start would be to look at The Invisible Listener v2.0 by @nereng. FWIW, I did a mini-review of that package (I gave it 8 out of 10 stars) a while ago. BTW that link should take you to the exact point in the thread where that mini-review is located. If not just look one up or down. Actually, if you go through that thread you may find other things that might be of use to you. All the things reviewed have links to their project pages.

TR

The problem for beginners is, to dig out something specific from a bulkload of scripts somewhere on the vault and then find what one need within code which is most commonly more sophisticated work with a lot of add ons which are not needed.

Which is why I did those mini-reviews and the table in fun doors. Actually I forgot to link to another thing the op may well find useful - the scripting FAQs (Frequently Asked Questions with answers). 100+ of the most common “How do I” questions answered.

TR

1 Like

If anyone hasn’t read those mini review threads they are well worth your time. I thoroughly enjoyed looking through them and got some good ideas.

I’m afraid I’m quite at a loss for how to proceed. I’m just not getting it.

I tried your Fun Door Demo, TR, and while I see how your password door is set up, I’m struggling to apply the same concept to my needs.

First of all, your puzzle is initiated by bashing a door, while I want to start with a trigger. Simple enough to do that. Your puzzle spawns a rat to converse with the player and listen. Your rat is visible (albeit concealed) and I want my listener to be fully invisible (tab highlight won’t show it). Your conversation is multiple parts, mine is a one liner (doesn’t open a conversation window). Your puzzle opens a door, I want to teleport the pc (and any summons/familiars/npc henchmen) to a waypoint elsewhere in the area.

As I don’t know the first thing about coding myself, I’m struggling with the Script Generator’s limited presets and make the most of it. So far I get my listener to spawn and say its line when I enter the trigger, but when I type the answer to the riddle nothing happens, so I don’t know if the problem is with the onconversation script of the listener, or if the onspawn script is setting up the listening correctly, or if the scripts don’t know who to teleport, or if perhaps cutscene invisibility is screwing up the listening.

Here is a module with the basics, reducing the scripting to the neccessary lines.
Sphinx.zip (10.9 KB)

1 Like

Thank you once more!