//:://///////////////////////////////////////////// //:: 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 IsOfficer(); void DoSomethingSpecial(); void ParseMyTag(); void RandomAnimation(); void main() { 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; if (GetState() == NPC_GRD_INIT) { ParseMyTag(); SetLocalLocation(OBJECT_SELF, "StartLocation", GetLocation(OBJECT_SELF)); SetState(NPC_GRD_PATROL); } if (GetState() == NPC_GRD_IDLE) { SetState(NPC_GRD_PATROL); } if (GetState() == NPC_GRD_PATROL) { SpeakString("Well, time to start my patrol"); SetState(NPC_GRD_ONPATROL); WalkWayPoints(); } if (GetState() == NPC_GRD_ONPATROL) { if (GetTimeSecond() == 0) RandomAnimation(); if (IsOfficer()) if (GetTimeHour() == 10 || GetTimeHour() == 16) // Training starts! SetState(NPC_GRD_TRAINING); if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsDusk()) SetState(NPC_GRD_ALE); else if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) SetState(NPC_GRD_REST); } if (GetState() == NPC_GRD_TRAINING) { ClearAllActions(); if (IsOfficer()) { // Call other guards for training SpeakString("Time to call em together fer a training"); PlaySound("as_pl_officerm3"); } else { // Go to Officer SpeakString("Oh, Captain is calling fer the training!"); } SetState(NPC_GRD_ISTRAINING); ActionForceMoveToObject(GetObjectByTag("WP_GRD_TRAINING"), TRUE); } if (GetState() == NPC_GRD_ISTRAINING) { if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsDusk()) SetState(NPC_GRD_ALE); else if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) SetState(NPC_GRD_REST); else if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && (GetIsNight() || GetIsDawn())) SetState(NPC_GRD_PATROL); else { // Training } } if (GetState() == NPC_GRD_ALE) { // Go to Tavern ClearAllActions(); SpeakString("Ah finally! Time fer an ale at the tavern!"); SetState(NPC_GRD_ISDRINKING); ActionForceMoveToObject(GetObjectByTag("WP_TAVERN")); } if (GetState() == NPC_GRD_ISDRINKING) { if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) SetState(NPC_GRD_REST); else if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && (GetIsNight() || GetIsDawn())) SetState(NPC_GRD_PATROL); else if (GetIsDay()) SetState(NPC_GRD_PATROL); else { // Drinking } } if (GetState() == NPC_GRD_REST) { // Go to Bed ClearAllActions(); SpeakString("Ah finally! Time fer an ale at the tavern!"); SetState(NPC_GRD_ISRESTING); ActionForceMoveToObject(GetObjectByTag("WP_GRD_REST")); } if (GetState() == NPC_GRD_ISRESTING) { if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsDusk()) SetState(NPC_GRD_ALE); else if (!GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && GetIsNight()) SetState(NPC_GRD_REST); else if (GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING) && (GetIsNight() || GetIsDawn())) SetState(NPC_GRD_PATROL); else if (GetIsDawn()) SetState(NPC_GRD_PATROL); else { // Resting } } } int GetState() { // get local state return GetLocalInt(OBJECT_SELF, "State"); } void SetState(int nState) { // Set local state SetLocalInt(OBJECT_SELF, "State", 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 = d10(); switch (nRandom) { case 1: PlayAnimation(ANIMATION_LOOPING_LISTEN); break; case 2: PlayAnimation(ANIMATION_LOOPING_LOOK_FAR); break; case 3: PlayAnimation(ANIMATION_LOOPING_PAUSE_TIRED); break; case 4: PlayAnimation(ANIMATION_LOOPING_PAUSE); break; case 5: PlayAnimation(ANIMATION_LOOPING_PAUSE2); break; case 6: PlayAnimation(ANIMATION_FIREFORGET_PAUSE_SCRATCH_HEAD); break; case 7: PlaySound("as_pl_whistle1");break; case 8: PlaySound("as_pl_whistle2");break; case 9: PlaySound("as_pl_yawningm1");break; case 10: PlaySound("as_pl_coughm1");break; } }