Advertisement
nickdodd25

24 hour restart

Mar 26th, 2012
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 18.67 KB | None | 0 0
  1. /***************************************************************************************************************************************
  2. ========================================================================================================================================
  3.                                 Nicks Auto server restart with maintenance mode
  4.                         This only restarts your server on a regular time that you define
  5.                                  Or when you do the commands to change.
  6.                          This script does not restart your server if it crashes.
  7.                                    This is my first full Filterscript.
  8.                    To edit the defalt time (in Minuets) edit #define TIME (time you want)
  9.                                 1441 is defalt minuets time roughly for 24 hours..
  10.       Please do not re-release without my permission or say you made it....being my first fs its not that pretty anyways lol
  11.                         Read Everything closely to see how to change the warning time
  12.  If you find any buggs or have a suggestion for the next version fell free to message me on samp forum, username nickdodd25
  13.                                                  Enjoy :D
  14. ========================================================================================================================================*/
  15. #include <a_samp>
  16. #tryinclude <timerfix>                                              // If you dont have the timer fix include I recommend it cause the timers will be more accurate.
  17. #define FILTERSCRIPT
  18. #if defined FILTERSCRIPT
  19. #define Color_Red       0xFF0000FF
  20. #define COLOR_BLUE      0x00FFFFFF
  21. #define Color_Yellow    0xFFFF00FF
  22. //--------------------------------------------------------------------------------------------------------------------------------------
  23. //======================================================================================================================================
  24.                         //RESTART CONFIG
  25. #define TIME            1441                                        //Edit this for defalt time amount 1441=24 hours. Being in a filterscript the timer is slower so could make it about 900 minutes
  26. #define ServerName      "Your server name"                          //Define your server name here.
  27. #define PassWord        "changeme"                                  //this locks the server for maintenance mode and before restart so people cant join, to make your own put "Your_Pass_Here"
  28. #define PassWord2       "0"                                         //"0" means password is getting removed, keep 0 unless your server has a password all the time then put "yourserverpass"
  29. #define WarningMessage  "Please Do Not start any missions untill after restart!" //Put your warning message here. If you dont want any chat warning put ""
  30.  
  31.                                                                     // Here Choose what warning limit you want!! Enable/Disable warning time. Only have one true or you will have multiple timers going at once.
  32. #define Enable10Min     true
  33. #define Enable5Min      false
  34. #define Enable2Min      false
  35.                                                                     //Now that you set the config go to the bottom of the script and remove the last 3 lines and enjoy.
  36. #define Build           "V 1.0.5"
  37. //======================================================================================================================================
  38. //--------------------------------------------------------------------------------------------------------------------------------------
  39. //**************************************************************************************************************************************
  40. new Timer1;
  41. new Timer2;
  42. new Timer3;
  43. new Timer4;
  44. new Timer5;
  45. new Timer6;
  46. new Timer7;
  47. new Timer8;
  48. new Timer9;
  49. public OnFilterScriptInit()
  50. {
  51.     new year,month,day;
  52.     getdate(year, month, day);
  53.     new hour,minute,second;
  54.     gettime(hour,minute,second);
  55.    
  56.     print("\n ___________________________________________________");
  57.     print(" -----------------------------------------------------");
  58.     printf("              Auto Restart %s                  ",Build);
  59.     print("              ------------------                      ");
  60.     print("         Nicks Auto Restart/Maintain Mode             ");
  61.     printf("          Timer is set for %d minutes.          ",TIME);
  62.     print("          ******Simple auto restart*****              ");
  63.     print("           First script By nickdodd25            ");
  64.     printf("        Date: %d/%d/%d - Time: %d:%d:%d",day,month,year,hour, minute, second);
  65.     print("------------------------------------------------------");
  66.     print(" ___________________________________________________\n");
  67.     print(" -> Loading...");
  68.  
  69.  
  70.     #if Enable10Min == true
  71.     Timer1 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, true);
  72.     #endif
  73.     #if Enable5Min  == true
  74.     Timer1 = SetTimer("Timer_5_MinWarning", 1000 * 60* TIME, true);
  75.     #endif
  76.     #if Enable2Min  == true
  77.     Timer1 = SetTimer("Timer_2_MinWarning", 1000 * 60* TIME, true);
  78.     #endif
  79.  
  80.    
  81.     return 1;
  82. }
  83.  
  84. public OnFilterScriptExit()
  85. {
  86.     new HostCommand1[128];
  87.     new HostCommand2[128];
  88.     format(HostCommand1, 128, "hostname %s", ServerName);
  89.     format(HostCommand2, 128, "password %s", PassWord2);
  90.     SendRconCommand(HostCommand1);
  91.     SendRconCommand(HostCommand2);
  92.     return 1;
  93. }
  94. #else
  95.  
  96. main()
  97. {
  98.     print("\n----------------------------------");
  99.     print(" ******Simple auto restart*****");
  100.     print(" First simple script By nickdodd25");
  101.     print("----------------------------------\n");
  102. }
  103.  
  104. #endif
  105.  
  106. public OnPlayerCommandText(playerid, cmdtext[])
  107. {
  108.     if (strcmp("/rscmds", cmdtext, true, 7) == 0)
  109.     {
  110.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red,"Only admins can use this command");
  111.         SendClientMessage(playerid,Color_Yellow,"           Rcon admins restart cmds cfg                ");
  112.         SendClientMessage(playerid,Color_Yellow,"  | /2min | /5min | /10min | /stoprestart | /24hour |  ");
  113.         SendClientMessage(playerid,Color_Yellow,"          | /maintain | /donemaintain |                ");
  114.         SendClientMessage(playerid,Color_Yellow,"            By:nickdodd25 build"Build"                 ");
  115.         SendClientMessage(playerid,Color_Yellow,"Thank you "ServerName" for testing/using this script");
  116.         return 1;
  117.     }
  118.     if (strcmp("/stoprestart", cmdtext, true, 12) == 0)
  119.     {
  120.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red,"Only admins can use this command");
  121.         KillTimer(Timer1);
  122.         KillTimer(Timer2);
  123.         KillTimer(Timer3);
  124.         KillTimer(Timer4);
  125.         KillTimer(Timer5);
  126.         KillTimer(Timer6);
  127.         KillTimer(Timer7);
  128.         KillTimer(Timer8);
  129.         KillTimer(Timer9);
  130.         new pName[MAX_PLAYER_NAME], string[56];
  131.         GetPlayerName(playerid, pName, sizeof(pName));
  132.         format(string, sizeof(string), "Admin %s has stop auto restart", pName);
  133.         SendClientMessageToAll(COLOR_BLUE, string);
  134.         print(string);
  135.         new HostCommand1[128];
  136.         format(HostCommand1, 128, "hostname %s", ServerName);
  137.         SendRconCommand(HostCommand1);
  138.         return 1;
  139.     }
  140.     if (strcmp("/2min", cmdtext, true, 5) == 0)
  141.     {
  142.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  143.         KillTimer(Timer1);
  144.         KillTimer(Timer2);
  145.         KillTimer(Timer3);
  146.         KillTimer(Timer4);
  147.         KillTimer(Timer5);
  148.         KillTimer(Timer6);
  149.         KillTimer(Timer7);
  150.         KillTimer(Timer8);
  151.         KillTimer(Timer9);
  152.         Timer5 = SetTimer("Timer_2_MinWarning", 1000, false);
  153.         new pName[MAX_PLAYER_NAME], string[56];
  154.         GetPlayerName(playerid, pName, sizeof(pName));
  155.         format(string, sizeof(string), "Admin %s has started 2 minute restart!", pName);
  156.         SendClientMessageToAll(COLOR_BLUE, string);
  157.         print(string);
  158.         return 1;
  159.     }
  160.     if (strcmp("/5min", cmdtext, true, 5) == 0)
  161.     {
  162.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  163.         KillTimer(Timer1);
  164.         KillTimer(Timer2);
  165.         KillTimer(Timer3);
  166.         KillTimer(Timer4);
  167.         KillTimer(Timer5);
  168.         KillTimer(Timer6);
  169.         KillTimer(Timer7);
  170.         KillTimer(Timer8);
  171.         KillTimer(Timer9);
  172.         Timer6 = SetTimer("Timer_5_MinWarning", 1000, false);
  173.         new pName[MAX_PLAYER_NAME], string[56];
  174.         GetPlayerName(playerid, pName, sizeof(pName));
  175.         format(string, sizeof(string), "Admin %s has started 5 minute restart!", pName);
  176.         SendClientMessageToAll(COLOR_BLUE, string);
  177.         print(string);
  178.         return 1;
  179.     }
  180.     if (strcmp("/10min", cmdtext, true, 6) == 0)
  181.     {
  182.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  183.         KillTimer(Timer1);
  184.         KillTimer(Timer2);
  185.         KillTimer(Timer3);
  186.         KillTimer(Timer4);
  187.         KillTimer(Timer5);
  188.         KillTimer(Timer6);
  189.         KillTimer(Timer7);
  190.         KillTimer(Timer8);
  191.         KillTimer(Timer9);
  192.         Timer7 = SetTimer("Timer_10_MinWarning", 1000, false);
  193.         new pName[MAX_PLAYER_NAME], string[56];
  194.         GetPlayerName(playerid, pName, sizeof(pName));
  195.         format(string, sizeof(string), "Admin %s has started 10 minute restart!", pName);
  196.         SendClientMessageToAll(COLOR_BLUE, string);
  197.         print(string);
  198.         return 1;
  199.     }
  200.     if (strcmp("/24hour", cmdtext, true, 7) == 0)
  201.     {
  202.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  203.         KillTimer(Timer1);
  204.         KillTimer(Timer2);
  205.         KillTimer(Timer3);
  206.         KillTimer(Timer4);
  207.         KillTimer(Timer5);
  208.         KillTimer(Timer6);
  209.         KillTimer(Timer7);
  210.         KillTimer(Timer8);
  211.         KillTimer(Timer9);
  212.         Timer8 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, false);
  213.         new pName[MAX_PLAYER_NAME], string[56];
  214.         GetPlayerName(playerid, pName, sizeof(pName));
  215.         format(string, sizeof(string), "Admin %s has started %d minute restart!", pName, TIME);
  216.         SendClientMessageToAll(COLOR_BLUE, string);
  217.         print(string);
  218.         return 1;
  219.     }
  220.     if (strcmp("/maintain", cmdtext, true, 9) == 0)
  221.     {
  222.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  223.        
  224.         new pName[MAX_PLAYER_NAME], string[56];
  225.         GetPlayerName(playerid, pName, sizeof(pName));
  226.         format(string, sizeof(string), "Admin %s has has put server in maintenance mode.", pName);
  227.         SendClientMessageToAll(COLOR_BLUE, string);
  228.         SendClientMessageToAll(COLOR_BLUE, "Kicking all players");
  229.         print(string);
  230.         new HostCommand1[128];
  231.         new HostCommand2[128];
  232.         printf("     %s is now in maintenance mode, type donemaintain to unlock server.",ServerName);
  233.         format(HostCommand1, 128, "hostname %s in maintenance Mode..Please Wait.", ServerName);
  234.         format(HostCommand2, 128, "password %s", PassWord);
  235.         for(new i; i < MAX_PLAYERS; i++)
  236.         if(!IsPlayerAdmin(playerid))
  237.         {
  238.             Kick(i);
  239.         }
  240.        
  241.         SendRconCommand(HostCommand1);
  242.         SendRconCommand(HostCommand2);
  243.         return 1;
  244.     }
  245.     if(strcmp("/donemaintain", cmdtext, true, 13)==0)
  246.     {
  247.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  248.         new HostCommand1[128];
  249.         new HostCommand2[128];
  250.         printf("     %s is now out of maintenance mode", ServerName);
  251.         format(HostCommand2, 128, "password %s", PassWord2);
  252.         format(HostCommand1, 128, "hostname %s", ServerName);
  253.         SendRconCommand(HostCommand1);
  254.         SendRconCommand(HostCommand2);
  255.         SendClientMessageToAll(COLOR_BLUE, "You have taken server out of maintenance mode.");
  256.         return 1;
  257.     }
  258.     return 0;
  259. }
  260. public OnRconCommand(cmd[])
  261. {
  262.     if(strcmp(cmd, "2min", true)==0)
  263.     {
  264.         printf("You have started 2 minute restart");
  265.         KillTimer(Timer1);
  266.         KillTimer(Timer2);
  267.         KillTimer(Timer3);
  268.         KillTimer(Timer4);
  269.         KillTimer(Timer5);
  270.         KillTimer(Timer6);
  271.         KillTimer(Timer7);
  272.         KillTimer(Timer8);
  273.         KillTimer(Timer9);
  274.         Timer5 = SetTimer("Timer_2_MinWarning", 100, false);
  275.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has started 2 minute restart!");
  276.         return 1;
  277.     }
  278.     if(strcmp(cmd, "5min", true)==0)
  279.     {
  280.         printf("You have started 5 minutet restart");
  281.         KillTimer(Timer1);
  282.         KillTimer(Timer2);
  283.         KillTimer(Timer3);
  284.         KillTimer(Timer4);
  285.         KillTimer(Timer5);
  286.         KillTimer(Timer6);
  287.         KillTimer(Timer7);
  288.         KillTimer(Timer8);
  289.         KillTimer(Timer9);
  290.         Timer5 = SetTimer("Timer_5_MinWarning", 100, false);
  291.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has started 5 minute restart!");
  292.     }
  293.     if(strcmp(cmd, "10min", true)==0)
  294.     {
  295.         printf("You have started 10 minutet restart");
  296.         KillTimer(Timer1);
  297.         KillTimer(Timer2);
  298.         KillTimer(Timer3);
  299.         KillTimer(Timer4);
  300.         KillTimer(Timer5);
  301.         KillTimer(Timer6);
  302.         KillTimer(Timer7);
  303.         KillTimer(Timer8);
  304.         KillTimer(Timer9);
  305.         Timer5 = SetTimer("Timer_10_MinWarning", 100, false);
  306.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has started 10 minute restart!");
  307.         return 1;
  308.     }
  309.  
  310.     if(strcmp(cmd, "stoprestart", true)==0)
  311.     {
  312.         printf("You have stopped restart");
  313.         KillTimer(Timer1);
  314.         KillTimer(Timer2);
  315.         KillTimer(Timer3);
  316.         KillTimer(Timer4);
  317.         KillTimer(Timer5);
  318.         KillTimer(Timer6);
  319.         KillTimer(Timer7);
  320.         KillTimer(Timer8);
  321.         KillTimer(Timer9);
  322.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has stopped restart!");
  323.         new HostCommand1[128];
  324.         format(HostCommand1, 128, "hostname %s", ServerName);
  325.         SendRconCommand(HostCommand1);
  326.         return 1;
  327.     }
  328.     if(strcmp(cmd, "24hour", true)==0)
  329.     {
  330.         printf("You have started 24 hour auto restart");
  331.         KillTimer(Timer1);
  332.         KillTimer(Timer2);
  333.         KillTimer(Timer3);
  334.         KillTimer(Timer4);
  335.         KillTimer(Timer5);
  336.         KillTimer(Timer6);
  337.         KillTimer(Timer7);
  338.         KillTimer(Timer8);
  339.         KillTimer(Timer9);
  340.         Timer8 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, false);
  341.         new string[56];
  342.         format(string, sizeof(string), "Owner/Admin has started %d minute restart!", TIME);
  343.         SendClientMessageToAll(COLOR_BLUE, string);
  344.         return 1;
  345.     }
  346.     if(strcmp(cmd, "maintain", true)==0)
  347.     {
  348.         new HostCommand1[128];
  349.         new HostCommand2[128];
  350.         printf("%s is now in maintenance mode, type donemaintain to unlock server.",ServerName);
  351.  
  352.         for(new i; i < MAX_PLAYERS; i++)
  353.             Kick(i);
  354.  
  355.         format(HostCommand1, 128, "hostname %s in maintenance Mode..Please Wait.", ServerName);
  356.         format(HostCommand2, 128, "password %s", PassWord);
  357.  
  358.         SendRconCommand(HostCommand1);//Puts "in Maintainence Mode..Please Wait after your server name.
  359.         SendRconCommand(HostCommand2);//locks the server with the pass you defined on PassWord
  360.         return 1;
  361.     }
  362.     if(strcmp(cmd, "donemaintain", true)==0)
  363.     {
  364.         new HostCommand1[128];
  365.         new HostCommand2[128];
  366.         printf("%s is now out of maintenance mode", ServerName);
  367.         format(HostCommand1, 128, "hostname %s", ServerName);
  368.         format(HostCommand2, 128, "password %s", PassWord2);
  369.         SendRconCommand(HostCommand1);//Sets your server name back to normal
  370.         SendRconCommand(HostCommand2);//this sets pass to 0 unlock the server unless you change PassWord2 define
  371.         return 1;
  372.     }
  373.     if(strcmp(cmd, "rscmds", true)==0)
  374.     {
  375.         print("***  stoprestart  ***");
  376.         print("******  10min  ******");
  377.         print("******  5min  *******");
  378.         print("******  2min  *******");
  379.         print("******  24hour  *****");
  380.         print("*****  maintain  ****");
  381.         print("***  donemaintain  **");
  382.         return 1;
  383.     }
  384.     return 0;
  385. }
  386. forward Timer_10_MinWarning();
  387. public Timer_10_MinWarning()// 10 minute restart timer
  388. {
  389.     print("\n====================================");
  390.     printf("  %d minutes are up Server Now restarting.",TIME);
  391.     print("******10 Minute Restart warning*******");
  392.     print("======================================\n");
  393.    
  394.     GameTextForAll("Server Restart in 10 minutes!", 5000, 3);
  395.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  396.    
  397.     Timer2 = SetTimer("Timer_5_MinWarning", 1000 * 60* 5, false);
  398.     return 1;
  399. }
  400. forward Timer_5_MinWarning();
  401. public Timer_5_MinWarning()// 5 minute restart timer
  402. {
  403.     print("\n======================================");
  404.     printf("  %d minutes are up Server Now restarting.",TIME);
  405.     print("********5 Minute Restart Warning********");
  406.     print("=========================================\n");
  407.    
  408.     GameTextForAll("Server Restart in 5 minutes!", 5000, 3);
  409.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  410.    
  411.     Timer3 = SetTimer("Timer_2_MinWarning", 1000 * 60* 3, false);
  412.     return;
  413. }
  414. forward Timer_2_MinWarning();
  415. public Timer_2_MinWarning()// 2 minute restart timer
  416. {
  417.     print("\n===================================");
  418.     printf("  %d minutes are up Server Now restarting.",TIME);
  419.     print(" ********AUTO SERVER RESTART********");
  420.     print("=====================================\n");
  421.    
  422.     GameTextForAll("Server restart in 2 minutes!", 5000, 3);
  423.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  424.     SendClientMessageToAll(COLOR_BLUE, "Server restart in 2 minutes!");
  425.            
  426.     Timer4 = SetTimer("Timer_Restart_WarnPlayers", 1000 * 60, false);
  427.     return 1;
  428. }
  429.  
  430. forward Timer_Restart_WarnPlayers();
  431. public Timer_Restart_WarnPlayers()
  432. {
  433.     print("\n===================================");
  434.     print(" *********1 Minute Warning***********");
  435.     print("=====================================\n");
  436.     new HostCommand1[128];
  437.     new HostCommand2[128];
  438.     GameTextForAll("Server restart in 1 minute!", 5000, 3);
  439.     SendClientMessageToAll(COLOR_BLUE, "Server restart in 1 minutes!");
  440.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  441.    
  442.     SetTimer("Timer_Restart_Kick", 1000 * 60, false);
  443.     // Change the hostname of the server and it's password
  444.     format(HostCommand1, 128, "hostname %s Pending restart......", ServerName);
  445.     SendRconCommand(HostCommand1);
  446.     format(HostCommand2, 128, "password %s", PassWord);//this locks the server so new people cant join during restart.
  447.     SendRconCommand(HostCommand2);
  448.  
  449.     return 1;
  450. }
  451.  
  452. forward Timer_Restart_Kick();
  453. public Timer_Restart_Kick()
  454. {
  455.     // Let everyone know that the server is kicking all players before restarting
  456.     GameTextForAll("Server restarting:Kicking all players!", 5000, 3);
  457.     // Kick all players
  458.     for(new i; i < MAX_PLAYERS; i++)
  459.         Kick(i);
  460.  
  461.     // Start the next timer that will restart the server
  462.     SetTimer("Timer_Restart_Reboot", 1000 * 5, false);
  463.  
  464.     return 1;
  465. }
  466.  
  467. forward Timer_Restart_Reboot();
  468. public Timer_Restart_Reboot()
  469. {
  470.     // Restart the server
  471.     SendRconCommand("gmx");
  472.     //=========================================================================
  473.     //SendRconCommand("reloadfs Your_Filterscript_Here");//with this line you may also restart separate Filterscripts");
  474.     //=========================================================================
  475.     print("\n===================================");
  476.     print(" ******Server Auto Restarting********");
  477.     print("=====================================\n");
  478.     new HostCommand2[128];
  479.  
  480.     format(HostCommand2, 128, "password %s", PassWord2);
  481.     SendRconCommand(HostCommand2);
  482.     new year,month,day;
  483.     getdate(year, month, day);
  484.     new hour,minute,second;
  485.     gettime(hour,minute,second);
  486.     printf(" Restarted on: %d/%d/%d - Time: %d:%d:%d",day,month,year,hour, minute, second);
  487.     return 1;
  488. }
  489. //remove anything below this once you have read and changed your restart config
  490. #if !defined Restart_Config
  491.     #error Set your Restart Config before using please then delet the last 3 lines!!!!
  492. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement