-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmafk.gsc
423 lines (335 loc) · 12.2 KB
/
mafk.gsc
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/*
MustBeAFK
A T6 Zombies AFK System by MustBeLeaving
You can find this script at https://github.com/garryspins/mustbeafk
Requires:
t6-gsc-utils (https://github.com/fedddddd/t6-gsc-utils)
DVars:
mafk_name [str = "[^6MAfk^7]"]- What text should be shown before chat messages?
mafk_prefix [str = ".afk"] - What should the prefix be for the chat commands?
mafk_burps [bool = 1] - Should the player burp when the afk timer is up?
mafk_hud [bool = 1] - Should the message saying youre afk be shown on screen?
mafk_user_times [bool = 0] - Should the user be able to specify a time to go afk for?
mafk_max_time [float = 15] - If user_times, what should the max time allowed be in minutes?
mafk_def_time [float = 15] - If user_times, what should the default time be if none is specified?
mafk_time [float = 15] - If not user_times, what should the afk time be? if 0 then time is infinite.
mafk_max_end [bool = 0] - End the game if everyone is either down or afk?
mafk_cooldown [float = 15] - How many minutes should you have to wait before using afk again.
Conkley has edited this to replace createServerFontString with client sided font string instead.
*/
#include maps\mp\_utility;
#include maps\mp\gametypes_zm\_hud_util;
// you know
init() {
level.mafk_name = getDvarStringDefault("mafk_name", "[^6MAfk^7]");
level.mafk_prefix = getDvarStringDefault("mafk_prefix", ".afk" );
level.mafk_burps = getDvarIntDefault("mafk_burps", 1) == 1;
level.mafk_hud = getDvarIntDefault("mafk_hud", 1) == 1;
level.mafk_user_times = getDvarIntDefault("mafk_user_times", 0) == 1;
level.mafk_max_time = getDvarFloatDefault("mafk_max_time", 15);
level.mafk_def_time = getDvarFloatDefault("mafk_def_time", 15);
level.mafk_time = getDvarFloatDefault("mafk_time", 15);
level.mafk_infinite = level.mafk_time == 0;
level.mafk_max_end = getDVarIntDefault("mafk_max_end", 0) == 1;
level.mafk_cooldown = (getDvarFloatDefault("mafk_cooldown", 15) * 60) * 1000;
onPlayerSay(::hook_chat);
if (level.mafk_max_end) {
level thread watchAllDownOrAFK();
}
if (level.mafk_cooldown != 0) {
level thread watchCooldown();
}
}
// a default string dvar getter
// since this doesnt exist anywhere in the std
getDvarStringDefault(dvar, def) {
value = GetDVar(dvar);
if (value != "") {
return value;
}
return def;
}
// trims the whitespace around a string
// only really used once but still
strtrim(str) {
padl = 0;
padr = 0;
for (i = 0; i < str.size; i++) {
if (str[i] == " ") {
padl = i;
} else {
break;
}
}
for (i = 0; i < str.size; i++) {
if (str[str.size - i] == " ") {
padr = i;
} else {
break;
}
}
return getSubStr(str, padl, str.size - padr);
}
// this is manual modulo
// you dont have to tell me how stupid this is, i know!
// modulo is just refusing to work properly in some places
// and i have absolutely no idea why
// so have fun with this!
mod(num, modby) {
while (num >= modby) {
num = num - modby;
}
return num;
}
// floor function since it doesnt exist for some reason!
// modulo works here?
floor(num) {
return num - (num % 1);
}
// formats a time from ms into a pretty string
// this can be improved obviously
fmttime(ms) {
ms = floor(ms);
seconds = mod(floor(ms / 1000), 60);
minutes = mod(floor((ms / 1000) / 60), 60);
hours = floor(floor((ms / 1000) / 60) / 60);
if (hours) {
text = hours + " hour";
if (hours > 1) {
text = text + "s";
}
if (minutes) {
text = text + " and " + minutes + " minute";
if (minutes > 1) {
text = text + "s";
}
}
return text;
}
if (minutes > 0) {
text = minutes + " minute";
if (minutes > 1) {
text = text + "s";
}
if (seconds) {
text = text + " and " + seconds + " second";
if (seconds > 1) {
text = text + "s";
}
}
return text;
}
if (seconds > 1) {
return seconds + " seconds";
}
if (seconds == 1) {
return seconds + " second";
}
return "no time";
}
// watch for if every player is either down or afk
// if they are then end the game
watchAllDownOrAFK() {
for(;;) {
players = getplayers();
count = 0;
afk = 0;
foreach(ply in players) {
if (!isAlive(ply)) {
count++;
} else if (ply.afk) {
count++;
afk++;
}
}
if ((count == players.size) && (afk != 0)) {
level notify("end_game");
}
wait 5;
}
}
// set the players cooldown
// this is separate from set_afk because
// we like to be a little efficient around these parts
watchCooldown() {
for (;;) {
self waittill("mafk_set", ply, val);
if (val == false) {
ply.mafk_cooldown = getTime() + self.mafk_cooldown;
}
}
}
// burps! but only if we want burps
burp() {
if (level.mafk_burps) {
self maps\mp\zombies\_zm_audio::playerexert("burp");
}
}
// sets the player to be afk or not, accepts a boolean
// this doesnt do anything except set some values on the player
// if you wish to extend anything use the notification
set_afk(value) {
self.afk = value;
self.afk_notify_half = false;
self freezeControls(value);
self.ignoreme = value;
if (value) {
self enableInvulnerability();
} else {
self disableInvulnerability();
}
level notify("mafk_set", self, value);
}
// this is the actual logic behind the chat command
// just a series of checks
quick_afk_on(time) {
// is the player down
if (self.sessionstate == "spectator" || !isAlive(self)) {
self tell(level.mafk_name + " You must be alive to go AFK.");
return false;
}
if (isDefined(self.mafk_cooldown)) {
if (self.mafk_cooldown >= getTime()) {
self tell(level.mafk_name + " You must wait ^4" + fmttime(self.mafk_cooldown - getTime()) + "^7 before going afk again.");
return false;
}
self.mafk_cooldown = undefined;
}
if (self.afk) {
if (isDefined(self.mafk_endtime)) {
self tell(level.mafk_name + " You are already AFK, if you would like to go un-afk type ^2.afk off");
self tell(level.mafk_name + " You have ^4" + fmttime(self.mafk_endtime - getTime()) + "^7 left");
} else {
self tell(level.mafk_name + " You have as long as you want to be afk.");
}
return false;
}
if (level.mafk_infinite && !level.mafk_user_times) {
say(level.mafk_name + " " + self.name + " has gone AFK.");
self set_afk(true);
return false;
}
say(level.mafk_name + " " + self.name + " has gone AFK for ^4" + fmttime((time * 60) * 1000));
self tell(level.mafk_name + " You have gone AFK, if you would like to go un-afk type ^2.afk off");
endtime = getTime() + ((time * 60) * 1000);
self set_afk(true);
self.mafk_endtime = endtime;
self thread check_afk_player(endtime);
if (level.mafk_hud) {
self thread afk_player_hud(endtime, (time * 60) * 1000);
}
self burp();
return false;
}
// what actually hooks onto chat
hook_chat(text, mode) {
text = strtrim(toLower(text));
split = strTok(text, " ");
if (split[0] != level.mafk_prefix) {
return true;
}
if ((split[1] == undefined) || (split[1] == "on")) {
if (level.mafk_user_times) {
return self quick_afk_on(level.mafk_def_time);
} else {
return self quick_afk_on(level.mafk_time);
}
return false;
}
if (level.mafk_user_times) {
switch (split[1]) {
case "off":
self tell(level.mafk_name + " You're back!");
say(level.mafk_name + " " + self.name + " has returned from being AFK!");
self set_afk(false);
self notify("afkcancel");
break;
case "time":
case "left":
if (self.afk) {
self tell(level.mafk_name + " You have ^4" + fmttime(self.mafk_endtime - getTime()) + "^7 left");
} else {
self tell(level.mafk_name + " You are not afk.");
}
break;
case "help":
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " [number]^7 - Turns on afk for the given amount of time (^2" + mintime + "^7 to ^2" + level.mafk_max_time + "^7 minutes)");
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " off^7 - Turns off afk");
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " help^7 - Shows this message");
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " time^7 - Shows how long youre allowed to be afk");
break;
default:
mintime = 1;
time = int(split[1]);
if ((time < mintime) || (time > level.mafk_max_time)) {
self tell(level.mafk_name + " Please give a valid time from ^2" + mintime + "^7 to ^2" + level.mafk_max_time + "^7 minutes");
return false;
}
return self quick_afk_on(time);
}
return false;
}
switch (split[1]) {
case "off":
self tell(level.mafk_name + " You're back!");
say(level.mafk_name + " " + self.name + " has returned from being AFK!");
self set_afk(false);
self notify("afkcancel");
break;
case "time":
case "left":
if (self.afk) {
self tell(level.mafk_name + " You have ^4" + fmttime(self.mafk_endtime - getTime()) + "^7 left");
} else {
self tell(level.mafk_name + " You are not afk.");
}
break;
case "help":
default:
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " on^7 - Turns on afk");
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " off^7 - Turns off afk");
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " help^7 - Shows this message");
self tell(level.mafk_name + " ^2" + level.mafk_prefix + " time^7 - Shows how much longer you can be afk");
}
return false;
}
// runs on the player to check if he should still be afk or not
check_afk_player(endtime) {
// These 3 endon's were moved here for better coding practices
self endon("disconnect");
self endon("afkcancel");
level endon("end_game");
for (;;) {
time = getTime();
if (time >= endtime) {
self set_afk(false);
self tell(level.mafk_name + " Your AFK time has expired!");
self burp();
self.mafk_endtime = undefined;
break;
}
wait 0.25;
}
}
// only runs if mafk_hud is 1
// draws the hud!
afk_player_hud(endtime, time) {
if (isDefined(self.mafk_hud)) {
return;
}
level endon("end_game");
self endon("disconnect");
self.mafk_hud = createFontString("objective", 2);
self.mafk_hud setPoint("CENTER", "TOP", 0, 0);
self.mafk_hud setText("You are currently afk!");
self.mafk_hud.hideWhenInMenu = 1;
for(;;) {
if ((getTime() >= endtime) || !self.afk) {
self.mafk_hud destroy();
break;
}
// logic to make it slowly fade
self.mafk_hud.alpha = ((endtime - getTime()) / time) + 0.75;
wait 0.50;
}
}