Author Topic: change time in reset script  (Read 325 times)

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
change time in reset script
« on: April 05, 2013, 12:51:33 pm »


               How do I set this to every 6 hours?









This is what I use, of course I am using the NWNX2 shutdown plugin but
it does either way. It restarts about every 24hrs as configured.



////////////////////////////////////////////////////////////////////////////////
//::
//:: This script will shutdown or restart your module using either NWNX2 or
//:: not. At the very bottom of the script there are two lines which depending
//:: on whether you use the NWNX2 restart plugin or not will determine your
//:: selection of code. Comment out "SetLocalString(GetModule(),"NWNX!RESETPLUGIN!SHUTDOWN","1");"
//:: if you DO NOT use the NWNX2 restart plugin.
//::
//:: This script also accounts for horses being used hence the execute "x3_mod_def_hb"
//::
////////////////////////////////////////////////////////////////////////////////
void main()
{
int iHour = GetTimeHour ();
int iMinute = GetTimeMinute ();
int iSecond = GetTimeSecond ();
int iMillisecond = GetTimeMillisecond();
SetTime(iHour, iMinute, iSecond, iMillisecond);
ExecuteScript("x3_mod_def_hb", OBJECT_SELF);
 int timekeeper = GetLocalInt(GetModule(), "loadtimer");
        SetLocalInt(GetModule(), "loadtimer", (timekeeper+1)) ;
 if (timekeeper == 9000){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          SendMessageToPC(oWarn, "Auto Restart Sequence Will Begin In One Hour!!!");
            oWarn = GetNextPC();
        }
         }

 if (timekeeper == 9300){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          SendMessageToPC(oWarn, "Auto Restart Sequence Will Begin In Thirty Minutes!!!");
            oWarn = GetNextPC();
        }
         }

 if (timekeeper == 9450){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          SendMessageToPC(oWarn, "Auto Restart Sequence Will Begin In FIFTEEN Minutes!!!");
            oWarn = GetNextPC();
        }
         }
 if (timekeeper == 9550){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          SendMessageToPC(oWarn, "Auto Restart Sequence Will Begin In FIVE Minutes!!!");
            oWarn = GetNextPC();
        }
         }
                       if (timekeeper == 9598){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          location lVis = GetLocation(oWarn);
          SendMessageToPC(oWarn, "Auto Reload Sequence Active: Server will restart in two minutes.");
          SendMessageToPC(oWarn, "You WILL have to reconnect.");
          SendMessageToPC(oWarn, "Saving all characters.");
          ExportAllCharacters();
          ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_TIME_STOP), lVis, 5.0);
          ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), lVis, 20.0);
            oWarn = GetNextPC();
        }
         }
 
            if (timekeeper == 9599){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          location lVis = GetLocation(oWarn);
          SendMessageToPC(oWarn, "Auto Restart Sequence Active, you will have to reconnect.");
          ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_METEOR_SWARM), lVis, 5.0);
            oWarn = GetNextPC();
        }
         }
 
            if (timekeeper == 9600){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          location lVis = GetLocation(oWarn);
          SendMessageToPC(oWarn, "Auto Restart Sequence Active, you will have to reconnect.");
          ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_METEOR_SWARM), lVis, 5.0);
            oWarn = GetNextPC();
        }
         }
              if (timekeeper == 9601){
              object oWarn = GetFirstPC();
              while ((oWarn != OBJECT_INVALID))
        {
          location lVis = GetLocation(oWarn);
          SendMessageToPC(oWarn, "Auto Restart Sequence Active, you will have to reconnect.");
          ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_METEOR_SWARM), lVis, 5.0);
            oWarn = GetNextPC();
        }
       }
         if (timekeeper >= 9602){
        SetLocalInt(GetModule(), "loadtimer", 0) ;
        //DelayCommand( 20.0, StartNewModule( GetModuleName() ) ); // <---- use this for module reload
      SetLocalString(GetModule(),"NWNX!RESETPLUGIN!SHUTDOWN","1"); // <---- use this if using the NWNx restart plugin
        }
}

Birdman076
               
               

               
            

Legacy_lovellin

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
change time in reset script
« Reply #1 on: May 01, 2013, 08:11:26 pm »


               If I understand the script correctly, it's intended to run in the module's heartbeat event. It counts the number of heartbeats in variable loadtimer and reacts when a certain threshold is reached. 6 hours are 3600 heartbeats. Do the shutdown after timekeeper has reached 3600 (last condition). To provide in-advance warning, adjust the first conditions accordingly.
BTW, I don't see that the first 4 lines are useful, because they read the current time and set it again. If this code doesn't pertain to a technical trick unknown to me, I recomment to delete them.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
change time in reset script
« Reply #2 on: May 02, 2013, 06:19:01 pm »


               That is the standard method for updating/resetting the clock which can lag if the server is lagging.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
change time in reset script
« Reply #3 on: May 25, 2013, 04:22:32 pm »


               

ffbj wrote...

That is the standard method for updating/resetting the clock which can lag if the server is lagging.


I concur...
               
               

               


                     Modifié par _Guile, 30 mai 2013 - 02:44 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
change time in reset script
« Reply #4 on: May 27, 2013, 03:33:59 am »


               I seen an error in the above script....

StartNewModule(GetModule());

// This is the correct usage...
StartNewModule(string sModuleName); 

// Here is the correct code for that function...

object oModule = GetModule();
if(oModule != OBJECT_INVALID)
{
 StartNewModule( GetName( oModule ) );
}
               
               

               


                     Modifié par _Guile, 30 mai 2013 - 02:40 .