Skip to content

Anyone know Letoscript?

I have a script to reward XP for unlocking things, and another for disarming traps. I got sick of doing it one by one and found letoscript and moneo.
After playing around for a bit, I was able to make a script that kind of works. Trying to look up syntax for Letoscript is like trying to find living mammoths. Specifically I need to check if the OnDisarm or OnUnlock already have a script assigned and not override it. Was hoping to check the length of the existing string or something, but who knows if that's even a function, and if it is, what letters to input to call it.
Also, I don't want to award XP if the locked object needs a key to unlock. I had the script working for that, but then it started ignoring that condition randomly.

Comments

  • ProlericProleric Member Posts: 1,316
    This example reports placeables that have a script assigned:
    # Find all placeables with a given script by area
    
    %mod = 'c:\NeverwinterNights\nwn\modules\Dark Energy.mod' or die;
    
    for (%mod['*.git']) 
      {
        $area = substr($_, 0, -4);
    	%are = %mod[$area + '.are'];
        $areaname = /Name;
        close (%are);	    
    	for (/{'Placeable List'}) 
    	  {
            if (/~/OnHeartbeat ne '')
    		{print $area, ";", $areaname, ";", /~/TemplateResRef, ";", /~/OnHeartbeat,";", "\n";}
          }  
      }
    

    If you post the script that stops working randomly, I'll have a look at it.
  • ForSeriousForSerious Member Posts: 466
    With pleasure:
    %mod = '01_FS_Chapter1TEST.mod';
    
    for (%mod['*.git']) {
      for (/{'Placeable List'}) {
            if (/~/Static == 0)
            {
                if (/~/TrapFlag == 1)
                {
                    replace 'OnDisarm', '', 'trap_xp';
                }
                [b]if (/~/Locked == 1 && /~/KeyRequired == 0)[/b]
                {
                    replace 'OnUnlock', '', 'unlock_xp';
                }
    	}
      }
      for (/{'Door List'}) {
              if (/~/Static == 0)
              {
                  if (/~/TrapFlag == 1)
                  {
                      replace 'OnDisarm', '', 'trap_xp';
                  }
                  if (/~/Locked == 1 && /~/KeyRequired == 0)
                  {
                      replace 'OnUnlock', '', 'unlock_xp';
                  }
      	}
        }
        for (/{'TriggerList'}) {
                if (/~/TrapFlag == 1)
                {
                    replace 'OnDisarm', '', 'trap_xp';
                }
            }
    }
    %mod = '>';
    close %mod;
    

    I'll be doing a few more tests, but KeyRequired == 0 is the part that stopped working in that it gets ignored and assigns the script. I just assume double ampersand is the and condition notation because that's most common.
    /~/
    
    Does that mean if exists? (Like JavaScript ? after a parameter variable)
  • ForSeriousForSerious Member Posts: 466
    So the way I have
    replace 'OnDisarm', '', 'trap_xp';
    
    written out, seems to replace all instances of OnDisarm in the module. That's why the if conditions were being ignored.
  • ProlericProleric Member Posts: 1,316
    edited October 2021
    /~/ means the current array element within the for loop.

    I've never tried replace - to change the current element only, it's something like
    /~/OnDisarm = 'trap_xp';
    

    I'm not at my desk to double-check the syntax or field names, so if that doesn't work, refer to the examples that ship with moneo on the Vault.
  • ForSeriousForSerious Member Posts: 466
    Proleric wrote: »
    /~/OnDisarm = 'trap_xp';
    
    I started with that syntax but soon found I needed a way to check if OnDisarm was already populated.
    If(/~/OnDisarm == "")
    
    Seems to yield true no matter what. I guess I can try:
    If(/~/OnDisarm eq '')
    

  • ProlericProleric Member Posts: 1,316
    Yes, sorry I missed that, string comparison is eq or ne.

    I included some syntax notes in the moneo package on the Vault.
  • ForSeriousForSerious Member Posts: 466
    I did not get it from the vault. I'll have to check that out.
    Changing to eq seems to be what I needed. I had to replace 'replace' and I seem to have it working:
    %mod = '01_FS_Chapter1.mod';
    $lockCount = 0;
    $TrapCount = 0;
    $Traps = 0;
    $DoorTrap = 0;
    $DoorLock = 0;
    for (%mod['*.git'])
    {
        for (/{'Placeable List'})
        {
            if (/~/Static == 0)
            {
                if (/~/TrapFlag eq '1')
                {
                    if(/~/OnDisarm eq '')
                    {
                        print /~/Tag, ' Trapped!', "\n";
                        /~/OnDisarm = "trap_xp";
                        $TrapCount++;
                    }
                    else
                    {
                        if(/~/OnDisarm ne 'trap_xp')
                        {
                            print /~/Tag, ' OnDisarm: ', /~/OnDisarm, "\n";
                        }
                    }
                }
                if (/~/Locked eq '1' && /~/KeyRequired eq '0')
                {
                    if(/~/OnUnlock eq '')
                    {
                        print /~/Tag, ' Locked!', "\n";
                        /~/OnUnlock = "unlock_xp";
                        $lockCount++;
                    }
                    else
                    {
                        if(/~/OnUnlock ne 'unlock_xp')
                        {
                            print /~/Tag, ' OnUnlock: ', /~/OnUnlock, "\n";
                        }
                    }
                }
            }
        }
        for (/{'Door List'})
        {
            if (/~/TrapFlag eq '1')
            {
                if(/~/OnDisarm eq '')
                {
                    print /~/Tag, ' Door Trapped!', "\n";
                    /~/OnDisarm = "trap_xp";
                    $DoorTrap++;
                }
                else
                {
                    if(/~/OnDisarm ne 'trap_xp')
                    {
                        print /~/Tag, ' OnDisarm: ', /~/OnDisarm, "\n";
                    }
                }
            }
            if (/~/Locked eq '1' && /~/KeyRequired eq '0')
            {
                if(/~/OnUnlock eq '')
                {
                    print /~/Tag, ' Door Locked!', "\n";
                    /~/OnUnlock = "unlock_xp";
                    $DoorLock++;
                }
                else
                {
                    if(/~/OnUnlock ne 'unlock_xp')
                    {
                        print /~/Tag, ' OnUnlock: ', /~/OnUnlock, "\n";
                    }
                }
            }
        }
        for (/{'TriggerList'})
        {
            if (/~/TrapFlag eq '1' && /~/TrapDetectable eq '1' && /~/TrapDisarmable eq '1')
            {
                if(/~/OnDisarm eq '')
                {
                    print /~/Tag, ' Trap Trapped!', "\n";
                    /~/OnDisarm = "trap_xp";
                    $Traps++;
                }
                else
                {
                    if(/~/OnDisarm ne 'trap_xp')
                    {
                        print /~/Tag, ' OnDisarm: ', /~/OnDisarm, "\n";
                    }
                }
            }
        }
    }
    print "Placeable Traps: ", $TrapCount,  "\n";
    print "Placeable Locks: ", $lockCount,  "\n";
    print "Door Traps: ", $DoorTrap,  "\n";
    print "Door Locks: ", $DoorLock,  "\n";
    print "Trap Traps: ", $Traps,  "\n";
    %mod = '>';
    close %mod;
    
Sign In or Register to comment.