NWScript:
void main()
{
int nUser = GetUserDefinedEventNumber();
if (nUser = 1001)
{
location lAlarm = GetLocation(GetObjectByTag("WP_Alarm"));
location lNpcLoc = GetLocation(OBJECT_SELF);
int iSounded = GetLocalInt(OBJECT_SELF, "iSoundAlarm");
float fSoundDistance = 5.0f;
object oEncounter = GetObjectByTag("encounter");
string sAlarm = "Alarm! Alarm! Intruders!";
if (iSounded == 1)
{
if (GetDistanceBetweenLocations(lAlarm, lNpcLoc) < fSoundDistance)
{
ActionSpeakString(sAlarm);
SetEncounterActive(TRUE, oEncounter);
}
}
}
else if (nUser = 1002)
{
location lAlarm = GetLocation(GetObjectByTag("WP_Alarm"));
int iSounded = GetLocalInt(OBJECT_SELF, "iSoundAlarm");
string sShout = "Intruders spotted!";
if (iSounded != 1)
{
object oPerceived = GetLastPerceived();
if ((GetLastPerceptionSeen()) && GetIsPC(oPerceived))
{
ActionSpeakString(sShout);
ActionMoveToLocation(lAlarm, TRUE);
SetLocalInt(OBJECT_SELF, "iSoundAlarm", 1);
}
}
}
}