Brian_Furious

HostName CountDown

Oct 11th, 2011
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.08 KB | None | 0 0
  1. /*
  2.  
  3.            Copyright [2011] [Anthony_prince aka Archer]
  4.  
  5.            Licensed under the Apache License, Version 2.0 (the "License");
  6.            you may not use this file except in compliance with the License.
  7.            You may obtain a copy of the License at
  8.  
  9.                http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.            Unless required by applicable law or agreed to in writing, software
  12.            distributed under the License is distributed on an "AS IS" BASIS,
  13.            WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.            See the License for the specific language governing permissions and
  15.            limitations under the License.
  16.  
  17. */
  18.  
  19. /*
  20.                             Files in the package
  21.                              ** CountDown.pwn **
  22.                              ** CountDown.amx **
  23.                              ** ChangeLog **
  24.                              ** How to install  **
  25.                              ** Credits **
  26.                ** The Folder "include" with all neccessary files to compile **
  27. */
  28.  
  29.  
  30. //===================Includes===================================================
  31. #include <a_samp>
  32. #include <files> // thanks to DragonBlue
  33. //===================Config=====================================================
  34. #define SaveFile "Test.ini" // default name of the file which will be saved
  35. #define PrintCount // Disable this if you dont wan't to print.
  36.  
  37. new ServerName[] = "MyServerName"; // Put here your Server Name it will be show when the countdown will finish
  38. //==================Strings=====================================================
  39. //Please don't touch this if you're newbie
  40.  
  41. new GeneralString[32+9+128];
  42. // I use "+" beacuse in this way i remember how many strings are here [CountDown, CountDownStop, SavedData/LoadData]
  43. // SaveData & LoadData will use the same cells (128).
  44. // 32 for the countdown hostname, 9 is for hostname strings but new ServerName[] = "MyServerName";
  45. // don't need a string beacuse will be found automaticaly.
  46. //==================CountDown Settings==========================================
  47. // Set Your countdown
  48. new CountDown,
  49.     hours=0,
  50.     minutes=0,
  51.     seconds=4; // Set the time to CountDown
  52.  
  53. //==================Callbacks===================================================
  54. forward OpenCountDown();
  55. forward SaveData();
  56. forward LoadData();
  57. //==============================================================================
  58.  
  59. public OnFilterScriptInit()
  60. {
  61.     print(" CountDown FilterScript Loaded" );
  62.     CountDown=SetTimer("OpenCountDown",1000,1);
  63.     return 1;
  64. }
  65.  
  66. public OnFilterScriptExit()
  67. {
  68.     print(" CountDown FilterScript UnLoaded ");
  69.     SaveData();
  70.     DOF2_Exit();
  71.     return 1;
  72. }
  73.  
  74. public OpenCountDown()
  75. {
  76.     seconds--;
  77.     if(!seconds) {
  78.         minutes--;
  79.         seconds=59;
  80.     } // Put second as 60 so it will countdown again till 0
  81.     if(!minutes) {
  82.         hours--;
  83.         minutes=59;
  84.     }
  85.     if(hours == -1 && minutes == 59) { // Made this beacause the countdown will try to go under 0
  86.         hours = 0;
  87.         minutes = 0;
  88.     }
  89.     if(dini_Exists(SaveFile)) { // Check if there's the save file if no will load the default count
  90.         LoadData();
  91.         seconds--;
  92.         if(!seconds) {
  93.             minutes--;
  94.             seconds=59;
  95.         } // Put second as 60 so it will countdown again till 0
  96.         if(!minutes) {
  97.             hours--;
  98.             minutes=59;
  99.         }
  100.         if(hours == -1 && minutes == 59) {
  101.             hours = 0;
  102.             minutes = 0;
  103.         }
  104.     }
  105.     format(GeneralString, sizeof(GeneralString), "hostname Opens In %02d:%02d:%02d",hours,minutes,seconds);
  106.     SendRconCommand(GeneralString);
  107.     #if defined PrintCount
  108.         printf(GeneralString);
  109.     #endif
  110.     // Don't move from below, it will save the time every second. Saveing the time every second is possible to create some ms of lag. But remeber this is a countdown so the server will work fine.
  111.     SaveData();
  112.     if(hours <= 0 && minutes <= -1 && seconds <= 59) CountDownStop();  // When the count finish will stop the countdown.
  113. }
  114.  
  115. public SaveData()
  116. {
  117.     format(GeneralString, sizeof(GeneralString), SaveFile);
  118.     if(!dini_Exists(SaveFile)) {
  119.         dini_Create(SaveFile);
  120.         dini_IntSet(GeneralString, "Hours", hours);
  121.         dini_IntSet(GeneralString, "Minutes", minutes);
  122.         dini_IntSet(GeneralString, "Seconds", seconds);
  123.     }
  124.     else
  125.     {
  126.         dini_IntSet(GeneralString, "Hours", hours);
  127.         dini_IntSet(GeneralString, "Minutes", minutes);
  128.         dini_IntSet(GeneralString, "Seconds", seconds);
  129.     }
  130.     return 1;
  131. }
  132.  
  133. public LoadData()
  134. {
  135.     if(!dini_Exists(SaveFile)) return false ;
  136.     format(GeneralString, sizeof(GeneralString), SaveFile);
  137.     hours = dini_Int(GeneralString, "Hours");
  138.     minutes = dini_Int(GeneralString, "Minutes");
  139.     seconds = dini_Int(GeneralString, "Seconds");
  140.     return 1;
  141. }
  142.  
  143.  
  144. stock CountDownStop()
  145. {
  146.     hours = 0;
  147.     minutes = 0;
  148.     seconds = 0;
  149.     format(GeneralString, sizeof(GeneralString), "hostname %s ", ServerName); // Here will show your Original Server Name after the count.
  150.     SendRconCommand(GeneralString); // Send the RCON command
  151.     SendRconCommand("password 0");  // This will open the server
  152.     print(" Server Opened " ); // I use print instead of a string as above i prefer to have less lag.
  153.     KillTimer(CountDown); // Stops the timer
  154.     dini_Remove(SaveFile); // This will help to reset the countdown to the original if it goes to 0
  155.     //SendRconCommand("unloadfs CountDown");
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment