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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
//############################################################################
//# #
//# GM scheduled broadcasts #
//# #
//############################################################################
// $@GMSA_STATUS values:
// 0: Broadcasts not running
// 1: Broadcasts running
// $@GMSA_NAME$: the GM/Admin who created the broadcast, if any
// $@GMSA_MSG$: the message to be broadcasted
// $@GMSA_MAX: the number of times the broadcast will be performed, if > 0
// $@GMSA_TICK: broadcast the message every $@GMSA_TICK hours
// $@GMSA_CURRENT_TICK: internal counter incremented every hour
017-9.gat,26,24,0|script|Stone Board|145
{
if (getgmlevel() < 30)
goto L_Close;
if ($@GMSA_STATUS)
goto L_InfoBroadcast;
goto L_PrepareBroadcast;
L_InfoBroadcast:
set @next_broadcast_ts, (3600000*($@GMSA_TICK - $@GMSA_CURRENT_TICK) - getnpctimer(0))/1000;
set @next_broadcast_h, @next_broadcast_ts/3600;
set @next_broadcast_m, (@next_broadcast_ts - @next_broadcast_h*3600)/60;
mes "[GM Scheduled Broadcasts Board]";
mes $@GMSA_NAME$ + " scheduled the current message, every " + $@GMSA_TICK + " hour(s):";
mes $@GMSA_MSG$;
next;
if (@next_broadcast_h > 0)
mes "The next broadcast will happen in " + @next_broadcast_h + " hour(s) and " + @next_broadcast_m + " minute(s).";
if (@next_broadcast_h == 0)
mes "The next broadcast will happen in " + @next_broadcast_m + " minute(s).";
next;
set @next_broadcast_ts, 0;
set @next_broadcast_h, 0;
set @next_broadcast_m, 0;
mes "What do you want to do?";
menu
"Nothing.", L_Close,
"Nothing but... what is this?", L_Help,
"Stop broadcasting.", L_StopBroadcast,
"Trigger manually the current broadcast.", L_ManualBroadcast;
L_PrepareBroadcast:
callsub S_Help;
next;
mes "There is no broadcast scheduled.";
mes "Do you want to create one?";
menu
"No.", L_Close,
"Yes.", L_CreateBroadcast;
L_CreateBroadcast:
mes "[GM Scheduled Broadcasts Board]";
mes "Enter the message to broadcast:";
input $@GMSA_MSG$;
if ($@GMSA_MSG$ == "")
goto L_InvalidBroadcastMessage;
next;
mes "[GM Scheduled Broadcasts Board]";
mes "The message will be broadcasted every X hour(s). Enter X:";
input $@GMSA_TICK;
if ($@GMSA_TICK < 1)
goto L_InvalidBroadcastTick;
next;
mes "[GM Scheduled Broadcasts Board]";
mes "If you want the message to be broadcasted a limited number of times, enter its value. Keep 0 otherwise:";
input $@GMSA_MAX;
next;
mes "[GM Scheduled Broadcasts Board]";
if ($@GMSA_MAX == 0)
mes "The current message will be broadcasted every " + $@GMSA_TICK + " hour(s):";
if ($@GMSA_MAX > 0)
mes "The current message will be broadcasted every " + $@GMSA_TICK + " hour(s), up to " + $@GMSA_MAX + " times:";
mes $@GMSA_MSG$;
next;
mes "Is this correct?";
menu
"No. I'll retry.", L_CreateBroadcast,
"No", L_Close,
"Yes. Broadcast this. (the first broadcast will happen in " + $@GMSA_TICK + " hour(s).)", L_StartBroadcast,
"Yes. Broadcast this, and make an extra broadcast right now.", L_StartBroadcast2;
L_InvalidBroadcastMessage:
mes "[GM Scheduled Broadcasts Board]";
mes "The message can't be empty. Please retry.";
goto L_CreateBroadcast;
L_InvalidBroadcastTick:
mes "[GM Scheduled Broadcasts Board]";
mes "You obviously can't repeat a message every 0 hours. Please retry.";
goto L_CreateBroadcast;
L_Help:
callsub S_Help;
goto L_Close;
S_Help:
mes "[GM Scheduled Broadcasts Board]";
mes "This board allows a GM to schedule a message to be broadcast every X hours.";
mes "Only one broadcast can be scheduled at a time.";
return;
S_PerformBroadcast:
announce $@GMSA_MSG$, 0;
return;
L_ManualBroadcast:
callsub S_PerformBroadcast;
mes "Done.";
goto L_Close;
L_StopBroadcast:
callsub S_StopBroadcast;
mes "Done.";
goto L_Close;
S_StopBroadcast:
stopnpctimer;
setnpctimer 0;
set $@GMSA_STATUS, 0;
set $@GMSA_NAME$, "";
set $@GMSA_MSG$, "";
set $@GMSA_TICK, 0;
set $@GMSA_MAX, 0;
set $@GMSA_CURRENT_TICK, 0;
return;
L_StartBroadcast2:
if ($@GMSA_STATUS == 1)
goto L_Abort;
callsub S_PerformBroadcast;
goto L_StartBroadcast;
L_StartBroadcast:
if ($@GMSA_STATUS == 1)
goto L_Abort;
set $@GMSA_STATUS, 1;
set $@GMSA_NAME$, strcharinfo(0);
set $@GMSA_CURRENT_TICK, 0;
initnpctimer;
mes "Done.";
goto L_Close;
L_Abort:
mes "[GM Scheduled Broadcasts Board]";
mes $@GMSA_NAME$ + " has created a scheduled broadcast just before you, hence yours will abort.";
goto L_Close;
L_Close:
close;
OnTimer3600000:
set $@GMSA_CURRENT_TICK, $@GMSA_CURRENT_TICK + 1;
setnpctimer 0;
if ($@GMSA_CURRENT_TICK != $@GMSA_TICK)
end;
callsub S_PerformBroadcast;
set $@GMSA_CURRENT_TICK, 0;
set $@GMSA_MAX, $@GMSA_MAX - 1;
if ($@GMSA_MAX != 0)
end;
callsub S_StopBroadcast;
end;
}
|