-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshavit-ghost.sp
614 lines (513 loc) · 16.7 KB
/
shavit-ghost.sp
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "CodingCow"
#define PLUGIN_VERSION "1.3"
// Version 1.0 - First release by Cow
// Version 1.1 - Added checks for replay data
// Version 1.2 - Added menu option to change box size
// Version 1.3 - Added beam color change option
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <clientprefs>
#include <shavit>
#pragma newdecls required
public Plugin myinfo =
{
name = "Ghost",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = ""
};
int g_BeamSprite;
ArrayList GhostData[MAXPLAYERS + 1];
ArrayList GhostData2[MAXPLAYERS + 1];
bool ghost[MAXPLAYERS + 1];
int ghostMode[MAXPLAYERS + 1];
bool recording[MAXPLAYERS + 1];
int cmdNum[MAXPLAYERS + 1];
int beamColor[MAXPLAYERS + 1][4];
bool beamColorVariety[MAXPLAYERS + 1];
int boxSize[MAXPLAYERS + 1];
Handle g_hGhostCookie;
Handle g_hGhostModeCookie;
Handle g_hTrailCookie;
Handle g_hBoxSizeCookie;
public void OnPluginStart()
{
g_hGhostCookie = RegClientCookie("GhostTrail", "Ghost Trails", CookieAccess_Protected);
g_hTrailCookie = RegClientCookie("TrailColor", "Ghost Trail Color", CookieAccess_Protected);
g_hGhostModeCookie = RegClientCookie("GhostMode", "Ghost Trail Mode", CookieAccess_Protected);
g_hBoxSizeCookie = RegClientCookie("BoxSize", "BoxSize", CookieAccess_Protected);
RegConsoleCmd("sm_ghost", ghostToggle);
RegConsoleCmd("sm_beam", BeamMenu);
RegAdminCmd("sm_ghostusers", getUsers, ADMFLAG_ROOT);
for (int i = 0; i <= MaxClients; i++)
{
delete GhostData[i];
GhostData[i] = new ArrayList(4);
delete GhostData2[i];
GhostData2[i] = new ArrayList(4);
ghost[i] = false;
recording[i] = false;
cmdNum[i] = 0;
beamColor[i] = { 255, 255, 255, 255 };
boxSize[i] = 14;
}
CreateTimer(300.0, advertise, _, TIMER_REPEAT);
}
public void OnConfigsExecuted()
{
g_BeamSprite = PrecacheModel("sprites/laserbeam.vmt");
}
public void OnClientCookiesCached(int client)
{
char cookieValue[32];
GetClientCookie(client, g_hGhostCookie, cookieValue, sizeof(cookieValue));
ghost[client] = view_as<bool>(StringToInt(cookieValue));
char cookieValue2[32];
GetClientCookie(client, g_hTrailCookie, cookieValue2, sizeof(cookieValue2));
if(StrEqual(cookieValue2, "Red"))
beamColor[client] = { 255, 0, 0, 255 };
else if(StrEqual(cookieValue2, "Green"))
beamColor[client] = { 0, 255, 0, 255 };
else if(StrEqual(cookieValue2, "Blue"))
beamColor[client] = { 0, 0, 255, 255 };
else if(StrEqual(cookieValue2, "Variety"))
{
beamColor[client] = { 122, 122, 122, 255 };
beamColorVariety[client] = true;
}
else
beamColor[client] = { 255, 255, 255, 255 };
if(StrEqual(cookieValue2, "Variety"))
{
beamColorVariety[client] = true;
}
else
{
beamColorVariety[client] = false;
}
char cookieValue3[32];
GetClientCookie(client, g_hGhostModeCookie, cookieValue3, sizeof(cookieValue3));
ghostMode[client] = StringToInt(cookieValue3);
char cookieValue4[32];
GetClientCookie(client, g_hBoxSizeCookie, cookieValue4, sizeof(cookieValue4));
boxSize[client] = StringToInt(cookieValue4);
}
public void OnClientPutInServer(int client)
{
delete GhostData[client];
GhostData[client] = new ArrayList(4);
delete GhostData2[client];
GhostData2[client] = new ArrayList(4);
recording[client] = false;
cmdNum[client] = 0;
}
public void OnClientDisconnect(int client)
{
delete GhostData[client];
GhostData[client] = new ArrayList(4);
delete GhostData2[client];
GhostData2[client] = new ArrayList(4);
ghost[client] = false;
recording[client] = false;
cmdNum[client] = 0;
ghostMode[client] = 0;
}
public Action advertise(Handle timer)
{
PrintToChatAll("[\x0CGhost\x01] type \x04!ghost \x01to race your personal best or the world record!");
}
public Action getUsers(int client, int args)
{
for (int i = 0; i <= MaxClients; i++)
{
if(ghost[i])
PrintToConsole(client, "%N | Ghost Enabled | %s", i, (ghostMode[i] == 0 ? "Personal Best" : "World Record"));
}
PrintToChat(client, "[\x0CGhost\x01] users logged in \x02Console");
return Plugin_Handled;
}
public Action ghostToggle(int client, int args)
{
Menu m = new Menu(ghostMenu);
m.SetTitle("Ghost Menu");
m.AddItem("Enable/Disable", "Enable/Disable");
m.AddItem("Beam Color", "Beam Color");
m.AddItem("Mode", (ghostMode[client] == 0 ? "Mode: Personal Best" : "Mode: World Record"));
m.AddItem("Increase Box Size", "Increase Box Size");
m.AddItem("Decrease Box Size", "Decrease Box Size");
m.ExitButton = true;
m.Display(client, 0);
return Plugin_Handled;
}
public int ghostMenu(Menu menu, MenuAction action, int client, int param2)
{
switch (action)
{
case MenuAction_Select:
{
char info[32];
if(menu.GetItem(param2, info, sizeof(info)))
{
if(StrEqual(info, "Enable/Disable"))
{
ghost[client] = !ghost[client];
SetClientCookie(client, g_hGhostCookie, (ghost[client] ? "1" : "0"));
if(ghost[client])
GhostData[client].Clear();
else
cmdNum[client] = 0;
PrintToChat(client, "[\x0CGhost\x01] Ghost: %s", (ghost[client] ? "\x04Enabled" : "\x02Disabled"));
}
else if(StrEqual(info, "Beam Color"))
{
BeamMenu(client, 0);
return;
}
else if(StrEqual(info, "Mode"))
{
if(ghostMode[client] == 0)
{
ghostMode[client] = 1;
ArrayList ar = Shavit_GetReplayFrames(Shavit_GetBhopStyle(client), Shavit_GetClientTrack(client), false);
if (ar != null) {
GhostData2[client] = ar.Clone();
}
else {
PrintToChat(client, "[\x0CGhost\x01] No replay data. Complete the map to create a replay.");
GhostData2[client].Clear();
}
}
else
{
ghostMode[client] = 0;
GhostData2[client].Clear();
}
SetClientCookie(client, g_hGhostModeCookie, (ghostMode[client] == 0 ? "0" : "1"));
PrintToChat(client, "[\x0CGhost\x01] Ghost Mode: %s", (ghostMode[client] == 0 ? "\x04Personal Best" : "\x0EWorld Record"));
if(ghostMode[client] == 0)
PrintToChat(client, "[\x0CGhost\x01] Complete the map and a Ghost will appear.");
}
else if(StrEqual(info, "Increase Box Size"))
{
if (boxSize[client] <= 62)
{
boxSize[client] += 2;
char newSize[32];
IntToString(boxSize[client], newSize, sizeof(newSize));
SetClientCookie(client, g_hBoxSizeCookie, newSize);
PrintToChat(client, "[\x0CGhost\x01] Box size increased from: %d to %d", boxSize[client] - 2, boxSize[client]);
}
else
{
PrintToChat(client, "[\x0CGhost\x01] \x07Box is too big to increase size.");
}
}
else if(StrEqual(info, "Decrease Box Size"))
{
if (boxSize[client] >= 4)
{
boxSize[client] -= 2;
char newSize[32];
IntToString(boxSize[client], newSize, sizeof(newSize));
SetClientCookie(client, g_hBoxSizeCookie, newSize);
PrintToChat(client, "[\x0CGhost\x01] Box size decreased from: %d to %d", boxSize[client] + 2, boxSize[client]);
}
else
{
PrintToChat(client, "[\x0CGhost\x01] \x07Box is too small to decrease size.");
}
}
ghostToggle(client, 0);
}
}
case MenuAction_End:
{
delete menu;
}
}
}
public Action BeamMenu(int client, int args)
{
Menu m = new Menu(beamColorMenu);
m.SetTitle("Ghost Beam Color");
m.AddItem("Red", "Red");
m.AddItem("Green", "Green");
m.AddItem("Blue", "Blue");
m.AddItem("Variety", "Variety");
m.AddItem("White", "White");
m.ExitButton = true;
m.Display(client, 0);
return Plugin_Handled;
}
public int beamColorMenu(Menu menu, MenuAction action, int client, int param2)
{
switch (action)
{
case MenuAction_Select:
{
char info[16];
if(menu.GetItem(param2, info, sizeof(info)))
{
char text[32];
if(StrEqual(info, "Red"))
{
beamColor[client] = { 255, 0, 0, 255 };
Format(text, sizeof(text), "\x02Red");
}
else if(StrEqual(info, "Green"))
{
beamColor[client] = { 0, 255, 0, 255 };
Format(text, sizeof(text), "\x04Green");
}
else if(StrEqual(info, "Blue"))
{
beamColor[client] = { 0, 0, 255, 255 };
Format(text, sizeof(text), "\x0CBlue");
}
else if(StrEqual(info, "Variety"))
{
beamColor[client] = { 122, 122, 122, 255 };
Format(text, sizeof(text), "\x02Va\x04rie\x0Cty");
}
else if(StrEqual(info, "White"))
{
beamColor[client] = { 255, 255, 255, 255 };
Format(text, sizeof(text), "White");
}
if(StrEqual(info, "Variety"))
{
beamColorVariety[client] = true;
}
else
{
beamColorVariety[client] = false;
}
PrintToChat(client, "[\x0CGhost\x01] Trail Color: %s", text);
SetClientCookie(client, g_hTrailCookie, info);
ghostToggle(client, 0);
}
}
case MenuAction_End:
{
delete menu;
}
}
}
public void Shavit_OnStyleChanged(int client, int oldstyle, int newstyle, int track, bool manual)
{
if(ghost[client] && ghostMode[client] == 1)
{
ArrayList ar = Shavit_GetReplayFrames(newstyle, track, false);
if (ar != null) {
GhostData2[client] = ar.Clone();
}
else {
PrintToChat(client, "[\x0CGhost\x01] No replay data. Complete the map to create a replay.");
GhostData2[client].Clear();
}
}
}
public void Shavit_OnLeaveZone(int client, int type, int track, int id, int entity, int data)
{
if(type == Zone_Start && ghost[client])
{
cmdNum[client] = 0;
recording[client] = true;
}
}
public void Shavit_OnEnterZone(int client, int type, int track, int id, int entity, int data)
{
if(type == Zone_Start && ghost[client])
{
cmdNum[client] = 0;
GhostData[client].Clear();
if(ghostMode[client] == 1)
{
ArrayList ar = Shavit_GetReplayFrames(Shavit_GetBhopStyle(client), Shavit_GetClientTrack(client), false);
if (ar != null) {
GhostData2[client] = ar.Clone();
}
else {
GhostData2[client].Clear();
}
}
}
else if(type == Zone_End && recording[client] && ghost[client] && ghostMode[client] == 0)
{
delete GhostData2[client];
GhostData2[client] = GhostData[client].Clone();
recording[client] = false;
}
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if(IsValidClient(client, true))
{
if(Shavit_InsideZone(client, Zone_Start, -1) || Shavit_InsideZone(client, Zone_End, -1))
return Plugin_Continue;
if(ghost[client] && ghostMode[client] == 0 && recording[client])
{
float pos[3];
GetClientAbsOrigin(client, pos);
float info[4];
info[0] = pos[0];
info[1] = pos[1];
info[2] = pos[2];
info[3] = (GetEntityFlags(client) & FL_ONGROUND ? 0.0 : 1.0);
GhostData[client].PushArray(info);
}
if(ghost[client] && GhostData2[client].Length > 1)
{
if(ghostMode[client] == 0)
{
if(cmdNum[client] > GhostData2[client].Length - 1)
cmdNum[client] = 0;
if(cmdNum[client] > 0 && cmdNum[client] < GhostData2[client].Length)
{
float info[4];
GhostData2[client].GetArray(cmdNum[client], info, sizeof(info));
float pos[3];
pos[0] = info[0];
pos[1] = info[1];
pos[2] = info[2];
// Last Info
float info2[4];
GhostData2[client].GetArray(cmdNum[client] - 1, info2, sizeof(info2));
float last_pos[3];
last_pos[0] = info2[0];
last_pos[1] = info2[1];
last_pos[2] = info2[2];
// SET ORB TO LOCATION
BeamEffect(client, last_pos, pos, 0.7, 1.0, 1.0, beamColor[client], 0.0, 0);
for (int i = 0; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_SPECTATOR && GetEntPropEnt(i, Prop_Send, "m_hObserverTarget") == client)
{
BeamEffect(i, last_pos, pos, 0.7, 1.0, 1.0, beamColor[client], 0.0, 0);
}
}
// If on ground draw square
if(info[3] == 0.0 && info2[3] != 0.0)
{
float square[4][3];
square[0][0] = pos[0] + boxSize[client];
square[0][1] = pos[1] + boxSize[client];
square[0][2] = pos[2];
square[1][0] = pos[0] + boxSize[client];
square[1][1] = pos[1] - boxSize[client];
square[1][2] = pos[2];
square[2][0] = pos[0] - boxSize[client];
square[2][1] = pos[1] - boxSize[client];
square[2][2] = pos[2];
square[3][0] = pos[0] - boxSize[client];
square[3][1] = pos[1] + boxSize[client];
square[3][2] = pos[2];
BeamEffect(client, square[0], square[1], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(client, square[1], square[2], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(client, square[2], square[3], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(client, square[3], square[0], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
if(beamColorVariety[client]) {
ChangeBeamColor(client);
}
for (int i = 0; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_SPECTATOR && GetEntPropEnt(i, Prop_Send, "m_hObserverTarget") == client)
{
BeamEffect(i, square[0], square[1], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(i, square[1], square[2], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(i, square[2], square[3], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(i, square[3], square[0], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
}
}
}
}
cmdNum[client]++;
}
else if(ghostMode[client] == 1)
{
int tickrate = RoundToZero(1.0 / GetTickInterval());
if(cmdNum[client] == 0)
cmdNum[client] = tickrate;
if(cmdNum[client] > GhostData2[client].Length - 1)
cmdNum[client] = tickrate;
if(cmdNum[client] > tickrate && cmdNum[client] < GhostData2[client].Length)
{
float info[8];
GhostData2[client].GetArray(cmdNum[client], info, sizeof(info));
float pos[3];
pos[0] = info[0];
pos[1] = info[1];
pos[2] = info[2];
// Last Info
float info2[8];
GhostData2[client].GetArray(cmdNum[client] - 1, info2, sizeof(info2));
float last_pos[3];
last_pos[0] = info2[0];
last_pos[1] = info2[1];
last_pos[2] = info2[2];
// SET ORB TO LOCATION
BeamEffect(client, last_pos, pos, 0.7, 1.0, 1.0, beamColor[client], 0.0, 0);
for (int i = 0; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_SPECTATOR && GetEntPropEnt(i, Prop_Send, "m_hObserverTarget") == client)
{
BeamEffect(i, last_pos, pos, 0.7, 1.0, 1.0, beamColor[client], 0.0, 0);
}
}
// If on ground draw square
if((info[6] & FL_ONGROUND) && !(info2[6] & FL_ONGROUND))
{
float square[4][3];
square[0][0] = pos[0] + boxSize[client];
square[0][1] = pos[1] + boxSize[client];
square[0][2] = pos[2];
square[1][0] = pos[0] + boxSize[client];
square[1][1] = pos[1] - boxSize[client];
square[1][2] = pos[2];
square[2][0] = pos[0] - boxSize[client];
square[2][1] = pos[1] - boxSize[client];
square[2][2] = pos[2];
square[3][0] = pos[0] - boxSize[client];
square[3][1] = pos[1] + boxSize[client];
square[3][2] = pos[2];
BeamEffect(client, square[0], square[1], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(client, square[1], square[2], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(client, square[2], square[3], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(client, square[3], square[0], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
if(beamColorVariety[client]) {
ChangeBeamColor(client);
}
for (int i = 0; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_SPECTATOR && GetEntPropEnt(i, Prop_Send, "m_hObserverTarget") == client)
{
BeamEffect(i, square[0], square[1], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(i, square[1], square[2], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(i, square[2], square[3], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
BeamEffect(i, square[3], square[0], 0.7, 1.0, 1.0, { 255, 105, 180, 255}, 0.0, 0);
}
}
}
}
cmdNum[client]++;
}
}
}
return Plugin_Continue;
}
public void BeamEffect(int client, float startvec[3], float endvec[3], float life, float width, float endwidth, const color[4], float amplitude, int speed)
{
TE_SetupBeamPoints(startvec, endvec, g_BeamSprite, 0, 0, 66, life, width, endwidth, 0, amplitude, color, speed);
TE_SendToClient(client);
}
public void ChangeBeamColor(int client)
{
beamColor[client][0] = GetRandomInt(0, 255);
beamColor[client][1] = GetRandomInt(0, 255);
beamColor[client][2] = GetRandomInt(0, 255);
beamColor[client][3] = 255;
}