(solved) Prevent disarming a trap with the "Find Trap" Spell

How can I make sure, that a trap can’t be disarmed with this spell (or the spy glass item)

Uncheck the disarmable flag doesn’t help. My best solution so far is to overwrite nw_s0_findtrap and check for a special tag.

But I wonder if there is a more elegant solution. I think I’ve seen “refusing traps” somewhere, but I don’t recall where.

@Mmat

Can you make it undetectable?

If so, and you want to still let players detect it, then use a “fake” version (another trigger) for them to detect, but leave the real trap undetectable.

Those “Lens of Detection” spoil my whole fun (… to kill a PC … :smiley: )

@Lance_Botelle : the code of the impact script of the spell “Find Trap” seems to ignore everything, it will disable even “undetectable” or “undisarmable” traps.

This is my solution so far (in case, somebody is interested). It’s the original script with two additional lines: if the DC is greater than 35, the spell will not disable it anymore. So only a rogue with proper skills can disable it …

// nw_s0_findtrap
#include "x2_inc_spellhook"

void main()
{
  if (!X2PreSpellCastCode()) return;

  effect eVis = EffectVisualEffect(VFX_IMP_KNOCK);
  effect eFail = EffectVisualEffect(VFX_IMP_GLOBE_USE);
  int nCnt = 1;
  int oType = OBJECT_TYPE_TRIGGER | OBJECT_TYPE_DOOR | OBJECT_TYPE_PLACEABLE;
  object oTrap = GetNearestObject(oType, OBJECT_SELF, nCnt);
  while(GetIsObjectValid(oTrap) && GetDistanceToObject(oTrap) <= 30.0)
    {
      if (GetIsTrapped(oTrap))
        {
          if (GetTrapDisarmDC(oTrap) > 35)
            ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eFail, GetLocation(oTrap));
          else
            {
              SetTrapDetectedBy(oTrap, OBJECT_SELF);
              ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(oTrap));
              DelayCommand(2.0, SetTrapDisabled(oTrap));
            }
        }
      nCnt++;
      oTrap = GetNearestObject(oType, OBJECT_SELF, nCnt);
    }
}

@Mmat

OK … I’m not familiar with Find Trap/Lens of Detection. (NWN 1/2 differences in detection, possibly? *) Edit the script as you say then. :thinking:

(*) Edited for clarity.

Mmmm, the spell “Find Traps” should exist in NWN2 … I wonder what it will do. Has NWN2 an “open to public” impact script for spells as NWN1?

1 Like

@Mmat

My bad … I meant that I am not familiar with the spells (not that they were not there) and that the differences in detection/disarm may have been different between NWNs. :slightly_smiling_face:

Sorry, I don’t know what you mean by this?

if all you want to do is literally find traps and not disarm them, you just need to comment-out that line in the spell’s impact script nw_s0_findtrap.nss :

      //DelayCommand(2.0, SetTrapDisabled(oTrap));

this will also change the behaviour for the loupe item that calls the spell.

“Find traps” is a common spell for clerics and wizards, but the “detection lens” item makes it available for everybody. No good.

There are differences for sure. Seemingly NWN2 uses a script with the very same name, but it doesn’t disable the trap. Instead there seems to be a function to highlight the trap. Ah, and it’s buggy.

By now I guess, overwriting the original bio script is the best solution as shown above. It’s easy to add additional checks within the loop.

Case closed.

Every spell has an “Impact script” where you’ll find, what the spell actually does to the target. In this script are checks for restrictions, immunities and saving throws too. The script can be opened with the toolset, even if it’s an original bio script.

Seemingly there is no “Open Script” function in the NWN2 toolset. So I used a placeable and could find the impact script in question.

@Mmat

Oh, I think you just mean can the script be posted! I think I understand now. :grin:

Yes, NWN2 also has “impact scripts” that can be copied and pasted here if required. They are listed in the spells.2da.

Yes, there is … In fact there are probably around three (or more) ways to do this. This is just one way …

What is the bug you speak of?

I once updated one of my own detection scripts to place the red glow on a target (because it did not apply it on a door in question), but other than that was there anything else?

Here is a snippet (with comments) from one of my own trap scripts … perhaps this is the issue you are alluding to? i.e. You want detection red glow without needing to set the trap as “trapped”?

if (iDetectRoll >= nDC)
		{				
			// USING SetTrapDetectedBy FUNCTION TURNS THIS RED
			// UPDATE: DOES *NOT* WORK UNLESS "TRAPPED" IS SET TRUE, WHICH WE DO 
			// NOT WANT TO SET ON MY OWN TRAPS. THEREFORE, WE NEED THIS AFTER ALL
			effect eGlow = EffectVisualEffect(VFX_DUR_GLOW_RED);				
			ApplyEffectToObject(DURATION_TYPE_PERMANENT, eGlow, oTrap);			
			
			oTrapSourceDestroy = OBJECT_SELF;						
		}	

The last condition in line 44 will abort the loop on the first trap which is non detectable, omitting all the traps in vicinity, which would be found if the loop weren’t aborted.

A very rare situation I guess, but nevertheless it’s wrong.

1 Like

Good catch - I’ll edit the script for my own campaign now, just in case such a rare situation should ever arise. :+1:

Traps (OC) is an area I have not done too much with. (I did some work for some homebrew traps, but that’s all.) I guess it’s an area I may have to add to my todo list and look at more closely at some point in the future.