watching the person outside of the range of their light.
Any help in this would be appreciated
I have neither NWN nor the toolset set installed so giving specific code is difficult. But conceptually I think this wouldn't be difficult. There are two sections in the script you linked that direct the creature to run away from light depending on distance:
ActionMoveAwayFromObject(oBrightestLight, TRUE);
and
ActionMoveAwayFromObject(oBrightestLight, FALSE, IntToFloat(iBrightest*5)+1.0);
I see a couple ways to do what you're describing. Either:
Use AssignCommand() to change both of those lines so that they're added to the command queue rather than issued as commands to be executed immediately. After that, queue a ActionOrientToTag command to change their facing. Telling them to face oBrightestLight would be simplest, but you would probably get a better result if you had them face the nearest player.
...or:
Adjust the distances add a new case for a certain distance range from oBrightestLight that they simply face your desired target.As is, they simply run away at distances of 2 or less, at greater distances (but with a valid light source) they run to a specific distance then stop, and with no valid light source they attack.
So, for example, change it so that if the distance to oBrightestLight is less than 6, then unconditionally run away, if it's less than 8 then face the target, and otherwise move to/attack target.
Actually...why not do it the easy way? This script is in the heartbeat, so it will execute pretty much constantly. Simply change it to "if closer than X to light, run away from it. Otherwise attack the closest PC." The result should be that they'll constantly be trying to run towards the nearest player, but as soon as there's light within the specified range, they'll stay away from it. That way you don't have to worry about changing their facing at all because they'll be moving towards or away from relevant targets. Facing will be handled automatically.
Though if you do this you might also want to include a case that they not do anything if they don't have a PC within line of sight. Otherwise you may end up with a zombie apocalypse as every monster in the area rushes to where the PCs are.
Sample code that probably has syntax errors because I don't have the toolset installed and I'm just typing this in windows notepad:
Change this section of code:
if( GetIsObjectValid(oBrightestLight) && !bAttack)
{
if(GetDistanceToObject(oBrightestLight)<2.1)
{
ClearAllActions();
ActionMoveAwayFromObject(oBrightestLight, TRUE);
}
else
{
ClearAllActions();
ActionMoveAwayFromObject(oBrightestLight, FALSE, IntToFloat(iBrightest*5)+1.0);
}
}
else if (!IsInConversation(OBJECT_SELF) && !bAttack)
{
if (GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS)
|| GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS_AVIAN)
|| GetIsEncounterCreature())
{
PlayMobileAmbientAnimations();
}
else if (GetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS))
{
PlayImmobileAmbientAnimations();
}
}
}
...to something like this:
if( GetIsObjectValid(oBrightestLight) && !bAttack)
{
if(GetDistanceToObject(oBrightestLight)<6)
{
ClearAllActions();
ActionMoveAwayFromObject(oBrightestLight, TRUE);
}
else if(GetNearestPC())
{
ClearAllActions();
ActionAttack(GetNearestPC());
}
else
{
// Do nothing
}
}
It's highly likely I've missed a bracket or something somewhere, but that seems the simplest way to do it. Also note that I removed all the ambient animations, but if there's no player in range, it doesn't really matter if the creatures are doing those where players can't see them.
Although, now that I look at it...the above will result in creatures that are constantly changing their mind about which way to go. It might be
creepier if you use the ActionOrientToTag method described in that first spoiler. That way, instead of constantly changing their minds you can have a range at which they run, and a range at which they sit just out of the light constantly staring at the players with their beady little eyes.