Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Include: SyncPlayerTime For SAMP: 0.3d+
- Author: Jonny5
- Version: 0.3
- Description:
- This include will create a Textdraw Clock and Sync all Players to the same time.
- There is currently 2 modes of display:
- Mode 1: Will Sync all Players times to the servers real world time.
- Mode 2: Will sync all players to the same (in Game) time
- Both systems can be used to change the day/to night night/ to day.
- Mode 1 will keep the time more constant, mode 2 is relying on PAWN timers to keep
- acurate time so the time will be off by up to 5ms atleast.
- Credits to:
- Twisted_Insane : Requested the script.
- */
- #define TD_FONT_COLOR 0x99CCFFFF //Time Font Color
- #define TD_OUTLINE_COLOR 0x0066CCFF //Time OutLine Color
- #define TD_OUTLINE_SIZE 1 //Time OutLine Size
- #define SYNC_SERVER_TIME //if uncommented will use server time, 1 real hour = 1 game hour
- #define USA_TIME_FORMAT //Use the 12 hour format.
- #define EFFECT_WEATHER //Set weather with player clock (only for mode 1)
- new Hour, Minute, TIMER_WorldTime;
- #if defined SYNC_SERVER_TIME
- new Second;
- #endif
- new Text:tdWorldTime;
- new PlayerIsSpawned[MAX_PLAYERS];
- forward UpdateWorldTime();
- public UpdateWorldTime()
- {
- #if defined SYNC_SERVER_TIME
- gettime(Hour, Minute, Second);
- new str[9];
- #else
- new str[6];
- Minute++;
- if(Minute == 60)
- {
- Minute=0;
- Hour++;
- }
- if(Hour == 24) Hour=0;
- #endif
- #if defined USA_TIME_FORMAT
- if (Hour > 12)
- {
- format(str, sizeof(str), "%02d:%02d:PM", Hour - 12, Minute);
- }
- else if (Hour ==0)
- {
- format(str, sizeof(str), "%02d:%02d:AM", Hour + 12, Minute);
- }
- else
- {
- format(str, sizeof(str), "%02d:%02d:AM", Hour, Minute);
- }
- #else
- format(str, sizeof(str), "%02d:%02d", Hour, Minute);
- #endif
- TextDrawSetString(tdWorldTime,str);
- #if defined EFFECT_WEATHER & defined SYNC_SERVER_TIME
- for(new i = 0,pl = GetMaxPlayers(); i < pl ;i++)
- {
- if(PlayerIsSpawned[i] == 1)
- {
- SetPlayerTime(i,Hour,Minute);
- }
- }
- #endif
- #if !defined SYNC_SERVER_TIME
- for(new i = 0,pl = GetMaxPlayers(); i < pl ;i++)
- {
- if(PlayerIsSpawned[i] == 1)
- {
- SetPlayerTime(i,Hour,Minute);
- }
- }
- #endif
- return 1;
- }
- //For more info on ALS Hooking check
- //http://forum.sa-mp.com/showthread.php?t=85907
- //--------------OnGameModeExit Hook-------------------
- public OnGameModeExit()
- {
- new ret = 1;
- KillTimer (TIMER_WorldTime);
- TextDrawHideForAll (tdWorldTime);
- TextDrawDestroy (tdWorldTime);
- if (funcidx("SPT_OnGameModeExit") != -1)
- {
- ret = CallLocalFunction("SPT_OnGameModeExit", "");
- }
- return ret;
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit SPT_OnGameModeExit
- forward SPT_OnGameModeExit();
- //--------------OnGameModeInit Hook-------------------
- public OnGameModeInit()
- {
- new ret = 1;
- tdWorldTime = TextDrawCreate(605.0,25.0," ");
- TextDrawUseBox (tdWorldTime, 0);
- TextDrawFont (tdWorldTime, 3);
- TextDrawColor (tdWorldTime, TD_FONT_COLOR);
- TextDrawSetOutline (tdWorldTime, TD_OUTLINE_SIZE);
- TextDrawBackgroundColor (tdWorldTime, TD_OUTLINE_COLOR);
- TextDrawSetShadow (tdWorldTime, 0);
- TextDrawAlignment (tdWorldTime, 3);
- TextDrawLetterSize (tdWorldTime, 0.3, 1.0);
- TextDrawShowForAll (tdWorldTime);
- TIMER_WorldTime = SetTimer("UpdateWorldTime", 1000, true);
- if (funcidx("SPT_OnGameModeInit") != -1)
- {
- ret = CallLocalFunction("SPT_OnGameModeInit", "");
- }
- return ret;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit SPT_OnGameModeInit
- forward SPT_OnGameModeInit();
- //--------------OnPlayerConnect Hook-------------------
- public OnPlayerConnect(playerid)
- {
- new ret = 1;
- TogglePlayerClock(playerid, 0);
- if (funcidx("SPT_OnPlayerConnect") != -1)
- {
- ret = CallLocalFunction("SPT_OnPlayerConnect", "i",playerid);
- }
- return ret;
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect SPT_OnPlayerConnect
- forward SPT_OnPlayerConnect(playerid);
- //--------------OnPlayerDisconnect Hook-------------------
- public OnPlayerDisconnect(playerid, reason)
- {
- new ret = 1;
- PlayerIsSpawned[playerid] = 0;
- if (funcidx("SPT_OnPlayerDisconnect") != -1)
- {
- ret = CallLocalFunction("SPT_OnPlayerDisconnect", "ii",playerid, reason);
- }
- return ret;
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect SPT_OnPlayerDisconnect
- forward SPT_OnPlayerDisconnect(playerid, reason);
- //--------------OnPlayerRequestClass Hook-------------------
- public OnPlayerRequestClass(playerid, classid)
- {
- new ret = 1;
- TextDrawHideForPlayer(playerid,tdWorldTime);
- PlayerIsSpawned[playerid] = 0;
- if (funcidx("SPT_OnPlayerRequestClass") != -1)
- {
- ret = CallLocalFunction("SPT_OnPlayerRequestClass", "ii",playerid, classid);
- }
- return ret;
- }
- #if defined _ALS_OnPlayerRequestClass
- #undef OnPlayerRequestClass
- #else
- #define _ALS_OnPlayerRequestClass
- #endif
- #define OnPlayerRequestClass SPT_OnPlayerRequestClass
- forward SPT_OnPlayerRequestClass(playerid, classid);
- //--------------OnPlayerSpawn Hook-------------------
- public OnPlayerSpawn(playerid)
- {
- new ret = 1;
- PlayerIsSpawned[playerid] = 1;
- SetPlayerTime(playerid,Hour,Minute);
- TextDrawShowForPlayer(playerid,tdWorldTime);
- if (funcidx("SPT_OnPlayerSpawn") != -1)
- {
- ret = CallLocalFunction("SPT_OnPlayerSpawn", "i",playerid);
- }
- return ret;
- }
- #if defined _ALS_OnPlayerSpawn
- #undef OnPlayerSpawn
- #else
- #define _ALS_OnPlayerSpawn
- #endif
- #define OnPlayerSpawn SPT_OnPlayerSpawn
- forward SPT_OnPlayerSpawn(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement