//:://///////////////////////////////////////////// //:: Name sc_guard_hb //:: FileName sc_guard_hb.nss //:: Copyright (c) 2001 Bioware Corp. //::////////////////////////////////////////////// /* NPC Guard Heartbeat Script Tag parameters: OFF Guard is an officer (there should not be more than one officer in an area) */ //::////////////////////////////////////////////// //:: Created By: Pad O'Lion //:: Created On: 07/03/2002 //::////////////////////////////////////////////// #include "NW_I0_GENERIC" int GetState(); void SetState(int nState); int GetSaveState(); void SetSaveState(int nState); int IsOfficer(); void DoSomethingSpecial(); void ParseMyTag(); void RandomAnimation(); void GuardTraining(int nState); void DoOfficerTrainingTalk(); int NPC_GRD_INIT = 0; //state when spawned int NPC_GRD_IDLE = 1; //not doing anything atm int NPC_GRD_PATROL = 2; //is patroulling int NPC_GRD_TRAINING = 3; //is training or is getting trained int NPC_GRD_ALE = 4; //is at the tavern int NPC_GRD_REST = 5; //rests int NPC_GRD_ONPATROL = 12; int NPC_GRD_ISTRAINING = 13; int NPC_GRD_ISDRINKING = 14; int NPC_GRD_ISRESTING = 15; int NPC_GRD_TALKING = 20; int nIdle; void main() { int nUser = GetUserDefinedEventNumber(); if (nUser == 1001) { if (GetTimeSecond() < 10) SendMessageToAllDMs (GetName(OBJECT_SELF) + " state: " + IntToString(GetState())); if (GetState() == NPC_GRD_INIT) { ParseMyTag(); SetLocalLocation(OBJECT_SELF, "StartLocation", GetLocation(OBJECT_SELF)); SetSaveState(NPC_GRD_PATROL); SetState(NPC_GRD_PATROL); } if (GetState() == NPC_GRD_IDLE) { ClearAllActions(); object oPerceived = GetLocalObject(OBJECT_SELF, "Perceived"); if (GetIsObjectValid(oPerceived)) if (GetDistanceBetween(OBJECT_SELF, oPerceived) <= 3.0f) PlaySound("as_pl_comtalk3"); else ActionMoveToObject(oPerceived); PlayImmobileAmbientAnimations(); //SetState(NPC_GRD_PATROL); } if (GetState() == NPC_GRD_PATROL) { SetIsTemporaryFriend(GetLocalObject(OBJECT_SELF, "Dummy")); SetLocalObject(OBJECT_SELF, "Dummy", OBJECT_INVALID); SetLocalObject(OBJECT_SELF, "Perceived", OBJECT_INVALID); SpeakString("Well, time to start my patrol."); SetSaveState(GetState()); SetState(NPC_GRD_ONPATROL); WalkWayPoints(); } if (GetState() == NPC_GRD_ONPATROL) { if (GetTimeSecond() <= 6) RandomAnimation(); if (IsOfficer()) if ((GetTimeHour() >= 10 && GetTimeHour() <= 12) || (GetTimeHour() >= 16 && GetTimeHour() <= 18)) // Training starts! { SetSaveState(GetState()); SetState(NPC_GRD_TRAINING); } if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsDusk()) { SetSaveState(GetState()); SetState(NPC_GRD_ALE); } else if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) { SetSaveState(GetState()); SetState(NPC_GRD_REST); } } if (GetState() == NPC_GRD_TRAINING) { SetSaveState(GetState()); SetState(NPC_GRD_ISTRAINING); ClearAllActions(); if (IsOfficer()) { // Call other guards for training SpeakString("Time to call em together fer a training"); PlaySound("as_pl_officerm3"); GuardTraining(NPC_GRD_TRAINING); ActionDoCommand(ActionForceMoveToObject(GetObjectByTag("WP_GRD_TRAINING"), TRUE)); ActionDoCommand(ActionSit(GetObjectByTag("OfficerBench"))); } else { // Go to Officer ClearAllActions(); SpeakString("Oh, Captain is calling fer the training!"); object oDummy = GetNearestObjectByTag("M1Q0BDummy"); if (GetIsObjectValid(oDummy)) { SetLocalObject(OBJECT_SELF, "Dummy", oDummy); ActionDoCommand(ActionForceMoveToObject(oDummy, TRUE)); SetIsTemporaryEnemy(oDummy); ActionDoCommand(ActionAttack(oDummy)); } else SpeakString ("Where is the training field?!"); } } if (GetState() == NPC_GRD_ISTRAINING) { if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsDusk()) { SetSaveState(GetState()); SetState(NPC_GRD_ALE); } else if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) { SetSaveState(GetState()); SetState(NPC_GRD_REST); } else if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && (GetIsDusk() || GetIsDawn())) { SetSaveState(GetState()); SetState(NPC_GRD_PATROL); } else { // Training if (GetDistanceBetween(OBJECT_SELF, GetObjectByTag("WP_GRD_TRAINING")) > 5.0f) if (IsOfficer()) { GuardTraining(NPC_GRD_ISTRAINING); ActionDoCommand(ActionForceMoveToObject(GetObjectByTag("WP_GRD_TRAINING"), TRUE)); } else { object oDummy = GetLocalObject(OBJECT_SELF, "Dummy"); ActionDoCommand(ActionForceMoveToObject(oDummy, TRUE)); ActionDoCommand(ActionAttack(oDummy)); } else if (IsOfficer()) DoOfficerTrainingTalk(); } } if (GetState() == NPC_GRD_ALE) { // Go to Tavern SetIsTemporaryFriend(GetLocalObject(OBJECT_SELF, "Dummy")); SetLocalObject(OBJECT_SELF, "Dummy", OBJECT_INVALID); ClearAllActions(); SpeakString("Ah finally! Time fer an ale at the tavern!"); SetSaveState(GetState()); SetState(NPC_GRD_ISDRINKING); ActionForceMoveToObject(GetObjectByTag("WP_TAVERN")); } if (GetState() == NPC_GRD_ISDRINKING) { if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) { SetSaveState(GetState()); SetState(NPC_GRD_REST); } else if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && (GetIsNight() || GetIsDawn())) { SetSaveState(GetState()); SetState(NPC_GRD_PATROL); } else if (GetIsDay()) { SetSaveState(GetState()); SetState(NPC_GRD_PATROL); } else { // Drinking } } if (GetState() == NPC_GRD_REST) { // Go to Bed SetIsTemporaryFriend(GetLocalObject(OBJECT_SELF, "Dummy")); SetLocalObject(OBJECT_SELF, "Dummy", OBJECT_INVALID); ClearAllActions(); SpeakString("Ah finally! Time fer an ale at the tavern!"); SetSaveState(GetState()); SetState(NPC_GRD_ISRESTING); ActionForceMoveToObject(GetObjectByTag("WP_GRD_REST")); } if (GetState() == NPC_GRD_ISRESTING) { if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsDusk()) { SetSaveState(GetState()); SetState(NPC_GRD_ALE); } else if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) { SetSaveState(GetState()); SetState(NPC_GRD_REST); } else if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && (GetIsNight() || GetIsDawn())) { SetSaveState(GetState()); SetState(NPC_GRD_PATROL); } else if (GetIsDawn()) { SetSaveState(GetState()); SetState(NPC_GRD_PATROL); } else { // Resting } } } if (nUser == 1002) { object oPerceived = GetLastPerceived(); if (GetIsObjectValid(oPerceived)) { if (GetState() != NPC_GRD_TRAINING && GetState() != NPC_GRD_ISTRAINING) { string sTag = GetTag(oPerceived); //SendMessageToAllDMs("I met " + sTag + "!"); //SendMessageToAllDMs("Officer? " + IntToString(FindSubString(sTag, "OFF"))); //SendMessageToAllDMs("Guard? " + IntToString(FindSubString(sTag, "Guard"))); if (FindSubString(sTag, "OFF") >= 0 || FindSubString(sTag, "Guard") >= 0) { SetSaveState(GetState()); SetState(NPC_GRD_IDLE); SetLocalObject(OBJECT_SELF, "Perceived", oPerceived); event ePerceived = EventUserDefined(1002); SignalEvent(oPerceived, ePerceived); if (IsOfficer()) { PlaySound("as_pl_officerm4"); SpeakString("Come on over here " + GetName(oPerceived) + " ... "); } else if (GetLocalInt(oPerceived, "Officer") == TRUE) SpeakString("Hail Captain!"); else SpeakString("Hail " + GetName(oPerceived)); ClearAllActions(); ActionMoveToObject(oPerceived); ActionDoCommand(PlayAnimation(ANIMATION_FIREFORGET_SALUTE)); DelayCommand(20.0f, SetLocalInt(OBJECT_SELF, "State", GetSaveState())); } } } } } void DoOfficerTrainingTalk() { ActionDoCommand(PlayAnimation(ANIMATION_LOOPING_TALK_FORCEFUL, 1.0f, 3.0f)); int nRandom = d4(); switch (nRandom) { case 1: PlaySound("as_pl_officerm1"); break; case 2: PlaySound("as_pl_officerm2"); break; case 3: PlaySound("as_pl_officerm3"); break; case 4: PlaySound("as_pl_officerm4"); break; } ActionDoCommand(ActionSit(GetObjectByTag("OfficerBench"))); } int GetState() { // get local state return GetLocalInt(OBJECT_SELF, "State"); } void SetState(int nState) { // Set local state SetLocalInt(OBJECT_SELF, "State", nState); } int GetSaveState() { // get local state return GetLocalInt(OBJECT_SELF, "SaveState"); } void SetSaveState(int nState) { // Set local state SetLocalInt(OBJECT_SELF, "SaveState", nState); } int IsOfficer() { // return if OBJECT_SELF is an officer return GetLocalInt(OBJECT_SELF,"Officer"); } void DoSomethingSpecial() { // some random action like animations, sounds, etc } void ParseMyTag() { // parse OBJECT_SELF Tag for initialization parameters string sTag = GetTag(OBJECT_SELF); if (FindSubString(sTag, "OFF") >= 0) SetLocalInt(OBJECT_SELF, "Officer", TRUE); if (FindSubString(sTag, "DS") >= 0) SetLocalInt(OBJECT_SELF, "DayShift", TRUE); if (FindSubString(sTag, "WPX") >= 0) SetLocalInt(OBJECT_SELF, "WalkRandomWaypoint", TRUE); } void RandomAnimation() { int nRandom = d4(); switch (nRandom) { case 1: PlaySound("as_pl_whistle1");break; case 2: PlaySound("as_pl_whistle2");break; case 3: PlaySound("as_pl_coughm1");break; case 4: PlaySound("as_pl_yawningm1");break; } } void GuardTraining(int nState) { int nNth = 1; object oObject = GetNearestObjectByTag("Guard", OBJECT_SELF, nNth); while (GetIsObjectValid(oObject)) { SetLocalInt(oObject, "State", nState); oObject = OBJECT_INVALID; nNth++; oObject = GetNearestObjectByTag("Guard", OBJECT_SELF, nNth); } }