Skip to content

Letter Puzzle

Would anyone know how to tackle coding a puzzle - (for instance), you would need to step on the letters sequetially to spell "enter", and the door unlocks and opens. I'm well out of my league on this one...

Comments

  • dunahandunahan Member Posts: 139
    I've saw that anywhere... I'll look and post it later, when I am at my PC.
  • ZephiriusZephirius Member Posts: 419
    Cool. Thanks...
  • dunahandunahan Member Posts: 139
    edited January 2022
    Okay, here's the code.... Had to cut it, due in mine there's more than one thing to do... It should be simple, but I havn't tested.
    https://gist.github.com/dunahan/f7a7e5b11ccf78b204be42091ac735ed

    Ah forgot.... This should work with vanilla NWN and even 1.69. But I don't know, if vanilla NWN has letters as placeables. You will also need triggers underneath the placeables on which the player will step.
    And another thing to think of, use the letters only once per word. So ENTER wouldn't work with this script, you should ajust the script. But NOSE for example works fine.
  • ZephiriusZephirius Member Posts: 419
    Hey, I really appreciate your help in this matter. I'm gonna check the link and see what happens...;)
  • ZephiriusZephirius Member Posts: 419
    Not sure what I'm doing wrong. Hmmm.
    I've drawn a trigger around each letter with this version of the script attached. I had to use GetObjectByTag() instead of OBJECT_SELF for the door and I added SetPlotFlag(oDoor, FALSE);
    void main()
    {
      object oPC, oPlaceable;
      string sLetter, sSolution = "ZUUL";                     // enter the solution here
      int nObjectType = GetObjectType(OBJECT_SELF);
    
      if (nObjectType == OBJECT_TYPE_TRIGGER)                // we assume, it's one of the painted trigger's
      {
        oPC = GetEnteringObject();                            // the entering object is the player
        oPlaceable = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, GetLocation(oPC));  // get the nearest placeable with the letter
        sLetter = GetName(oPlaceable);                        // the letter is on the placeable's name
    
        if (!FindSubString(GetLocalString(oPC, "word"), sLetter))  // only add if it isn't found yet
          SetLocalString(oPC, "word", GetLocalString(oPC, "word") + sLetter);  // set the letter to the collected letter's
      }
    
      if (nObjectType == OBJECT_TYPE_DOOR && GetLocked(GetObjectByTag("EVIL_DOOR"))) // it's the door
      {
        oPC = GetClickingObject();                            // so the clicker is the pc
        if (GetLocalString(oPC, "word") == sSolution)         // only unlock if he collected the right letters in the right order
        {
          object oDoor = GetObjectByTag("EVIL_DOOR");
          SetLocked(oDoor, FALSE);
          SetPlotFlag(oDoor, FALSE);                          // unlock it
          SendMessageToPC(oPC, "Door unlocked!");             // and send a message to the player
          DeleteLocalString(oPC, "word");                     // delete the passphrase
        }
      }
    }
    
  • dunahandunahan Member Posts: 139
    I'll take a look at my version and yours later 😊
  • dunahandunahan Member Posts: 139
    Updated my gist, cleaned the script and corrected my errors :)
    You should place the script in OnEnter at the triggers and OnFailToOpen at the door.

    void main()
    {
      object oPC, oPlaceable;
      string sLetter, sSolution = "NOSE";                     // enter the solution here
      int nObjectType = GetObjectType(OBJECT_SELF);           // type used to identify the object
    
      if (nObjectType ==  OBJECT_TYPE_TRIGGER)                // we assume, it's one of the painted trigger's
      {
        oPC = GetEnteringObject();                            // the entering object is the player
        oPlaceable = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, GetLocation(oPC));  // get the nearest placeable with the letter
        sLetter = GetName(oPlaceable);                        // the letter is on the placeable's name
    
        if (FindSubString(GetLocalString(oPC, "word"), sLetter) == -1)  // only add if it isn't found yet
          SetLocalString(oPC, "word", GetLocalString(oPC, "word") + sLetter);  // set the letter to the collected letter's
      }
    
      if (nObjectType == OBJECT_TYPE_DOOR)                    // it's the door
      {
        oPC = GetClickingObject();                            // so the clicker is the pc
        if (GetLocalString(oPC, "word") == sSolution)         // only unlock if he collected the right letters in the right order
        {
          SetLocked(OBJECT_SELF, FALSE);                      // unlock it
          SendMessageToPC(oPC, "Door unlocked!");             // and send a message to the player
          DeleteLocalString(oPC, "word");                     // delete the passphrase
        }
      }
    }
    
  • ZephiriusZephirius Member Posts: 419
    Will give it a go. When I get back from running errands. Thanks for your help as always.
  • ZephiriusZephirius Member Posts: 419
    I have all the generic triggers drawn around each placeable set to their OnEnter handlers. Each placeable has a letter for a name - sLetter spelling "NOSE"
    I'll change the solution later, but for now lets compare apples to apples. - so the script I'm running now is exacly the same as yours.

    I've placed the script on the OnFailToOpen handler of the door in question. The door is locked -
    I'm still getting nothing. I'm sure I'm doing something wrong... :(
  • dunahandunahan Member Posts: 139
    edited January 2022
    I updated my scriptset and uploaded a nashered fileset also an my compiled module on github under
    https://github.com/dunahan/wordpuzzle
    Beware its NWN EE .34 ;-)

    Ah, forgot to change the solution in my module from NOSE to ABCE... Corrected the files on GitHub and the module. Download it for an example 😉
    Post edited by dunahan on
  • ZephiriusZephirius Member Posts: 419
    edited January 2022
    Thanks dunahan for all the debug stuff and your help. It's working great now. Many thanks.
    Now - How to Destroy 26 objects (all the letters of the alpabet) simetaneously with just a few lines of code or so?
    Post edited by Zephirius on
  • ZephiriusZephirius Member Posts: 419
    edited January 2022
    /
    Post edited by Zephirius on
Sign In or Register to comment.