[SCRIPTING] Is NW_FLAG_ESCAPE_LEAVE Broken?

Topic says it all, is NW_FLAG_ESCAPE_LEAVE broken? I know it says in nw_c2_default9 that “these may not actually work,” but I’m pretty sure I’ve used this in the past back in v1.69.

I’ve set the variable NW_GENERIC_ MASTER to “64” - as described in the note from GZ on an old Bioware thread and placed the waypoint “EXIT_RUNNER” as described so it knows where to flee when the ActivateFleeToExit() is called.

According to the Lexicon, it should work.

I’m using AssignCommand() to assign ActivateFleeToExit() to the creature tagged RUNNER in a trigger, but instead RUNNER always attacks the PC. Should I be doing ActivateFleeToExit() in a custom Heartbeat for RUNNER instead?

Oh, I’m using the OC AI for the template - nw_c2_default1 et al.

Got it working. I had to set up a custom OnSpawn and OnUserDefined. I also misread the Lexicon, ActivateFleeToExit() goes is an OnPerception event.

So…now my goblin runner sees the PC, shouts out in goblin, and flees to the cave to warn the others.

2 Likes

Howdy! I have NEVER been able to make this work and often have to waste DM-time possessing the spotter and running him off-screen or to an exit trigger!
If you could post a How-To with the relevant script lines, it would be an absolute blessing!!!

No problem.

On Spawn

// OnSpawn Event

#include "NW_I0_GENERIC"
#include "NW_O2_CONINCLUDE"

void main()
{

    SetSpawnInCondition(NW_FLAG_ESCAPE_LEAVE);
    SetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL);
    SetSpawnInCondition(NW_FLAG_PERCIEVE_EVENT);

//------------------------------------------------------------------------------
// DEFAULT GENERIC BEHAVIOR (DO NOT TOUCH)

    //Goes through and sets up which shouts the NPC will listen to.
    SetListeningPatterns();

    /*
        Optional Parameter:

            void WalkWayPoints(int nRun = FALSE, float fPause = 1.0)

            1. Looks to see if any Way Points in the module have the tag
               "WP_" + NPC TAG + "_0X", if so walk them

            2. If the tag of the Way Point is "POST_" + NPC TAG the creature
               will return this way point after combat.
    */

    WalkWayPoints();

    //Use this to create a small amount of treasure on the creature
    GenerateNPCTreasure();
}

And…

// OnUserDefined Event
#include "NW_I0_GENERIC"

void main()
{
    int nEvent = GetUserDefinedEventNumber();

    if (nEvent == EVENT_PERCEIVE)
    {
        //Yell out a shout in goblin
        SpeakString("Maach! Maach! Akorthaar! Akorthaar!"); // "Help! Help! Intruders! Intruders!"
        ActivateFleeToExit();
    }
}

I usually tweak the perception range in the template so that the “sentry” sees the PC before the PC sees the sentry.

Thank you so much, good sir!
It works fine now, though you had me for a while with the second script: “// OnUserDefined Event”
Once I bunged it into the OnPerception handler, though, it worked like a dream!!
Thanks again for the answer to a ten year niggle!!

With the 1st script in the OnSpawn event, you should have just been able to use the 2nd script in the OnUserDefined even - the last script in the creature’s script set list

Um, I tried it again in the OnUser slot, but no dice - did it just using your code in a blank script, and again in my own base OnUser script - still works fine when put in the OnPeception slot, though!
However, I did notice on further testing that ANYTHING that gets within Mr Goblin’s perception range sends him charging off to his waypoint!!
Tried an ambient neutral rabbit hopping about, and a same-faction hostile goblin walking waypoints past the sentry - off to the alam he went on both occasions before my PC was anywhere in sight!!
What is it with NWN (or me!), that just when you think you’ve got one thing right, something else goes pear-shaped?!
Anyhow, thanks again for your help.

My bad…try this instead for the OnPerception code

// OnUserDefined Event
#include "NW_I0_GENERIC"

void main()
{
    int nEvent = GetUserDefinedEventNumber();

    if (nEvent == EVENT_PERCEIVE)
    {
        //Yell out a shout in goblin
        if (GetIsPC(GetLastPercieived()) )
        {
             SpeakString("Maach! Maach! Akorthaar! Akorthaar!"); // "Help! Help! Intruders! Intruders!"
             ActivateFleeToExit();
        }
    }
}

Not sure why it won’t for you as an OnUserDefined event. You are placing the OnSpawn code from above in the OnSpawn script slot, correct?