CountDown.pwn 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. Copyright [2011] [Anthony_prince aka Archer]
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. //===================Includes===================================================
  14. #include <a_samp>
  15. #include <YSI\y_ini> // thanks to Y_Less
  16. //===================Macros=====================================================
  17. #define isnull(%1) ((%1[0] == 0) || (%1[0] == 1 && %1[1] == 0)) //Thanks to Slice
  18. //===================Config=====================================================
  19. #define PrintCount // Disable this if you dont wan't to print.
  20. #define Path "LoadData.ini"
  21. #define ServerName "This is my server" // This string will show when the countdown finishes
  22. #define ServerPassword false // This will lock your server until the countdown finishes [true to enable | false to disable]
  23. #define PasswordName "countdown"
  24. //==================Strings=====================================================
  25. //Please don't touch this if you're newbie
  26. new SrvName[] = ServerName;
  27. #if ServerPassword == true
  28. new SrvPass[] = PasswordName; // Put your password here
  29. #endif
  30. #if ServerPassword == false
  31. #undef PasswordName
  32. new SrvPass[] = " "; // Prevent the error that SrvPass is not defined
  33. #endif
  34. new GeneralString[32+26+24];
  35. // I use "+" beacuse in this way i remember how many strings are here [CountDown, CountDownStop, RconPassword format]
  36. //==================CountDown Settings==========================================
  37. new CountDown,
  38. _days=1,
  39. _hours=0,
  40. _minutes=1,
  41. _seconds=10
  42. ; // Set the time to CountDown
  43. //==================Callbacks===================================================
  44. forward OpenCountDown();
  45. //==============================================================================
  46. public OnFilterScriptInit()
  47. {
  48. print(" CountDown FilterScript Loaded" );
  49. if(!isnull(SrvPass) || ServerPassword == true) {
  50. format(GeneralString, sizeof(GeneralString), "password %s", SrvPass);
  51. SendRconCommand(GeneralString);
  52. }
  53. else {
  54. SendRconCommand("password 0");
  55. }
  56. CountDown=SetTimer("OpenCountDown",1000,true);
  57. return 1;
  58. }
  59. public OnFilterScriptExit()
  60. {
  61. print(" CountDown FilterScript UnLoaded ");
  62. return 1;
  63. }
  64. public OpenCountDown()
  65. {
  66. if(fexist(Path)) INI_ParseFile(Path, "%s", .bFileFirst = true);
  67. _seconds--;
  68. switch(_seconds)
  69. {
  70. case -1:
  71. _seconds = 59,
  72. _minutes--;
  73. }
  74. switch(_minutes)
  75. {
  76. case -1:
  77. _minutes = 59,
  78. _hours--;
  79. }
  80. switch(_hours)
  81. {
  82. case -1:
  83. _hours = 23,
  84. _days--;
  85. }
  86. SaveData();
  87. format(GeneralString, sizeof(GeneralString), "hostname Opens In %01dd:%02dh:%02dm:%02ds",_days,_hours,_minutes,_seconds);
  88. SendRconCommand(GeneralString);
  89. #if defined PrintCount
  90. printf(GeneralString);
  91. #endif
  92. if(!_days&&!_hours&&!_minutes&&!_seconds) CountDownStop();
  93. }
  94. stock SaveData()
  95. {
  96. new INI:File = INI_Open(Path);
  97. //INI_SetTag(File,"CountDown");
  98. INI_WriteInt(File, "Days", _days);
  99. INI_WriteInt(File, "Hours", _hours);
  100. INI_WriteInt(File, "Minutes", _minutes);
  101. INI_WriteInt(File, "Seconds", _seconds);
  102. INI_Close(File);
  103. return 1;
  104. }
  105. forward LoadData(name[], value[]);
  106. public LoadData(name[],value[])
  107. {
  108. INI_Int("Days", _days);
  109. INI_Int("Hours", _hours);
  110. INI_Int("Minutes", _minutes);
  111. INI_Int("Seconds", _seconds);
  112. return 1;
  113. }
  114. stock CountDownStop()
  115. {
  116. format(GeneralString, sizeof(GeneralString), "hostname %s ", SrvName); // Here will show your Original Server Name after the count.
  117. SendRconCommand(GeneralString); // Send the RCON command
  118. SendRconCommand("password 0"); // This will open the server
  119. print(" Server Opened " ); // I use print instead of a string as above i prefer to have less lag.
  120. KillTimer(CountDown); // Stops the timer
  121. fremove(Path);
  122. }