So I found this amazing code for Neverwinter Nights, that lets you make creatures afraid of light. However, the script writer disappeared before adding in the feature of them watching the person outside of the range of their light.
http://pastebin.com/GPhHG3Rq //::///////////////////////////////////////////////
//:: Name ag_ai_shyl_hb
/*
Modified OnHeartbeat AI script
Originals x2_def_heartbeat NW_C2_DEFAULT1
This script causes NPCs to perform default animations
while not otherwise engaged.
Creatures shy of light will move away from sources of light that they perceive
*/
//:://////////////////////////////////////////////
//:: Created By: Naomi Novik (12/22/2002)
//:: Modified: The Magus (2011 may 30) special ai for light shy creatures
//:://////////////////////////////////////////////
#include "ag_inc_shylight"
void main()
{
// * if not runnning normal or better Ai then exit for performance reasons
if (GetAILevel() == AI_LEVEL_VERY_LOW) return;
// Buff ourselves up right away if we should
if(GetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY))
{
// This will return TRUE if an enemy was within 40.0 m
// and we buffed ourselves up instantly to respond --
// simulates a spellcaster with protections enabled
// already.
if(TalentAdvancedBuff(40.0))
{
// This is a one-shot deal
SetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY, FALSE);
// This return means we skip sending the user-defined
// heartbeat signal in this one case.
return;
}
}
if(GetHasEffect(EFFECT_TYPE_SLEEP))
{
// If we're asleep and this is the result of sleeping
// at night, apply the floating 'z's visual effect
// every so often
if(GetSpawnInCondition(NW_FLAG_SLEEPING_AT_NIGHT))
{
effect eVis = EffectVisualEffect(VFX_IMP_SLEEP);
if(d10() > 6)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF);
}
}
}
// If we have the 'constant' waypoints flag set, walk to the next waypoint.
else if ( GetWalkCondition(NW_WALK_FLAG_CONSTANT) )
{
WalkWayPoints();
}
// Check to see if we should be playing default animations
// - make sure we don't have any current targets
else if ( !GetIsObjectValid(GetAttemptedAttackTarget())
&& !GetIsObjectValid(GetAttemptedSpellTarget())
// && !GetIsPostOrWalking())
// && !GetIsObjectValid(GetNearestSeenEnemy())
)
{
// Since we aren't doing anything in particular we should be looking out for light sources and enemies
// variables used in identifying the source of the closest pool of light
int bAttack = FALSE;
int nNth = 1;
int iLightBrightness;
int iBrightest;
float fDistToLight = 0.0;
float fDistBrightest;
object oBrightestLight;
object oNearest = GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, OBJECT_SELF, nNth);
// loop through seen creatures, looking for sources of light
while ( GetIsObjectValid(oNearest) )
{
iLightBrightness = 0;
iLightBrightness = GetLightBrightness(oNearest);
// found a light source
if (iLightBrightness > 0)
{
float fTemp = fDistToLight;
fDistToLight= GetDistanceToObject(oNearest) - IntToFloat(iLightBrightness*5);
// compare with previously found lightsources to determine which has the closest pool of light
if ( fTemp == 0.0 )
{
oBrightestLight = oNearest;
fDistBrightest = fDistToLight;
iBrightest = iLightBrightness;
}
else if ( fDistToLight < fDistBrightest )
{
fDistBrightest = fDistToLight;
oBrightestLight = oNearest;
iBrightest = iLightBrightness;
}
else if ( fDistToLight == fDistBrightest && iBrightest < iLightBrightness )
{
fDistBrightest = fDistToLight;
oBrightestLight = oNearest;
iBrightest = iLightBrightness;
}
}
else if(GetIsEnemy(oNearest) && !IsInLight(oNearest))
{
bAttack = TRUE;
ClearAllActions();
DetermineCombatRound(oNearest);
break;
}
oNearest = GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, OBJECT_SELF, ++nNth);
}
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();
}
}
}
// Send the user-defined event signal if specified
if(GetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT))
{
SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_HEARTBEAT));
}
}
Any help in this would be appreciated, as I'm trying to make a module focusing around this.