Advertisement
nickdodd25

24 hour restart V2.0

May 1st, 2012
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 29.14 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 and set the config
  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. ==================================================================================================================*/
  14. #include <a_samp>
  15. #include <sscanf2>
  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. #define COL_LIGHTBLUE               "{00CED1}"
  23. #define COL_WHITE                   "{FFFFFF}"
  24. #define COL_GREEN                   "{00FF22}"
  25. #define COL_RED                     "{F81414}"
  26. //======================================================================================================================================
  27. //RESTART CONFIG
  28. #define TIME            1441                        //Edit this for defalt time amount 1441=24 hours.
  29. #define ServerName      "changeme"  //Define your server name here.
  30. #define PassWord        "changeme"              //to make your own put "Your_Pass_Here"
  31. #define PassWord2       "0"                     //"0" means password is getting removed, keep 0 unless your server has a password all the time then put "yourserverpass"
  32. #define WarningMessage  "Restaring My Peeps"        //Put your warning message here. If you dont want any chat warning put ""
  33. #define EnableWelcome   true                        //put to false if you dont want a message on player connect
  34. //=====================================================================================================================================
  35. //set to false to disable dialogs if you have other filterscripts using dialogs or the scripts will interfear
  36. #define EnableDialog    true
  37. //if set to false only commands will work if set to true only dialogs will work
  38. //=====================================================================================================================================
  39. // Here Choose what warning limit you want!! Enable/Disable warning time. Only have one true or you will have multiple timers going at once.
  40. #define Enable10Min     true
  41. #define Enable5Min      false
  42. #define Enable2Min      false
  43. //======================================================================================================================================
  44. //dialog ids note if you have other filterscripts that use dialogs then set dialogs to false cause the two scripts will interfere
  45. #define DIALOG_RSP      3000
  46. #define DIALOG_COMMANDS 3001
  47. #define DIALOG_RESTART  3002
  48. //======================================================================================================================================
  49. //Now that you set the config go to the bottom of the script and remove the last 3 lines and enjoy.
  50. #define Build           "V 2.0"
  51. //======================================================================================================================================
  52. //forwards for the timers
  53. forward Timer_10_MinWarning();
  54. forward Timer_5_MinWarning();
  55. forward Timer_2_MinWarning();
  56. forward Timer_Restart_Kick(playerid);
  57. forward Timer_Restart_WarnPlayers();
  58. forward Timer_Restart_Reboot();
  59. new Timer1;
  60. new Timer2;
  61. new Timer3;
  62. new Timer4;
  63. new Timer5;
  64. new Timer6;
  65. new Timer7;
  66. new Timer8;
  67. new Timer9;
  68. new Timer10;
  69. //**************************************************************************************************************************************
  70. public OnFilterScriptInit()
  71. {
  72.     new year,month,day;
  73.     getdate(year, month, day);
  74.     new hour,minute,second;
  75.     gettime(hour,minute,second);
  76.    
  77.     print("\n ___________________________________________________");
  78.     print(" -----------------------------------------------------");
  79.     printf("              Auto Restart %s                  ",Build);
  80.     print("              ------------------                      ");
  81.     print("         Nicks Auto Restart/Maintain Mode             ");
  82.     printf("          Timer is set for %d minutes.          ",TIME);
  83.     print("          ******Simple auto restart*****              ");
  84.     print("         First simple script By nickdodd25            ");
  85.     print("------------------------------------------------------");
  86.     print(" ___________________________________________________\n");
  87.     print(" -> Loading...");
  88.  
  89.  
  90.     #if Enable10Min == true
  91.     Timer1 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, true);
  92.     #endif
  93.     #if Enable5Min  == true
  94.     Timer1 = SetTimer("Timer_5_MinWarning", 1000 * 60* TIME, true);
  95.     #endif
  96.     #if Enable2Min  == true
  97.     Timer1 = SetTimer("Timer_2_MinWarning", 1000 * 60* TIME, true);
  98.     #endif
  99.  
  100.     printf(" Date: %d/%d/%d - Time: %d:%d:%d",day,month,year,hour, minute, second);
  101.     return 1;
  102. }
  103.  
  104. public OnFilterScriptExit()
  105. {
  106.     KillTimer(Timer1);
  107.     KillTimer(Timer2);
  108.     KillTimer(Timer3);
  109.     KillTimer(Timer4);
  110.     KillTimer(Timer5);
  111.     KillTimer(Timer6);
  112.     KillTimer(Timer7);
  113.     KillTimer(Timer8);
  114.     KillTimer(Timer9);
  115.     KillTimer(Timer10);
  116.     new HostCommand1[128];
  117.     new HostCommand2[128];
  118.     format(HostCommand1, 128, "hostname %s", ServerName);
  119.     format(HostCommand2, 128, "password %s", PassWord2);
  120.     SendRconCommand(HostCommand1);
  121.     SendRconCommand(HostCommand2);
  122.     return 1;
  123. }
  124. #else
  125.  
  126. main()
  127. {
  128.     print("\n----------------------------------");
  129.     print(" ******Simple auto restart*****");
  130.     print(" First simple script By nickdodd25");
  131.     print("----------------------------------\n");
  132. }
  133.  
  134. #endif
  135. public OnPlayerConnect(playerid)
  136. {
  137.     #if EnableWelcome == true
  138.     SendClientMessage(playerid,Color_Yellow, ""ServerName" is using 24hour auto restart "Build" By nickdod25");
  139.     #endif
  140.     return 1;
  141. }
  142.  
  143. public OnPlayerCommandText(playerid, cmdtext[])
  144. {
  145.     #if EnableDialog == true
  146.     if (!strcmp("/rsp", cmdtext, true))
  147.     {
  148.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red,"Only admins can use this command");
  149.         ShowPlayerDialog(playerid, DIALOG_RSP, DIALOG_STYLE_LIST,""COL_WHITE"Restart Pannel "COL_LIGHTBLUE"By: nickdodd25",""COL_LIGHTBLUE"Restart Commands\n"COL_LIGHTBLUE"Stop Restart\n"COL_LIGHTBLUE"2 minute restart\n"COL_LIGHTBLUE"5 minute restart\n"COL_LIGHTBLUE"10 minuterestart\n"COL_LIGHTBLUE"24 hour restart\n"COL_LIGHTBLUE"Start maintain mode\n"COL_LIGHTBLUE"Stop maintain mode\n"COL_LIGHTBLUE"Restart","Ok","Cancel");
  150.         return 1;
  151.     }
  152.     #endif
  153.     #if EnableDialog == false
  154.     if (!strcmp("/rscmds", cmdtext, true))
  155.     {
  156.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red,"Only admins can use this command");
  157.         SendClientMessage(playerid,Color_Yellow,"=====******Rcon admins restart cmds cfg*******===");
  158.         SendClientMessage(playerid,Color_Yellow,"| /2min | /5min | /10min | /stoprestart | /24hour |");
  159.         SendClientMessage(playerid,Color_Yellow,"==***| /maintain | /maintaindone | /restart |***==");
  160.         return 1;
  161.     }
  162.     if (!strcmp("/stoprestart", cmdtext, true))
  163.     {
  164.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red,"Only admins can use this command");
  165.         KillTimer(Timer1);
  166.         KillTimer(Timer2);
  167.         KillTimer(Timer3);
  168.         KillTimer(Timer4);
  169.         KillTimer(Timer5);
  170.         KillTimer(Timer6);
  171.         KillTimer(Timer7);
  172.         KillTimer(Timer8);
  173.         KillTimer(Timer9);
  174.         KillTimer(Timer10);
  175.         new pName[MAX_PLAYER_NAME], string[56];
  176.         GetPlayerName(playerid, pName, sizeof(pName));
  177.         format(string, sizeof(string), "Admin %s has stop auto restart", pName);
  178.         SendClientMessageToAll(COLOR_BLUE, string);
  179.         print(string);
  180.         new HostCommand1[128];
  181.         format(HostCommand1, 128, "hostname %s Testing restart.", ServerName);
  182.         SendRconCommand(HostCommand1);
  183.         return 1;
  184.     }
  185.     if (!strcmp("/2min", cmdtext, true))
  186.     {
  187.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  188.         KillTimer(Timer1);
  189.         KillTimer(Timer2);
  190.         KillTimer(Timer3);
  191.         KillTimer(Timer4);
  192.         KillTimer(Timer5);
  193.         KillTimer(Timer6);
  194.         KillTimer(Timer7);
  195.         KillTimer(Timer8);
  196.         KillTimer(Timer9);
  197.         KillTimer(Timer10);
  198.         Timer5 = SetTimer("Timer_2_MinWarning", 1000, false);
  199.         new pName[MAX_PLAYER_NAME], string[56];
  200.         GetPlayerName(playerid, pName, sizeof(pName));
  201.         format(string, sizeof(string), "Admin %s has started 2 minute restart!", pName);
  202.         SendClientMessageToAll(COLOR_BLUE, string);
  203.         print(string);
  204.         return 1;
  205.     }
  206.     if (!strcmp("/5min", cmdtext, true))
  207.     {
  208.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  209.         KillTimer(Timer1);
  210.         KillTimer(Timer2);
  211.         KillTimer(Timer3);
  212.         KillTimer(Timer4);
  213.         KillTimer(Timer5);
  214.         KillTimer(Timer6);
  215.         KillTimer(Timer7);
  216.         KillTimer(Timer8);
  217.         KillTimer(Timer9);
  218.         KillTimer(Timer10);
  219.         Timer6 = SetTimer("Timer_5_MinWarning", 1000, false);
  220.         new pName[MAX_PLAYER_NAME], string[56];
  221.         GetPlayerName(playerid, pName, sizeof(pName));
  222.         format(string, sizeof(string), "Admin %s has started 5 minute restart!", pName);
  223.         SendClientMessageToAll(COLOR_BLUE, string);
  224.         print(string);
  225.         return 1;
  226.     }
  227.     if (!strcmp("/10min", cmdtext, true))
  228.     {
  229.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  230.         KillTimer(Timer1);
  231.         KillTimer(Timer2);
  232.         KillTimer(Timer3);
  233.         KillTimer(Timer4);
  234.         KillTimer(Timer5);
  235.         KillTimer(Timer6);
  236.         KillTimer(Timer7);
  237.         KillTimer(Timer8);
  238.         KillTimer(Timer9);
  239.         KillTimer(Timer10);
  240.         Timer7 = SetTimer("Timer_10_MinWarning", 1000, false);
  241.         new pName[MAX_PLAYER_NAME], string[56];
  242.         GetPlayerName(playerid, pName, sizeof(pName));
  243.         format(string, sizeof(string), "Admin %s has started 10 minute restart!", pName);
  244.         SendClientMessageToAll(COLOR_BLUE, string);
  245.         print(string);
  246.         return 1;
  247.     }
  248.     if (!strcmp("/24hour", cmdtext, true))
  249.     {
  250.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  251.         KillTimer(Timer1);
  252.         KillTimer(Timer2);
  253.         KillTimer(Timer3);
  254.         KillTimer(Timer4);
  255.         KillTimer(Timer5);
  256.         KillTimer(Timer6);
  257.         KillTimer(Timer7);
  258.         KillTimer(Timer8);
  259.         KillTimer(Timer9);
  260.         KillTimer(Timer10);
  261.         Timer8 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, false);
  262.         new pName[MAX_PLAYER_NAME], string[56];
  263.         GetPlayerName(playerid, pName, sizeof(pName));
  264.         format(string, sizeof(string), "Admin %s has started %d minute restart!", pName, TIME);
  265.         SendClientMessageToAll(COLOR_BLUE, string);
  266.         print(string);
  267.         return 1;
  268.     }
  269.     if (!strcmp("/maintain", cmdtext, true))
  270.     {
  271.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  272.        
  273.         new pName[MAX_PLAYER_NAME], string[56];
  274.         GetPlayerName(playerid, pName, sizeof(pName));
  275.         format(string, sizeof(string), "Admin %s has has put server in maintanence mode.", pName);
  276.         SendClientMessageToAll(COLOR_BLUE, string);
  277.         SendClientMessageToAll(COLOR_BLUE, "Kicking all players");
  278.         print(string);
  279.         new HostCommand1[128];
  280.         new HostCommand2[50];
  281.         printf("     %s is now in maintainece mode, type donemaintain to unlock server.",ServerName);
  282.         format(HostCommand1, 128, "hostname %s in Mantainence Mode..Please Wait.", ServerName);
  283.         format(HostCommand2, 50, "password %s", PassWord);
  284.         for(new i; i < MAX_PLAYERS; i++)
  285.         if(!IsPlayerAdmin(playerid))
  286.         {
  287.             Kick(i);
  288.         }
  289.         SendRconCommand(HostCommand1);
  290.         SendRconCommand(HostCommand2);
  291.         return 1;
  292.     }
  293.     if(!strcmp("/donemaintain", cmdtext, true))
  294.     {
  295.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  296.         new HostCommand1[128];
  297.         new HostCommand2[50];
  298.         printf("     %s is now out of maintainece mode", ServerName);
  299.         format(HostCommand1, 128, "hostname %s", ServerName);
  300.         format(HostCommand2, 50, "password %s", PassWord2);
  301.         SendRconCommand(HostCommand1);
  302.         SendRconCommand(HostCommand2);
  303.         SendClientMessageToAll(COLOR_BLUE, "You have taken server out of maintainence mode.");
  304.         return 1;
  305.     }
  306.     if(!strcmp(cmdtext,"/restart", true, 8))
  307.     {
  308.         KillTimer(Timer1);
  309.         KillTimer(Timer2);
  310.         KillTimer(Timer3);
  311.         KillTimer(Timer4);
  312.         KillTimer(Timer5);
  313.         KillTimer(Timer6);
  314.         KillTimer(Timer7);
  315.         KillTimer(Timer8);
  316.         KillTimer(Timer9);
  317.         KillTimer(Timer10);
  318.         new rsdelay, string[128];
  319.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  320.         if(sscanf(cmdtext[9],"d",rsdelay)) return SendClientMessage(playerid,Color_Red, "USAGE: /restart <time in minutes>");
  321.         if(rsdelay == 0) return SendClientMessage(playerid,Color_Red,"Time must be more than 1 minute.");
  322.         {
  323.             Timer10 = SetTimer("Timer_Restart_Kick", rsdelay*1000*60,false);
  324.             format(string,sizeof(string),"The server will restart in %d minutes.",rsdelay);
  325.             SendClientMessageToAll(COLOR_BLUE,string);
  326.             GameTextForAll(string, 5000, 3);
  327.         }
  328.         return 1;
  329.     }
  330.     #endif
  331.     return 0;
  332. }
  333. public OnRconCommand(cmd[])
  334. {
  335.     if(strcmp(cmd, "2min", true)==0)
  336.     {
  337.         printf("     You have started 2 minutet restart");
  338.         KillTimer(Timer1);
  339.         KillTimer(Timer2);
  340.         KillTimer(Timer3);
  341.         KillTimer(Timer4);
  342.         KillTimer(Timer5);
  343.         KillTimer(Timer6);
  344.         KillTimer(Timer7);
  345.         KillTimer(Timer8);
  346.         KillTimer(Timer9);
  347.         KillTimer(Timer10);
  348.         Timer5 = SetTimer("Timer_2_MinWarning", 100, false);
  349.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has started 2 minute restart!");
  350.         return 1;
  351.     }
  352.     if(strcmp(cmd, "5min", true)==0)
  353.     {
  354.         printf("     You have started 5 minutet restart");
  355.         KillTimer(Timer1);
  356.         KillTimer(Timer2);
  357.         KillTimer(Timer3);
  358.         KillTimer(Timer4);
  359.         KillTimer(Timer5);
  360.         KillTimer(Timer6);
  361.         KillTimer(Timer7);
  362.         KillTimer(Timer8);
  363.         KillTimer(Timer9);
  364.         KillTimer(Timer10);
  365.         Timer5 = SetTimer("Timer_5_MinWarning", 100, false);
  366.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has started 5 minute restart!");
  367.     }
  368.     if(strcmp(cmd, "10min", true)==0)
  369.     {
  370.         printf("     You have started 10 minutet restart");
  371.         KillTimer(Timer1);
  372.         KillTimer(Timer2);
  373.         KillTimer(Timer3);
  374.         KillTimer(Timer4);
  375.         KillTimer(Timer5);
  376.         KillTimer(Timer6);
  377.         KillTimer(Timer7);
  378.         KillTimer(Timer8);
  379.         KillTimer(Timer9);
  380.         KillTimer(Timer10);
  381.         Timer5 = SetTimer("Timer_10_MinWarning", 100, false);
  382.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has started 10 minute restart!");
  383.         return 1;
  384.     }
  385.  
  386.     if(strcmp(cmd, "stoprestart", true)==0)
  387.     {
  388.         printf("You have stopped restart");
  389.         KillTimer(Timer1);
  390.         KillTimer(Timer2);
  391.         KillTimer(Timer3);
  392.         KillTimer(Timer4);
  393.         KillTimer(Timer5);
  394.         KillTimer(Timer6);
  395.         KillTimer(Timer7);
  396.         KillTimer(Timer8);
  397.         KillTimer(Timer9);
  398.         KillTimer(Timer10);
  399.         SendClientMessageToAll(COLOR_BLUE, "Owner/Admin has stopped restart!");
  400.         new HostCommand1[128];
  401.         format(HostCommand1, 128, "hostname %s Testing restart.", ServerName);
  402.         SendRconCommand(HostCommand1);
  403.         return 1;
  404.     }
  405.     if(strcmp(cmd, "24hour", true)==0)
  406.     {
  407.         printf("You have started 24 hour auto restart");
  408.         KillTimer(Timer1);
  409.         KillTimer(Timer2);
  410.         KillTimer(Timer3);
  411.         KillTimer(Timer4);
  412.         KillTimer(Timer5);
  413.         KillTimer(Timer6);
  414.         KillTimer(Timer7);
  415.         KillTimer(Timer8);
  416.         KillTimer(Timer9);
  417.         KillTimer(Timer10);
  418.         Timer8 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, false);
  419.         new string[56];
  420.         format(string, sizeof(string), "Owner/Admin has started %d minute restart!", TIME);
  421.         SendClientMessageToAll(COLOR_BLUE, string);
  422.         return 1;
  423.     }
  424.     if(strcmp(cmd, "maintain", true)==0)
  425.     {
  426.         new HostCommand1[128];
  427.         new HostCommand2[128];
  428.         printf("%s is now in maintainece mode, type donemaintain to unlock server.",ServerName);
  429.  
  430.         for(new i; i < MAX_PLAYERS; i++)
  431.             Kick(i);
  432.  
  433.         format(HostCommand1, 128, "hostname %s in Mantainence Mode..Please Wait.", ServerName);
  434.         format(HostCommand2, 128, "password %s", PassWord);
  435.  
  436.         SendRconCommand(HostCommand1);//Puts "in Maintainence Mode..Please Wait after your server name.
  437.         SendRconCommand(HostCommand2);//locks the server with the pass you defined on PassWord
  438.         return 1;
  439.     }
  440.     if(strcmp(cmd, "donemaintain", true)==0)
  441.     {
  442.         new HostCommand1[128];
  443.         new HostCommand2[128];
  444.         printf("%s is now out of maintainece mode", ServerName);
  445.         format(HostCommand1, 128, "hostname %s", ServerName);
  446.         format(HostCommand2, 128, "password %s", PassWord2);
  447.         SendRconCommand(HostCommand1);//Sets your server name back to normal
  448.         SendRconCommand(HostCommand2);//this sets pass to 0 unlock the server unless you change PassWord2 define
  449.         return 1;
  450.     }
  451.     if(strcmp(cmd, "rscmds", true)==0)
  452.     {
  453.         print("***  stoprestart  ***");
  454.         print("******  10min  ******");
  455.         print("******  5min  *******");
  456.         print("******  2min  *******");
  457.         print("******  24hour  *****");
  458.         print("*****  maintain  ****");
  459.         print("***  maintaindone  **");
  460.         return 1;
  461.     }
  462.     return 0;
  463. }
  464.  
  465. public Timer_10_MinWarning()// 10 minute restart timer
  466. {
  467.     print("\n====================================");
  468.     printf("  %d minutes are up Server Now restarting.",TIME);
  469.     print("******10 Minute Restart warning*******");
  470.     print("======================================\n");
  471.    
  472.     GameTextForAll("Server Restart in 10 minutes!", 5000, 3);
  473.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  474.    
  475.     Timer2 = SetTimer("Timer_5_MinWarning", 1000 * 60* 5, false);
  476.     return 1;
  477. }
  478.  
  479. public Timer_5_MinWarning()// 5 minute restart timer
  480. {
  481.     print("\n======================================");
  482.     printf("  %d minutes are up Server Now restarting.",TIME);
  483.     print("********5 Minute Restart Warning********");
  484.     print("=========================================\n");
  485.    
  486.     GameTextForAll("Server Restart in 5 minutes!", 5000, 3);
  487.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  488.    
  489.     Timer3 = SetTimer("Timer_2_MinWarning", 1000 * 60* 3, false);
  490.     return;
  491. }
  492.  
  493. public Timer_2_MinWarning()// 2 minute restart timer
  494. {
  495.     print("\n===================================");
  496.     printf("  %d minutes are up Server Now restarting.",TIME);
  497.     print(" ********AUTO SERVER RESTART********");
  498.     print("=====================================\n");
  499.    
  500.     GameTextForAll("Server restart in 2 minutes!", 5000, 3);
  501.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  502.     SendClientMessageToAll(COLOR_BLUE, "Server restart in 2 minutes!");
  503.            
  504.     Timer4 = SetTimer("Timer_Restart_WarnPlayers", 1000 * 60, false);
  505.     return 1;
  506. }
  507.  
  508.  
  509. public Timer_Restart_WarnPlayers()
  510. {
  511.     print("\n===================================");
  512.     print(" *********1 Minute Warning***********");
  513.     print("=====================================\n");
  514.     new HostCommand1[128];
  515.     new HostCommand2[128];
  516.     GameTextForAll("Server restart in 1 minute!", 5000, 3);
  517.     SendClientMessageToAll(COLOR_BLUE, "Server restart in 1 minutes!");
  518.     SendClientMessageToAll(COLOR_BLUE, WarningMessage);
  519.    
  520.     SetTimer("Timer_Restart_Kick", 1000 * 60, false);
  521.     // Change the hostname of the server and it's password
  522.     format(HostCommand1, 128, "hostname %s Pending restart......", ServerName);
  523.     SendRconCommand(HostCommand1);
  524.     format(HostCommand2, 128, "password %s", PassWord);//this locks the server so new people cant join during restart.
  525.     SendRconCommand(HostCommand2);
  526.  
  527.     return 1;
  528. }
  529.  
  530. public Timer_Restart_Kick(playerid)
  531. {
  532.     // Let everyone know that the server is kicking all players before restarting
  533.     GameTextForAll("Server restarting:Kicking all players!", 5000, 3);
  534.     // Kick all players
  535.     /*for(new i; i < MAX_PLAYERS; i++)
  536.         Kick(i);*/
  537.     for(new i; i < MAX_PLAYERS; i++)
  538.     if(!IsPlayerAdmin(playerid))
  539.     {
  540.         Kick(i);
  541.     }
  542.  
  543.     // Start the next timer that will restart the server
  544.     SetTimer("Timer_Restart_Reboot", 1000 * 5, false);
  545.  
  546.     return 1;
  547. }
  548.  
  549.  
  550. public Timer_Restart_Reboot()
  551. {
  552.     // Restart the server
  553.     SendRconCommand("gmx");
  554.     //=========================================================================
  555.     //SendRconCommand("reloadfs Your_Filterscript_Here");//with this line you may also restart separate Filterscripts
  556.     SendRconCommand("reloadfs shipfail3");
  557.     //=========================================================================
  558.     print("\n===================================");
  559.     print(" ******Server Auto Restarting********");
  560.     print("=====================================\n");
  561.     new HostCommand2[128];
  562.  
  563.     format(HostCommand2, 128, "password %s", PassWord2);
  564.     SendRconCommand(HostCommand2);
  565.     new year,month,day;
  566.     getdate(year, month, day);
  567.     new hour,minute,second;
  568.     gettime(hour,minute,second);
  569.     printf(" Date: %d/%d/%d - Time: %d:%d:%d",day,month,year,hour, minute, second);
  570.     return 1;
  571. }
  572. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  573. {
  574.     switch( dialogid )
  575.     {
  576.         case DIALOG_RSP:
  577.         {
  578.             if(!response) return SendClientMessage(playerid,Color_Yellow,"You closed the Rsp panel");
  579.             if(response)
  580.             {
  581.                 if (listitem == 0)
  582.                 {
  583.                     new pDialog[550];
  584.                     strcat(pDialog, ""COL_WHITE"            =====******Rcon admins restart cmds cfg*******===\n", sizeof(pDialog));
  585.                     strcat(pDialog, ""COL_LIGHTBLUE"/rsp                opens the Restart Pannel\n", sizeof(pDialog));
  586.                     strcat(pDialog, "/rscmds            Shows commands for restarting\n", sizeof(pDialog));
  587.                     strcat(pDialog, "/2min              Restarts the server in 2 minutes\n", sizeof(pDialog));
  588.                     strcat(pDialog, "/5min              Restarts the server in 5 minutes\n", sizeof(pDialog));
  589.                     strcat(pDialog, "/10min                 Restarts the server in 10 minutes\n", sizeof(pDialog));
  590.                     strcat(pDialog, "/24hour            Starts 24 hour (defalt is 1441 minutes or what ever it has been set to) restart\n", sizeof(pDialog));
  591.                     strcat(pDialog, "/maintain          Starts maintainence mode\n", sizeof(pDialog));
  592.                     strcat(pDialog, "/donemaintain          Stops maintainence mode\n", sizeof(pDialog));
  593.                     strcat(pDialog, "/restart               Restarts the server at the time you input(NOTE: will not call the warning timers)\n", sizeof(pDialog));
  594.                     ShowPlayerDialog(playerid, DIALOG_COMMANDS, DIALOG_STYLE_MSGBOX,""COL_WHITE"Restart Commands",pDialog,"Ok","");
  595.                 }
  596.                 if (listitem == 1)
  597.                 {
  598.                     KillTimer(Timer1);
  599.                     KillTimer(Timer2);
  600.                     KillTimer(Timer3);
  601.                     KillTimer(Timer4);
  602.                     KillTimer(Timer5);
  603.                     KillTimer(Timer6);
  604.                     KillTimer(Timer7);
  605.                     KillTimer(Timer8);
  606.                     KillTimer(Timer9);
  607.                     KillTimer(Timer10);
  608.                     new pName[MAX_PLAYER_NAME], string[56];
  609.                     GetPlayerName(playerid, pName, sizeof(pName));
  610.                     format(string, sizeof(string), "Admin %s has stop auto restart", pName);
  611.                     SendClientMessageToAll(COLOR_BLUE, string);
  612.                     print(string);
  613.                     new HostCommand1[128];
  614.                     format(HostCommand1, 128, "hostname %s Testing restart.", ServerName);
  615.                     SendRconCommand(HostCommand1);
  616.  
  617.                 }
  618.                 if (listitem == 2)
  619.                 {
  620.                     KillTimer(Timer1);
  621.                     KillTimer(Timer2);
  622.                     KillTimer(Timer3);
  623.                     KillTimer(Timer4);
  624.                     KillTimer(Timer5);
  625.                     KillTimer(Timer6);
  626.                     KillTimer(Timer7);
  627.                     KillTimer(Timer8);
  628.                     KillTimer(Timer9);
  629.                     KillTimer(Timer10);
  630.                     Timer5 = SetTimer("Timer_2_MinWarning", 1000, false);
  631.                     new pName[MAX_PLAYER_NAME], string[56];
  632.                     GetPlayerName(playerid, pName, sizeof(pName));
  633.                     format(string, sizeof(string), "Admin %s has started 2 minute restart!", pName);
  634.                     SendClientMessageToAll(COLOR_BLUE, string);
  635.                     print(string);
  636.                 }
  637.                 if (listitem == 3)
  638.                 {
  639.                     KillTimer(Timer1);
  640.                     KillTimer(Timer2);
  641.                     KillTimer(Timer3);
  642.                     KillTimer(Timer4);
  643.                     KillTimer(Timer5);
  644.                     KillTimer(Timer6);
  645.                     KillTimer(Timer7);
  646.                     KillTimer(Timer8);
  647.                     KillTimer(Timer9);
  648.                     KillTimer(Timer10);
  649.                     Timer6 = SetTimer("Timer_5_MinWarning", 1000, false);
  650.                     new pName[MAX_PLAYER_NAME], string[56];
  651.                     GetPlayerName(playerid, pName, sizeof(pName));
  652.                     format(string, sizeof(string), "Admin %s has started 5 minute restart!", pName);
  653.                     SendClientMessageToAll(COLOR_BLUE, string);
  654.                     print(string);
  655.                 }
  656.                 if (listitem == 4)
  657.                 {
  658.                     KillTimer(Timer1);
  659.                     KillTimer(Timer2);
  660.                     KillTimer(Timer3);
  661.                     KillTimer(Timer4);
  662.                     KillTimer(Timer5);
  663.                     KillTimer(Timer6);
  664.                     KillTimer(Timer7);
  665.                     KillTimer(Timer8);
  666.                     KillTimer(Timer9);
  667.                     KillTimer(Timer10);
  668.                     Timer7 = SetTimer("Timer_10_MinWarning", 1000, false);
  669.                     new pName[MAX_PLAYER_NAME], string[56];
  670.                     GetPlayerName(playerid, pName, sizeof(pName));
  671.                     format(string, sizeof(string), "Admin %s has started 10 minute restart!", pName);
  672.                     SendClientMessageToAll(COLOR_BLUE, string);
  673.                     print(string);
  674.                 }
  675.                 if (listitem == 5)
  676.                 {
  677.                     KillTimer(Timer1);
  678.                     KillTimer(Timer2);
  679.                     KillTimer(Timer3);
  680.                     KillTimer(Timer4);
  681.                     KillTimer(Timer5);
  682.                     KillTimer(Timer6);
  683.                     KillTimer(Timer7);
  684.                     KillTimer(Timer8);
  685.                     KillTimer(Timer9);
  686.                     KillTimer(Timer10);
  687.                     Timer8 = SetTimer("Timer_10_MinWarning", 1000 * 60* TIME, false);
  688.                     new pName[MAX_PLAYER_NAME], string[56];
  689.                     GetPlayerName(playerid, pName, sizeof(pName));
  690.                     format(string, sizeof(string), "Admin %s has started %d minute restart!", pName, TIME);
  691.                     SendClientMessageToAll(COLOR_BLUE, string);
  692.                     print(string);
  693.                 }
  694.                 if (listitem == 6)
  695.                 {
  696.                     new pName[MAX_PLAYER_NAME], string[56];
  697.                     GetPlayerName(playerid, pName, sizeof(pName));
  698.                     format(string, sizeof(string), "Admin %s has has put server in maintanence mode.", pName);
  699.                     SendClientMessageToAll(COLOR_BLUE, string);
  700.                     SendClientMessageToAll(COLOR_BLUE, "Kicking all players");
  701.                     print(string);
  702.                     new HostCommand1[128];
  703.                     new HostCommand2[50];
  704.                     printf("%s is now in maintainece mode, type donemaintain to unlock server.",ServerName);
  705.                     format(HostCommand1, 128, "hostname %s in Mantainence Mode..Please Wait.", ServerName);
  706.                     format(HostCommand2, 50, "password %s", PassWord);
  707.                     for(new i; i < MAX_PLAYERS; i++)
  708.                     if(!IsPlayerAdmin(playerid))
  709.                     {
  710.                         Kick(i);
  711.                     }
  712.                     SendRconCommand(HostCommand1);
  713.                     SendRconCommand(HostCommand2);
  714.                 }
  715.                 if (listitem == 7)
  716.                 {
  717.                     new HostCommand1[128];
  718.                     new HostCommand2[50];
  719.                     printf("%s is now out of maintainece mode", ServerName);
  720.                     format(HostCommand1, 128, "hostname %s", ServerName);
  721.                     format(HostCommand2, 50, "password %s", PassWord2);
  722.                     SendRconCommand(HostCommand1);
  723.                     SendRconCommand(HostCommand2);
  724.                     SendClientMessageToAll(COLOR_BLUE, "You have taken server out of maintainence mode.");
  725.                 }
  726.                 if (listitem == 8)
  727.                 {
  728.                     ShowPlayerDialog(playerid, DIALOG_RESTART, DIALOG_STYLE_INPUT,""COL_WHITE"Restart","USAGE: Restart <in minutes>\nNOTE: will not call the warning timers.","Ok","");
  729.                 }
  730.             }
  731.         }
  732.         case DIALOG_RESTART:
  733.         {
  734.             if( !response ) return SendClientMessage(playerid,Color_Red,"You Closed the Restart dialog!");
  735.             if( response )
  736.             {
  737.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_RESTART, DIALOG_STYLE_INPUT, ""COL_WHITE"Restart...",""COL_RED"You have entered an invalid or no Time limit.\n"COL_WHITE"Make sure your time is in minutes!","Ok","Cancel");
  738.                 KillTimer(Timer1);
  739.                 KillTimer(Timer2);
  740.                 KillTimer(Timer3);
  741.                 KillTimer(Timer4);
  742.                 KillTimer(Timer5);
  743.                 KillTimer(Timer6);
  744.                 KillTimer(Timer7);
  745.                 KillTimer(Timer8);
  746.                 KillTimer(Timer9);
  747.                 KillTimer(Timer10);
  748.                 new rsdelay, string[128];
  749.                 if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,Color_Red, "Only admins can use this command");
  750.                 if(sscanf(inputtext,"d",rsdelay)) return ShowPlayerDialog(playerid, DIALOG_RESTART, DIALOG_STYLE_INPUT, ""COL_WHITE"Restart...",""COL_RED"You have entered an invalid or no Time limit.\n"COL_WHITE"Make sure your time is in minutes!","Ok","Cancel");
  751.                 if(rsdelay == 0) return SendClientMessage(playerid,Color_Red,"Time must be more than 1 minute.");
  752.                 {
  753.                     Timer10 = SetTimer("Timer_Restart_Kick", rsdelay*1000*60,false);
  754.                     format(string,sizeof(string),"The server will restart in %d minutes.",rsdelay);
  755.                     SendClientMessageToAll(COLOR_BLUE,string);
  756.                     GameTextForAll(string, 5000, 3);
  757.                 }
  758.             }
  759.         }
  760.     }
  761.     return 1;
  762. }
  763.  
  764. #if !defined Restart_Config
  765.     #error Set your Restart Config before using please!!!!
  766. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement