Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILTERSCRIPT
- #include <a_samp>
- #include <TimestampToDate>
- #define FS_NAME "Advanced Time"
- #define FS_VERS_MAJ 0
- #define FS_VERS_MIN 0
- #define FS_VERS_BLD 32
- #define FS_VERS_TAG "RC"
- //==== You may edit this part ====//
- #define DEFAULT TIME_NORMAL //Default time type (see below)
- #define D_YEAR 2014 //Default year when first opening the filterscript
- #define D_MON 10 //Default month when first opening the filterscript
- #define D_DAY 30 //Default day
- #define D_HOUR 12 //Default hour
- #define D_MIN 0 //Default minute
- #define D_SEC 0 //Default second
- #define GMT 1 //The GMT's timezone of your server!
- //===== End of this part. =====//
- //Seriously, it's not necesarry to edit stuff below here. Get some coffee instead =D
- #define TIME_DEFAULT 0 //GTA:SA time - 1m = 1s
- #define TIME_NORMAL 1 //Normal time rate, can be changed at any time - 1m = 1m
- #define TIME_SYNC 2 //Server synchronised time
- #define CB:%0(%1) forward %0(%1); public %0(%1) //TIP: Use it for your own scripts. Really handy :)
- #define ploop(%0) for (new %0 = 0; %0 < MAX_PLAYERS; %0++) if (IsPlayerConnected(%0) && !IsPlayerNPC(%0))
- new TimeType,
- TimeTimer = (-2), //Not sure what the max ID/limit for timers is, and not sure if (-1) would give problems or not
- DT[2][3];
- public OnFilterScriptInit()
- {
- new File:timeFile,
- readStr[50],
- fCount = (-1);
- print(" ");
- print("|----- Loading Kwarde's Advanced Time FS -----|");
- if (!fexist("time.conf"))
- {
- print("* Creating the configuration file with the standard time settings");
- timeFile = fopen("time.conf", io_append);
- format(readStr, 50, "%d\n%d\n%d\n%d\n%d\n%d\n%d", DEFAULT, D_YEAR, D_MON, D_DAY, D_HOUR, D_MIN, D_SEC);
- fwrite(timeFile, readStr);
- fclose(timeFile);
- }
- timeFile = fopen("time.conf", io_read);
- while (fread(timeFile, readStr))
- {
- fCount++;
- if (fCount == 0) TimeType = strval(readStr);
- if (fCount == 1) DT[0][0] = strval(readStr);
- if (fCount == 2) DT[0][1] = strval(readStr);
- if (fCount == 3) DT[0][2] = strval(readStr);
- if (fCount == 4) DT[1][0] = strval(readStr);
- if (fCount == 5) DT[1][1] = strval(readStr);
- if (fCount == 6) DT[1][2] = strval(readStr);
- }
- fclose(timeFile);
- TimeTimer = SetTimer("UpdateTime", 1000, true);
- print("* Configuration loaded and timer started");
- print("* Filterscript "#FS_NAME" v"#FS_VERS_MAJ"."#FS_VERS_MIN"."#FS_VERS_BLD"-"#FS_VERS_TAG" loaded");
- print("|----------------------------------------|");
- print(" ");
- return 1;
- }
- public OnFilterScriptExit()
- {
- SaveData();
- print(" ");
- print("-- CREDITS OF AdvancedTime.amx --");
- print("* Kwarde - Script creator");
- print("* Jochemd - TimestampToDate.inc");
- print("-- Thanks for using my script! --");
- print(" ");
- return 1;
- }
- CB:UpdateTime()
- {
- switch (TimeType)
- {
- case TIME_DEFAULT:
- {
- DT[1][1]++;
- if (DT[1][1] > 59)
- {
- DT[1][0]++;
- DT[1][1] = 0;
- }
- if (DT[1][0] > 23)
- {
- NextDay();
- DT[1][0] = 0;
- }
- }
- case TIME_NORMAL:
- {
- DT[1][2]++;
- if (DT[1][2] > 59)
- {
- DT[1][1]++;
- DT[1][2] = 0;
- }
- if (DT[1][1] > 59)
- {
- DT[1][0]++;
- DT[1][1] = 0;
- }
- if (DT[1][0] > 23)
- {
- NextDay();
- DT[1][0] = 0;
- }
- }
- case TIME_SYNC: TimestampToDate(gettime(), DT[0][0], DT[0][1], DT[0][2], DT[1][0], DT[1][1], DT[1][2], GMT);
- }
- ploop(i) SetPlayerTime(i, DT[1][0], DT[1][1]);
- }
- stock bool:LeapYear(year)
- return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
- stock bool:IsLastDay(day, month, year)
- {
- if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
- {
- if (day == 31) return true;
- return false;
- }
- else if (month == 2)
- {
- if (LeapYear(year) && day == 29) return true;
- else if (!LeapYear(year) && day == 28) return true;
- return false;
- }
- else if (month == 4 || month == 6 || month == 9 || month == 11)
- {
- if (day == 30) return true;
- return false;
- }
- return false;
- }
- stock NextDay()
- {
- if (IsLastDay(DT[0][2], DT[0][1], DT[0][0]))
- {
- DT[0][2] = 1;
- DT[0][1]++;
- }
- if (DT[0][1] > 12)
- {
- DT[0][1] = 1;
- DT[0][0]++;
- }
- }
- stock SaveData()
- {
- if (fexist("time.conf")) fremove("time.conf");
- new File:timeFile = fopen("time.conf", io_append),
- str[50];
- format(str, 50, "%d\n%d\n%d\n%d\n%d\n%d\n%d", TimeType, DT[0][0], DT[0][1], DT[0][2], DT[1][0], DT[1][1], DT[1][2]);
- fwrite(timeFile, str);
- fclose(timeFile);
- }
- //===== FUNCTIONS =====//
- stock SetTime(hour, minute, second)
- {
- if (TimeType == TIME_SYNC) return false;
- DT[1][0] = hour;
- DT[1][1] = minute;
- DT[1][2] = second;
- SaveData();
- return true;
- }
- stock SetDate(day, month, year)
- {
- if (TimeType == TIME_SYNC) return false;
- DT[0][0] = year;
- DT[0][1] = month;
- DT[0][2] = day;
- SaveData();
- return true;
- }
- stock SetTimeType(type = DEFAULT)
- {
- TimeType = type;
- SaveData();
- return true;
- }
- stock ToggleTime(bool:toggle = true) //Free/unfreeze time (only works on TIME_DEFAULT and TIME_NORMAL !). toggle=true: freeze time. toggle=false: unfreeze time
- {
- if (TimeType == TIME_SYNC) return false;
- if (TimeTimer > (-2))
- {
- KillTimer(TimeTimer);
- TimeTimer = (-2);
- }
- else TimeTimer = SetTimer("UpdateTimer", 1000, true);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement