Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright [2011] [Anthony_prince aka Archer]
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- /*
- Files in the package
- ** CountDown.pwn **
- ** CountDown.amx **
- ** ChangeLog **
- ** How to install **
- ** Credits **
- ** The Folder "include" with all neccessary files to compile **
- */
- //===================Includes===================================================
- #include <a_samp>
- #include <files> // thanks to DragonBlue
- //===================Config=====================================================
- #define SaveFile "Test.ini" // default name of the file which will be saved
- #define PrintCount // Disable this if you dont wan't to print.
- new ServerName[] = "MyServerName"; // Put here your Server Name it will be show when the countdown will finish
- //==================Strings=====================================================
- //Please don't touch this if you're newbie
- new GeneralString[32+9+128];
- // I use "+" beacuse in this way i remember how many strings are here [CountDown, CountDownStop, SavedData/LoadData]
- // SaveData & LoadData will use the same cells (128).
- // 32 for the countdown hostname, 9 is for hostname strings but new ServerName[] = "MyServerName";
- // don't need a string beacuse will be found automaticaly.
- //==================CountDown Settings==========================================
- // Set Your countdown
- new CountDown,
- hours=0,
- minutes=0,
- seconds=4; // Set the time to CountDown
- //==================Callbacks===================================================
- forward OpenCountDown();
- forward SaveData();
- forward LoadData();
- //==============================================================================
- public OnFilterScriptInit()
- {
- print(" CountDown FilterScript Loaded" );
- CountDown=SetTimer("OpenCountDown",1000,1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- print(" CountDown FilterScript UnLoaded ");
- SaveData();
- DOF2_Exit();
- return 1;
- }
- public OpenCountDown()
- {
- seconds--;
- if(!seconds) {
- minutes--;
- seconds=59;
- } // Put second as 60 so it will countdown again till 0
- if(!minutes) {
- hours--;
- minutes=59;
- }
- if(hours == -1 && minutes == 59) { // Made this beacause the countdown will try to go under 0
- hours = 0;
- minutes = 0;
- }
- if(dini_Exists(SaveFile)) { // Check if there's the save file if no will load the default count
- LoadData();
- seconds--;
- if(!seconds) {
- minutes--;
- seconds=59;
- } // Put second as 60 so it will countdown again till 0
- if(!minutes) {
- hours--;
- minutes=59;
- }
- if(hours == -1 && minutes == 59) {
- hours = 0;
- minutes = 0;
- }
- }
- format(GeneralString, sizeof(GeneralString), "hostname Opens In %02d:%02d:%02d",hours,minutes,seconds);
- SendRconCommand(GeneralString);
- #if defined PrintCount
- printf(GeneralString);
- #endif
- // 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.
- SaveData();
- if(hours <= 0 && minutes <= -1 && seconds <= 59) CountDownStop(); // When the count finish will stop the countdown.
- }
- public SaveData()
- {
- format(GeneralString, sizeof(GeneralString), SaveFile);
- if(!dini_Exists(SaveFile)) {
- dini_Create(SaveFile);
- dini_IntSet(GeneralString, "Hours", hours);
- dini_IntSet(GeneralString, "Minutes", minutes);
- dini_IntSet(GeneralString, "Seconds", seconds);
- }
- else
- {
- dini_IntSet(GeneralString, "Hours", hours);
- dini_IntSet(GeneralString, "Minutes", minutes);
- dini_IntSet(GeneralString, "Seconds", seconds);
- }
- return 1;
- }
- public LoadData()
- {
- if(!dini_Exists(SaveFile)) return false ;
- format(GeneralString, sizeof(GeneralString), SaveFile);
- hours = dini_Int(GeneralString, "Hours");
- minutes = dini_Int(GeneralString, "Minutes");
- seconds = dini_Int(GeneralString, "Seconds");
- return 1;
- }
- stock CountDownStop()
- {
- hours = 0;
- minutes = 0;
- seconds = 0;
- format(GeneralString, sizeof(GeneralString), "hostname %s ", ServerName); // Here will show your Original Server Name after the count.
- SendRconCommand(GeneralString); // Send the RCON command
- SendRconCommand("password 0"); // This will open the server
- print(" Server Opened " ); // I use print instead of a string as above i prefer to have less lag.
- KillTimer(CountDown); // Stops the timer
- dini_Remove(SaveFile); // This will help to reset the countdown to the original if it goes to 0
- //SendRconCommand("unloadfs CountDown");
- }
Advertisement
Add Comment
Please, Sign In to add comment