-
Notifications
You must be signed in to change notification settings - Fork 1
/
realtime_clock.pwn
92 lines (73 loc) · 1.69 KB
/
realtime_clock.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#define FILTERSCRIPT
#include <a_samp>
#include <realtime-clock>
new
Text:g_TDClock
;
void:SetClock(hour, minute)
{
new
timestr[8]
;
format(timestr, sizeof(timestr), "%02d:%02d", hour, minute);
TextDrawSetString(g_TDClock, timestr);
}
ShowClock(playerid)
{
if (!IsPlayerConnected(playerid))
{
return 0;
}
return TextDrawShowForPlayer(playerid, g_TDClock);
}
ShowClockToAllPlayers()
{
return TextDrawShowForAll(g_TDClock);
}
HideClockToAllPlayers()
{
return TextDrawHideForAll(g_TDClock);
}
public OnFilterScriptInit()
{
// This design of textdraw picked from filterscript 'gl_realtime'.
g_TDClock = TextDrawCreate(605.0, 25.0, "00:00");
TextDrawUseBox(g_TDClock, 0);
TextDrawFont(g_TDClock, 3);
TextDrawSetShadow(g_TDClock, 0); // no shadow
TextDrawSetOutline(g_TDClock, 2); // thickness 1
TextDrawBackgroundColor(g_TDClock, 0x000000FF);
TextDrawColor(g_TDClock, 0xFFFFFFFF);
TextDrawAlignment(g_TDClock, 3);
TextDrawLetterSize(g_TDClock, 0.5, 1.5);
// Set interval and don't start the timer first.
RealTime_SetInterval(10000, false);
// Sync realtime with server time.
RealTime_Sync();
ShowClockToAllPlayers();
SetClock(RealTime_GetHour(), RealTime_GetMinute());
return 1;
}
public OnFilterScriptExit()
{
RealTime_StopTime();
HideClockToAllPlayers();
return 1;
}
public OnPlayerConnect(playerid)
{
ShowClock(playerid);
SetPlayerTime(playerid, RealTime_GetHour(), RealTime_GetMinute());
return 1;
}
public OnWorldTimeUpdate(hour, minute)
{
SetClock(hour, minute);
// Update the worldtime's server info.
new
str[16]
;
format(str, sizeof(str), "worldtime %02d:%02d", hour, minute);
SendRconCommand(str);
return 1;
}