This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bTimes-cp.sp
746 lines (659 loc) · 16.8 KB
/
bTimes-cp.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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
#pragma semicolon 1
#include <bTimes-core>
public Plugin:myinfo =
{
name = "[bTimes] Checkpoints",
author = "blacky, cam",
description = "Checkpoints plugin for the timer",
version = VERSION,
url = URL
}
#include <sdktools>
#include <sourcemod>
#include <bTimes-timer>
#include <bTimes-random>
#include <bTimes-zones>
#include <smlib/entities>
new Float:g_cp[MAXPLAYERS+1][10][3][3];
new g_cpcount[MAXPLAYERS+1];
new bool:g_UsePos[MAXPLAYERS+1] = {true, ...};
new bool:g_UseVel[MAXPLAYERS+1] = {false, ...};
new bool:g_UseAng[MAXPLAYERS+1] = {false, ...};
new g_LastUsed[MAXPLAYERS+1],
bool:g_HasLastUsed[MAXPLAYERS+1];
new g_LastSaved[MAXPLAYERS+1],
bool:g_HasLastSaved[MAXPLAYERS+1];
new bool:g_BlockTpTo[MAXPLAYERS+1][MAXPLAYERS+1];
new String:g_msg_start[128],
String:g_msg_varcol[128],
String:g_msg_textcol[128];
// Cvars
new Handle:g_hAllowCp;
public OnPluginStart(){
if(GetGameType() != GameType_CSGO && GetGameType() != GameType_CSS)
SetFailState("This timer does not support this game (%d)", GetGameType());
// Cvars
g_hAllowCp = CreateConVar("timer_allowcp", "1", "Allows players to use the checkpoint plugin's features.", 0, true, 0.0, true, 1.0);
AutoExecConfig(true, "cp", "timer");
// Commands
RegConsoleCmdEx("sm_cp", SM_CP, "Opens the checkpoint menu.");
RegConsoleCmdEx("sm_checkpoint", SM_CP, "Opens the checkpoint menu.");
RegConsoleCmdEx("sm_tele", SM_Tele, "Teleports you to the specified checkpoint.");
RegConsoleCmdEx("sm_tp", SM_Tele, "Teleports you to the specified checkpoint.");
RegConsoleCmdEx("sm_save", SM_Save, "Saves a new checkpoint.");
RegConsoleCmdEx("sm_tpto", SM_TpTo, "Teleports you to a player.");
RegAdminCmd("sm_goto", SM_GoTo, ADMFLAG_CUSTOM5, "Allows admins to force sm_tpto to a player.");
// Makes FindTarget() work properly
LoadTranslations("common.phrases");
}
public OnClientPutInServer(client)
{
g_cpcount[client] = 0;
for(new i=1; i<=MaxClients; i++)
{
g_BlockTpTo[i][client] = false;
}
}
public OnTimerChatChanged(MessageType, String:Message[])
{
if(MessageType == 0)
{
Format(g_msg_start, sizeof(g_msg_start), Message);
ReplaceMessage(g_msg_start, sizeof(g_msg_start));
}
else if(MessageType == 1)
{
Format(g_msg_varcol, sizeof(g_msg_varcol), Message);
ReplaceMessage(g_msg_varcol, sizeof(g_msg_varcol));
}
else if(MessageType == 2)
{
Format(g_msg_textcol, sizeof(g_msg_textcol), Message);
ReplaceMessage(g_msg_textcol, sizeof(g_msg_textcol));
}
}
public Action:SM_GoTo(client, args)
{
if(IsPlayerAlive(client))
{
if(args == 0)
{
PrintColorText(client, "%s%sYou must specify a user.",
g_msg_start,
g_msg_textcol);
return Plugin_Handled;
}
else
{
decl String:argString[250];
GetCmdArgString(argString, sizeof(argString));
new target = FindTarget(client, argString, false, false);
if(client != target)
{
if(target != -1)
{
if(IsPlayerAlive(target))
{
new Float:pos[3];
GetEntPropVector(target, Prop_Send, "m_vecOrigin", pos);
StopTimer(client);
TeleportEntity(client, pos, NULL_VECTOR, NULL_VECTOR);
}else{
PrintColorText(client, "%s%sTarget not alive.",
g_msg_start,
g_msg_textcol);
}
}else{
PrintColorText(client, "%s%sTarget not found.",
g_msg_start,
g_msg_textcol);
}
}else{
PrintColorText(client, "%s%sYou can't target yourself.",
g_msg_start,
g_msg_textcol);
}
}
}
return Plugin_Handled;
}
public Action:SM_TpTo(client, args)
{
if(GetConVarBool(g_hAllowCp))
{
if(IsPlayerAlive(client))
{
if(args == 0)
{
OpenTpToMenu(client);
}
else
{
decl String:argString[250];
GetCmdArgString(argString, sizeof(argString));
new target = FindTarget(client, argString, false, false);
if(client != target)
{
if(target != -1)
{
if(IsPlayerAlive(target))
{
if(IsFakeClient(target))
{
new Float:pos[3];
GetEntPropVector(target, Prop_Send, "m_vecOrigin", pos);
StopTimer(client);
TeleportEntity(client, pos, NULL_VECTOR, NULL_VECTOR);
}
else
{
SendTpToRequest(client, target);
}
}
else
{
PrintColorText(client, "%s%sTarget not alive.",
g_msg_start,
g_msg_textcol);
}
}
else
{
OpenTpToMenu(client);
}
}
else
{
PrintColorText(client, "%s%sYou can't target yourself.",
g_msg_start,
g_msg_textcol);
}
}
}
else
{
PrintColorText(client, "%s%sYou must be alive to use the sm_tpto command.",
g_msg_start,
g_msg_textcol);
}
}
return Plugin_Handled;
}
OpenTpToMenu(client)
{
new Handle:menu = CreateMenu(Menu_Tpto);
SetMenuTitle(menu, "Select player to teleport to");
decl String:sTarget[MAX_NAME_LENGTH], String:sInfo[8];
for(new target = 1; target <= MaxClients; target++)
{
if(target != client && IsClientInGame(target))
{
GetClientName(target, sTarget, sizeof(sTarget));
IntToString(GetClientUserId(target), sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, sTarget);
}
}
SetMenuExitBackButton(menu, true);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public Menu_Tpto(Handle:menu, MenuAction:action, client, param2)
{
if(action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
new target = GetClientOfUserId(StringToInt(info));
if(target != 0)
{
if(IsFakeClient(target))
{
new Float:vPos[3];
Entity_GetAbsOrigin(target, vPos);
StopTimer(client);
TeleportEntity(client, vPos, NULL_VECTOR, NULL_VECTOR);
}
else
{
SendTpToRequest(client, target);
}
}
else
{
PrintColorText(client, "%s%sTarget not in game.",
g_msg_start,
g_msg_textcol);
}
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
SendTpToRequest(client, target)
{
if(g_BlockTpTo[target][client] == false)
{
new Handle:menu = CreateMenu(Menu_TpRequest);
decl String:sInfo[16];
new UserId = GetClientUserId(client);
SetMenuTitle(menu, "%N wants to teleport to you", client);
Format(sInfo, sizeof(sInfo), "%d;a", UserId);
AddMenuItem(menu, sInfo, "Accept");
Format(sInfo, sizeof(sInfo), "%d;d", UserId);
AddMenuItem(menu, sInfo, "Deny");
Format(sInfo, sizeof(sInfo), "%d;b", UserId);
AddMenuItem(menu, sInfo, "Deny & Block");
DisplayMenu(menu, target, 20);
}
else
{
PrintColorText(client, "%s%s%N %sblocked all tpto requests from you.",
g_msg_start,
g_msg_varcol,
target,
g_msg_textcol);
}
}
public Menu_TpRequest(Handle:menu, MenuAction:action, param1, param2)
{
if(action == MenuAction_Select)
{
decl String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
decl String:sInfoExploded[2][16];
ExplodeString(info, ";", sInfoExploded, 2, 16);
new client = GetClientOfUserId(StringToInt(sInfoExploded[0]));
if(client != 0)
{
if(sInfoExploded[1][0] == 'a') // accept
{
new Float:vPos[3];
Entity_GetAbsOrigin(param1, vPos);
StopTimer(client);
TeleportEntity(client, vPos, NULL_VECTOR, NULL_VECTOR);
PrintColorText(client, "%s%s%N %saccepted your request.",
g_msg_start,
g_msg_varcol,
param1,
g_msg_textcol);
}
else if(sInfoExploded[1][0] == 'd') // deny
{
PrintColorText(client, "%s%s%N %sdenied your request.",
g_msg_start,
g_msg_varcol,
param1,
g_msg_textcol);
}
else if(sInfoExploded[1][0] == 'b') // deny and block
{
g_BlockTpTo[param1][client] = true;
PrintColorText(client, "%s%s%N %sdenied denied your request and blocked future requests from you.",
g_msg_start,
g_msg_varcol,
param1,
g_msg_textcol);
}
}
else
{
PrintColorText(param1, "%s%sThe tp requester is no longer in game.",
g_msg_start,
g_msg_textcol);
}
}
else if(action == MenuAction_End)
CloseHandle(menu);
}
public Action:SM_CP(client, args)
{
if(GetConVarBool(g_hAllowCp))
{
OpenCheckpointMenu(client);
}
return Plugin_Handled;
}
OpenCheckpointMenu(client)
{
new Handle:menu = CreateMenu(Menu_Checkpoint);
SetMenuTitle(menu, "Checkpoint menu");
AddMenuItem(menu, "Save", "Save");
AddMenuItem(menu, "Teleport", "Teleport");
AddMenuItem(menu, "Delete", "Delete");
AddMenuItem(menu, "usepos", g_UsePos[client]?"Use position: Yes":"Use position: No");
AddMenuItem(menu, "usevel", g_UseVel[client]?"Use velocity: Yes":"Use velocity: No");
AddMenuItem(menu, "useang", g_UseAng[client]?"Use angles: Yes":"Use angles: No");
AddMenuItem(menu, "Noclip", "Noclip");
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public Menu_Checkpoint(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
if(StrEqual(info, "Save"))
{
SaveCheckpoint(param1);
OpenCheckpointMenu(param1);
}
else if(StrEqual(info, "Teleport"))
{
OpenTeleportMenu(param1);
}
else if(StrEqual(info, "Delete"))
{
OpenDeleteMenu(param1);
}
else if(StrEqual(info, "usepos"))
{
g_UsePos[param1] = !g_UsePos[param1];
OpenCheckpointMenu(param1);
}
else if(StrEqual(info, "usevel"))
{
g_UseVel[param1] = !g_UseVel[param1];
OpenCheckpointMenu(param1);
}
else if(StrEqual(info, "useang"))
{
g_UseAng[param1] = !g_UseAng[param1];
OpenCheckpointMenu(param1);
}
else if(StrEqual(info, "Noclip"))
{
FakeClientCommand(param1, "sm_practice");
OpenCheckpointMenu(param1);
}
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
OpenTeleportMenu(client)
{
new Handle:menu = CreateMenu(Menu_Teleport);
SetMenuTitle(menu, "Teleport");
AddMenuItem(menu, "lastused", "Last used");
AddMenuItem(menu, "lastsaved", "Last saved");
decl String:tpString[8], String:infoString[8];
for(new i=0; i < g_cpcount[client]; i++)
{
Format(tpString, sizeof(tpString), "CP %d", i+1);
Format(infoString, sizeof(infoString), "%d", i);
AddMenuItem(menu, infoString, tpString);
}
SetMenuExitBackButton(menu, true);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public Menu_Teleport(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
if(StrEqual(info, "lastused"))
{
TeleportToLastUsed(param1);
OpenTeleportMenu(param1);
}
else if(StrEqual(info, "lastsaved"))
{
TeleportToLastSaved(param1);
OpenTeleportMenu(param1);
}
else
{
decl String:infoGuess[8];
for(new i=0; i < g_cpcount[param1]; i++)
{
Format(infoGuess, sizeof(infoGuess), "%d", i);
if(StrEqual(info, infoGuess))
{
TeleportToCheckpoint(param1, i);
OpenTeleportMenu(param1);
break;
}
}
}
}
else if (action == MenuAction_Cancel)
{
if(param2 == MenuCancel_ExitBack)
{
OpenCheckpointMenu(param1);
}
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
OpenDeleteMenu(client)
{
if(g_cpcount[client] != 0)
{
new Handle:menu = CreateMenu(Menu_Delete);
SetMenuTitle(menu, "Delete");
decl String:display[16], String:info[8];
for(new i=0; i < g_cpcount[client]; i++)
{
Format(display, sizeof(display), "Delete %d", i+1);
IntToString(i, info, sizeof(info));
AddMenuItem(menu, info, display);
}
SetMenuExitBackButton(menu, true);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
else
{
PrintColorText(client, "%s%sYou have no checkpoints saved.",
g_msg_start,
g_msg_textcol);
OpenCheckpointMenu(client);
}
}
public Menu_Delete(Handle:menu, MenuAction:action, param1, param2)
{
if(action == MenuAction_Select)
{
decl String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
DeleteCheckpoint(param1, StringToInt(info));
OpenDeleteMenu(param1);
}
else if(action == MenuAction_Cancel)
{
if(param2 == MenuCancel_ExitBack)
{
OpenCheckpointMenu(param1);
}
}
else if(action == MenuAction_End)
CloseHandle(menu);
}
public Action:SM_Tele(client, args)
{
if(args != 0)
{
decl String:sArg[255];
GetCmdArgString(sArg, sizeof(sArg));
new checkpoint = StringToInt(sArg) - 1;
TeleportToCheckpoint(client, checkpoint);
}
else
{
ReplyToCommand(client, "[SM] Usage: sm_tele <Checkpoint number>");
}
return Plugin_Handled;
}
public Action:SM_Save(client, argS)
{
SaveCheckpoint(client);
return Plugin_Handled;
}
SaveCheckpoint(client)
{
if(GetConVarBool(g_hAllowCp))
{
if(g_cpcount[client] < 10)
{
Entity_GetAbsOrigin(client, g_cp[client][g_cpcount[client]][0]);
Entity_GetAbsVelocity(client, g_cp[client][g_cpcount[client]][1]);
GetClientEyeAngles(client, g_cp[client][g_cpcount[client]][2]);
g_HasLastSaved[client] = true;
g_LastSaved[client] = g_cpcount[client];
g_cpcount[client]++;
PrintColorText(client, "%s%sCheckpoint %s%d%s saved.",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
g_cpcount[client],
g_msg_textcol);
}
else
{
PrintColorText(client, "%s%sYou have too many checkpoints.",
g_msg_start,
g_msg_textcol);
}
}
}
DeleteCheckpoint(client, cpnum)
{
if(0 <= cpnum <= g_cpcount[client])
{
for(new i=cpnum+1; i<10; i++)
for(new i2=0; i2<3; i2++)
for(new i3=0; i3<3; i3++)
g_cp[client][i-1][i2][i3] = g_cp[client][i][i2][i3];
g_cpcount[client]--;
if(cpnum == g_LastUsed[client] || g_cpcount[client] < g_LastUsed[client])
g_HasLastUsed[client] = false;
else if(cpnum < g_LastUsed[client])
g_LastUsed[client]--;
if(cpnum == g_LastSaved[client] || g_cpcount[client] < g_LastSaved[client])
g_HasLastSaved[client] = false;
else if(cpnum < g_LastSaved[client])
g_LastSaved[client]--;
}
else
{
PrintColorText(client, "%s%sCheckpoint %s%d%s doesn't exist",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
cpnum+1,
g_msg_textcol);
}
}
TeleportToCheckpoint(client, cpnum)
{
if(GetConVarBool(g_hAllowCp))
{
if(0 <= cpnum < g_cpcount[client])
{
new Float:vPos[3];
for(new i; i < 3; i++)
vPos[i] = g_cp[client][cpnum][0][i];
vPos[2] += 5.0;
StopTimer(client);
//SetEntityFlags(client, GetEntityFlags(client) & ~FL_ONGROUND);
// Prevent using velocity with checkpoints inside start zones so players can't abuse it to beat times
if(g_UsePos[client] == false)
{
new String:styleAbbreviation[32];
GetStyleAbbr(GetClientStyle(client), styleAbbreviation, sizeof(styleAbbreviation), true);
new Float:vClientPos[3];
Entity_GetAbsOrigin(client, vClientPos);
if(StrEqual(styleAbbreviation, "ps")){
TeleportEntity(client,
g_UsePos[client]?g_cp[client][cpnum][0]:NULL_VECTOR,
g_UseAng[client]?g_cp[client][cpnum][2]:NULL_VECTOR,
g_UseVel[client]?g_cp[client][cpnum][1]:NULL_VECTOR);
}
else if(Timer_InsideZone(client, MAIN_START) != -1 || Timer_InsideZone(client, BONUS_START) != -1)
{
TeleportEntity(client,
g_UsePos[client]?g_cp[client][cpnum][0]:NULL_VECTOR,
g_UseAng[client]?g_cp[client][cpnum][2]:NULL_VECTOR,
Float:{0.0, 0.0, 0.0});
}
else
{
TeleportEntity(client,
g_UsePos[client]?g_cp[client][cpnum][0]:NULL_VECTOR,
g_UseAng[client]?g_cp[client][cpnum][2]:NULL_VECTOR,
g_UseVel[client]?g_cp[client][cpnum][1]:NULL_VECTOR);
}
}
else
{
new String:styleAbbreviation[32];
GetStyleAbbr(GetClientStyle(client), styleAbbreviation, sizeof(styleAbbreviation), true);
if(StrEqual(styleAbbreviation, "ps")){
TeleportEntity(client,
g_UsePos[client]?g_cp[client][cpnum][0]:NULL_VECTOR,
g_UseAng[client]?g_cp[client][cpnum][2]:NULL_VECTOR,
g_UseVel[client]?g_cp[client][cpnum][1]:NULL_VECTOR);
}
else if(!Timer_IsPointInsideZone(vPos, MAIN_START, 0) && !Timer_IsPointInsideZone(vPos, BONUS_START, 0))
{
TeleportEntity(client,
g_UsePos[client]?g_cp[client][cpnum][0]:NULL_VECTOR,
g_UseAng[client]?g_cp[client][cpnum][2]:NULL_VECTOR,
g_UseVel[client]?g_cp[client][cpnum][1]:NULL_VECTOR);
}
else
{
TeleportEntity(client,
g_UsePos[client]?g_cp[client][cpnum][0]:NULL_VECTOR,
g_UseAng[client]?g_cp[client][cpnum][2]:NULL_VECTOR,
Float:{0.0, 0.0, 0.0});
}
}
g_HasLastUsed[client] = true;
g_LastUsed[client] = cpnum;
}
else
{
PrintColorText(client, "%s%sCheckpoint %s%d%s doesn't exist",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
cpnum+1,
g_msg_textcol);
}
}
}
TeleportToLastUsed(client)
{
if(GetConVarBool(g_hAllowCp))
{
if(g_HasLastUsed[client] == true)
{
TeleportToCheckpoint(client, g_LastUsed[client]);
}
else
{
PrintColorText(client, "%s%sYou have no last used checkpoint.",
g_msg_start,
g_msg_textcol);
}
}
}
TeleportToLastSaved(client)
{
if(GetConVarBool(g_hAllowCp))
{
if(g_HasLastSaved[client] == true)
{
TeleportToCheckpoint(client, g_LastSaved[client]);
}
else
{
PrintColorText(client, "%s%sYou have no last saved checkpoint.",
g_msg_start,
g_msg_textcol);
}
}
}