Hourly heartbeat events

What it does
Lets you run anything each hour, or at any of the daytime transitions (dawn>day, day>dusk, etc.)

Script 1
the function DoModuleHourlyHB should be called from your modules OnHeartBeat script.

//:://///////////////////////////////////////////// //:: Hourly Heartbeat Event Signals //:: inc_mod_hb //::////////////////////////////////////////////// //:: //:: Version 1.0 //:: //:: Signals user defined events at the top of each hour, //:: as well as events for changes in day, i.e. from dawn //:: to day, from day to dusk, etc. //:: //:: Call the DoModuleHourlyHB function in the modules //:: OnHeartBeat script. //:: //:: If using the HCR ruleset, call the function from //:: the PostEvent function in the nc_inc_on_hrtbt //:: script. //:: //:: Areas to recieve the events must have Tags of Area###, //:: starting at Area000. They also must have the area_userdef //:: script defined as their OnUserDefined script. //:: //::////////////////////////////////////////////// //:: Created By: Torbin Wren (cyrilcrocker@hotmail.com) //:: Created On: 2 Oct 2002 //::////////////////////////////////////////////// /* Constants int EVENT_HOURBEAT = 2060; int EVENT_NIGHTBEAT = 2061; int EVENT_DAWNBEAT = 2062; int EVENT_DAYBEAT = 2063; int EVENT_DUSKBEAT = 2064; int TIME_NIGHT = 1; int TIME_DAWN = 2; int TIME_DAY = 3; int TIME_DUSK = 4; /* Function Prototypes // Returns a string padded to 3 characters with 0's string GetLPadNum(int WPNum); void DoModuleHourlyHB; //:://///////////////////////////////////////////// //:: GetLPadNum //::////////////////////////////////////////////// //:: Given a number, convert it to a string with //:: left padding of 0's //:: 1 becomes 01 //::////////////////////////////////////////////// //:: Created By: Kent Miller //:: Created On: Sept 3, 2002 //::////////////////////////////////////////////// string GetLPadNum(int nNum) { if (nNum<10) return "00"+IntToString(nNum); else if (nNum<100) return "0"+IntToString(nNum); else return IntToString(nNum); } void DoModuleHourlyHB { int nAreaNum; object oArea; int nCurTimeState; int nSignalTimeState = FALSE; int nLastTimeState = GetLocalInt(OBJECT_SELF,"nCurTimeState"); if (GetIsNight) nCurTimeState = TIME_NIGHT; else if (GetIsDawn) nCurTimeState = TIME_DAWN; else if (GetIsDay) nCurTimeState = TIME_DAY; else nCurTimeState = TIME_DUSK; if (nLastTimeState!=nCurTimeState) {   nSignalTimeState = nCurTimeState; SetLocalInt(OBJECT_SELF,"nCurTimeState",nCurTimeState); } int nLastHour = GetLocalInt(OBJECT_SELF,"nCurHour"); int nCurHour = GetTimeHour; if (nLastHour!=nCurHour) {   nAreaNum = 0; oArea = GetObjectByTag("Area"+GetLPadNum(nAreaNum)); while (oArea!=OBJECT_INVALID) {     SignalEvent(oArea,EventUserDefined(EVENT_HOURBEAT)); switch (nSignalTimeState) {       case 1: {         SignalEvent(oArea,EventUserDefined(EVENT_NIGHTBEAT)); break; }       case 2: {         SignalEvent(oArea,EventUserDefined(EVENT_DAWNBEAT)); break; }       case 3: {         SignalEvent(oArea,EventUserDefined(EVENT_DAYBEAT)); break; }       case 4: {         SignalEvent(oArea,EventUserDefined(EVENT_DUSKBEAT)); break; }     }      nAreaNum++; oArea = GetObjectByTag("Area"+GetLPadNum(nAreaNum)); }   SetLocalInt(OBJECT_SELF,"nCurHour",nCurHour); } }

Script 2
put in each areas OnUserDefined script.

//:://///////////////////////////////////////////// //:: Hourly Heart Beat Area Script //:: area_userdef //::////////////////////////////////////////////// //:: //:: Passes on the hourly and daytime transition events to objects. //:: //::////////////////////////////////////////////// //:: Created By: Torbin Wren (cyrilcrocker@hotmail.com) //:: Created On: 2 Oct 2002 //::////////////////////////////////////////////// int HOURLYHB_DO_CREATURES = TRUE; int HOURLYHB_DO_PLACEABLES = TRUE; int HOURLYHB_DO_DOORS = TRUE; int HOURLYHB_DO_TRIGGERS = TRUE; int NIGHTHB_DO_CREATURES = TRUE; int NIGHTHB_DO_PLACEABLES = TRUE; int NIGHTHB_DO_DOORS = TRUE; int NIGHTHB_DO_TRIGGERS = TRUE; int DAWNHB_DO_CREATURES = TRUE; int DAWNHB_DO_PLACEABLES = TRUE; int DAWNHB_DO_DOORS = TRUE; int DAWNHB_DO_TRIGGERS = TRUE; int DAYHB_DO_CREATURES = TRUE; int DAYHB_DO_PLACEABLES = TRUE; int DAYHB_DO_DOORS = TRUE; int DAYHB_DO_TRIGGERS = TRUE; int DUSKHB_DO_CREATURES = TRUE; int DUSKHB_DO_PLACEABLES = TRUE; int DUSKHB_DO_DOORS = TRUE; int DUSKHB_DO_TRIGGERS = TRUE; void PassOnEvent(int nEvent) { int nTest = TRUE; object oMe = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_IS_ALIVE, TRUE); // FOR DEBUGGING PURPOSES ONLY!!! int nDoSignalEvent = FALSE; object oObject = GetFirstObjectInArea(OBJECT_SELF); while (oObject!=OBJECT_INVALID) {   if (GetObjectType(oObject)==OBJECT_TYPE_CREATURE) {     switch (nEvent) {       case 2060: {         nDoSignalEvent = HOURLYHB_DO_CREATURES; break; }       case 2061: {         nDoSignalEvent = NIGHTHB_DO_CREATURES; break; }       case 2062: {         nDoSignalEvent = DAWNHB_DO_CREATURES; break; }       case 2063: {         nDoSignalEvent = DAYHB_DO_CREATURES; break; }       case 2064: {         nDoSignalEvent = DUSKHB_DO_CREATURES; break; }     }    }    else if (GetObjectType(oObject)==OBJECT_TYPE_PLACEABLE) {     switch (nEvent) {       case 2060: {         nDoSignalEvent = HOURLYHB_DO_PLACEABLES; break; }       case 2061: {         nDoSignalEvent = NIGHTHB_DO_PLACEABLES; break; }       case 2062: {         nDoSignalEvent = DAWNHB_DO_PLACEABLES; break; }       case 2063: {         nDoSignalEvent = DAYHB_DO_PLACEABLES; break; }       case 2064: {         nDoSignalEvent = DUSKHB_DO_PLACEABLES; break; }     }    }    else if (GetObjectType(oObject)==OBJECT_TYPE_DOOR) {     switch (nEvent) {       case 2060: {         nDoSignalEvent = HOURLYHB_DO_DOORS; break; }       case 2061: {         nDoSignalEvent = NIGHTHB_DO_DOORS; break; }       case 2062: {         nDoSignalEvent = DAWNHB_DO_DOORS; break; }       case 2063: {         nDoSignalEvent = DAYHB_DO_DOORS; break; }       case 2064: {         nDoSignalEvent = DUSKHB_DO_DOORS; break; }     }    }    else if (GetObjectType(oObject)==OBJECT_TYPE_TRIGGER) {     switch (nEvent) {       case 2060: {         nDoSignalEvent = HOURLYHB_DO_TRIGGERS; break; }       case 2061: {         nDoSignalEvent = NIGHTHB_DO_TRIGGERS; break; }       case 2062: {         nDoSignalEvent = DAWNHB_DO_TRIGGERS; break; }       case 2063: {         nDoSignalEvent = DAYHB_DO_TRIGGERS; break; }       case 2064: {         nDoSignalEvent = DUSKHB_DO_TRIGGERS; break; }     }    }    if (nDoSignalEvent) SignalEvent(oObject,EventUserDefined(nEvent)); oObject = GetNextObjectInArea(OBJECT_SELF); } } void main { int nUser = GetUserDefinedEventNumber; switch (nUser) {   case 2060: // Hourly Heart Beat {     PassOnEvent(nUser); break; }   case 2061: // Dusk to Night Heart Beat {     PassOnEvent(nUser); break; }   case 2062: // Night to Dawn Heart Beat {     PassOnEvent(nUser); break; }   case 2063: // Dawn to Day Heart Beat {     PassOnEvent(nUser); break; }   case 2064: // Day to Dusk Heart Beat {     PassOnEvent(nUser); break; } } }