-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathshavit-zones.sp
More file actions
5500 lines (4539 loc) · 139 KB
/
shavit-zones.sp
File metadata and controls
5500 lines (4539 loc) · 139 KB
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* shavit's Timer - Map Zones
* by: shavit, GAMMA CASE, rtldg, KiD Fearless, Kryptanyte, carnifex, rumour, BoomShotKapow, Nuko, Technoblazed, Kxnrl, Extan, sh4hrazad, OliviaMourning
*
* This file is part of shavit's Timer (https://github.com/shavitush/bhoptimer)
*
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <sourcemod>
#include <clientprefs>
#include <sdktools>
#include <sdkhooks>
#include <convar_class>
#include <dhooks>
#include <profiler>
#include <shavit/core>
#include <shavit/zones>
#include <shavit/physicsuntouch>
#undef REQUIRE_PLUGIN
#include <adminmenu>
#include <shavit/replay-recorder>
#undef REQUIRE_EXTENSIONS
#include <cstrike>
#include <tf2>
#include <eventqueuefix>
#pragma semicolon 1
#pragma newdecls required
#define DEBUG 0
#define FSOLID_NOT_SOLID 4
#define FSOLID_TRIGGER 8
#define EF_NODRAW 32
#define SOLID_BBOX 2
EngineVersion gEV_Type = Engine_Unknown;
Database gH_SQL = null;
int gI_Driver = Driver_unknown;
bool gB_YouCanLoadZonesNow = false;
char gS_Map[PLATFORM_MAX_PATH];
enum struct zone_settings_t
{
bool bVisible;
int iRed;
int iGreen;
int iBlue;
int iAlpha;
float fWidth;
bool bFlatZone;
bool bUseVanillaSprite;
bool bNoHalo;
int iBeam;
int iHalo;
int iSpeed;
char sBeam[PLATFORM_MAX_PATH];
}
// 0 - nothing
// 1 - wait for E tap to setup first coord
// 2 - wait for E tap to setup second coord
// 3 - confirm
int gI_MapStep[MAXPLAYERS+1];
Handle gH_StupidTimer[MAXPLAYERS+1];
int gI_CurrentTraceEntity = 0;
zone_cache_t gA_EditCache[MAXPLAYERS+1];
int gI_HookListPos[MAXPLAYERS+1];
int gI_ZoneID[MAXPLAYERS+1];
bool gB_WaitingForChatInput[MAXPLAYERS+1];
float gV_WallSnap[MAXPLAYERS+1][3];
bool gB_Button[MAXPLAYERS+1];
float gF_Modifier[MAXPLAYERS+1];
int gI_AdjustAxis[MAXPLAYERS+1];
int gI_GridSnap[MAXPLAYERS+1];
bool gB_SnapToWall[MAXPLAYERS+1];
bool gB_CursorTracing[MAXPLAYERS+1];
int gI_LatestTeleportTick[MAXPLAYERS+1];
// player zone status
int gI_InsideZone[MAXPLAYERS+1][TRACKS_SIZE]; // bit flag
bool gB_InsideZoneID[MAXPLAYERS+1][MAX_ZONES];
// zone cache
zone_settings_t gA_ZoneSettings[ZONETYPES_SIZE][TRACKS_SIZE];
zone_cache_t gA_ZoneCache[MAX_ZONES]; // Vectors will not be inside this array.
int gI_MapZones = 0;
float gV_MapZones_Visual[MAX_ZONES][8][3];
float gV_ZoneCenter[MAX_ZONES][3];
int gI_HighestStage[TRACKS_SIZE];
float gF_CustomSpawn[TRACKS_SIZE][3];
int gI_EntityZone[2048] = {-1, ...};
int gI_LastStage[MAXPLAYERS+1];
char gS_BeamSprite[PLATFORM_MAX_PATH];
char gS_BeamSpriteIgnoreZ[PLATFORM_MAX_PATH];
int gI_BeamSpriteIgnoreZ;
// admin menu
TopMenu gH_AdminMenu = null;
TopMenuObject gH_TimerCommands = INVALID_TOPMENUOBJECT;
// misc cache
bool gB_Late = false;
ConVar sv_gravity = null;
// cvars
Convar gCV_SQLZones = null;
Convar gCV_PrebuiltZones = null;
Convar gCV_ClimbButtons = null;
Convar gCV_Interval = null;
Convar gCV_TeleportToStart = null;
Convar gCV_TeleportToEnd = null;
Convar gCV_AllowDrawAllZones = null;
Convar gCV_UseCustomSprite = null;
Convar gCV_Height = null;
Convar gCV_Offset = null;
Convar gCV_EnforceTracks = null;
Convar gCV_BoxOffset = null;
Convar gCV_ExtraSpawnHeight = null;
Convar gCV_PrebuiltVisualOffset = null;
Convar gCV_ForceTargetnameReset = null;
Convar gCV_ResetTargetnameMain = null;
Convar gCV_ResetTargetnameBonus = null;
Convar gCV_ResetClassnameMain = null;
Convar gCV_ResetClassnameBonus = null;
// handles
Handle gH_DrawVisible = null;
Handle gH_DrawAllZones = null;
bool gB_DrawAllZones[MAXPLAYERS+1];
Cookie gH_DrawAllZonesCookie = null;
// table prefix
char gS_MySQLPrefix[32];
// chat settings
chatstrings_t gS_ChatStrings;
// forwards
Handle gH_Forwards_EnterZone = null;
Handle gH_Forwards_LeaveZone = null;
Handle gH_Forwards_LoadZonesHere = null;
Handle gH_Forwards_StageMessage = null;
// sdkcalls
Handle gH_PhysicsRemoveTouchedList = null;
Handle gH_PassesTriggerFilters = null;
Handle gH_CommitSuicide = null; // sourcemod always finds a way to amaze me
// dhooks
DynamicHook gH_TeleportDhook = null;
// kz support
float gF_ClimbButtonCache[MAXPLAYERS+1][TRACKS_SIZE][2][3]; // 0 - location, 1 - angles
// set start
bool gB_HasSetStart[MAXPLAYERS+1][TRACKS_SIZE];
bool gB_StartAnglesOnly[MAXPLAYERS+1][TRACKS_SIZE];
float gF_StartPos[MAXPLAYERS+1][TRACKS_SIZE][3];
float gF_StartAng[MAXPLAYERS+1][TRACKS_SIZE][3];
// modules
bool gB_Eventqueuefix = false;
bool gB_ReplayRecorder = false;
bool gB_AdminMenu = false;
#define CZONE_VER 'c'
// custom zone stuff
Cookie gH_CustomZoneCookie = null;
int gI_ZoneDisplayType[MAXPLAYERS+1][ZONETYPES_SIZE][TRACKS_SIZE];
int gI_ZoneColor[MAXPLAYERS+1][ZONETYPES_SIZE][TRACKS_SIZE];
int gI_ZoneWidth[MAXPLAYERS+1][ZONETYPES_SIZE][TRACKS_SIZE];
int gI_LastMenuPos[MAXPLAYERS+1];
public Plugin myinfo =
{
name = "[shavit] Map Zones",
author = "shavit, GAMMA CASE, rtldg, KiD Fearless, Kryptanyte, carnifex, rumour, BoomShotKapow, Nuko, Technoblazed, Kxnrl, Extan, sh4hrazad, OliviaMourning",
description = "Map zones for shavit's bhop timer.",
version = SHAVIT_VERSION,
url = "https://github.com/shavitush/bhoptimer"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
// zone natives
CreateNative("Shavit_GetZoneData", Native_GetZoneData);
CreateNative("Shavit_GetZoneFlags", Native_GetZoneFlags);
CreateNative("Shavit_GetStageCount", Native_GetStageCount);
CreateNative("Shavit_InsideZone", Native_InsideZone);
CreateNative("Shavit_InsideZoneGetID", Native_InsideZoneGetID);
CreateNative("Shavit_IsClientCreatingZone", Native_IsClientCreatingZone);
CreateNative("Shavit_ZoneExists", Native_ZoneExists);
CreateNative("Shavit_Zones_DeleteMap", Native_Zones_DeleteMap);
CreateNative("Shavit_SetStart", Native_SetStart);
CreateNative("Shavit_DeleteSetStart", Native_DeleteSetStart);
CreateNative("Shavit_GetClientLastStage", Native_GetClientLastStage);
CreateNative("Shavit_GetZoneTrack", Native_GetZoneTrack);
CreateNative("Shavit_GetZoneType", Native_GetZoneType);
CreateNative("Shavit_GetZoneID", Native_GetZoneID);
CreateNative("Shavit_ReloadZones", Native_ReloadZones);
CreateNative("Shavit_UnloadZones", Native_UnloadZones);
CreateNative("Shavit_GetZoneCount", Native_GetZoneCount);
CreateNative("Shavit_GetZone", Native_GetZone);
CreateNative("Shavit_AddZone", Native_AddZone);
CreateNative("Shavit_RemoveZone", Native_RemoveZone);
// registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins
RegPluginLibrary("shavit-zones");
gB_Late = late;
return APLRes_Success;
}
public void OnPluginStart()
{
LoadTranslations("shavit-common.phrases");
LoadTranslations("shavit-zones.phrases");
// game specific
gEV_Type = GetEngineVersion();
// menu
RegAdminCmd("sm_addzone", Command_Zones, ADMFLAG_RCON, "Opens the mapzones menu.");
RegAdminCmd("sm_zones", Command_Zones, ADMFLAG_RCON, "Opens the mapzones menu.");
RegAdminCmd("sm_mapzones", Command_Zones, ADMFLAG_RCON, "Opens the mapzones menu. Alias of sm_zones.");
RegAdminCmd("sm_delzone", Command_DeleteZone, ADMFLAG_RCON, "Delete a mapzone");
RegAdminCmd("sm_deletezone", Command_DeleteZone, ADMFLAG_RCON, "Delete a mapzone");
RegAdminCmd("sm_deleteallzones", Command_DeleteAllZones, ADMFLAG_RCON, "Delete all mapzones");
RegAdminCmd("sm_modifier", Command_Modifier, ADMFLAG_RCON, "Changes the axis modifier for the zone editor. Usage: sm_modifier <number>");
RegAdminCmd("sm_addspawn", Command_AddSpawn, ADMFLAG_RCON, "Adds a custom spawn location");
RegAdminCmd("sm_delspawn", Command_DelSpawn, ADMFLAG_RCON, "Deletes a custom spawn location");
RegAdminCmd("sm_zoneedit", Command_ZoneEdit, ADMFLAG_RCON, "Modify an existing zone.");
RegAdminCmd("sm_editzone", Command_ZoneEdit, ADMFLAG_RCON, "Modify an existing zone. Alias of sm_zoneedit.");
RegAdminCmd("sm_modifyzone", Command_ZoneEdit, ADMFLAG_RCON, "Modify an existing zone. Alias of sm_zoneedit.");
RegAdminCmd("sm_hookzone", Command_HookZone, ADMFLAG_RCON, "Hook an existing trigger, teleporter, or button.");
RegAdminCmd("sm_tptozone", Command_TpToZone, ADMFLAG_RCON, "Teleport to a zone");
RegAdminCmd("sm_reloadzonesettings", Command_ReloadZoneSettings, ADMFLAG_ROOT, "Reloads the zone settings.");
RegConsoleCmd("sm_beamer", Command_Beamer, "Draw cool beams");
RegConsoleCmd("sm_stages", Command_Stages, "Opens the stage menu. Usage: sm_stages [stage #]");
RegConsoleCmd("sm_stage", Command_Stages, "Opens the stage menu. Usage: sm_stage [stage #]");
RegConsoleCmd("sm_s", Command_Stages, "Opens the stage menu. Usage: sm_s [stage #]");
RegConsoleCmd("sm_set", Command_SetStart, "Set current position as spawn location in start zone.");
RegConsoleCmd("sm_setstart", Command_SetStart, "Set current position as spawn location in start zone.");
RegConsoleCmd("sm_ss", Command_SetStart, "Set current position as spawn location in start zone.");
RegConsoleCmd("sm_sp", Command_SetStart, "Set current position as spawn location in start zone.");
RegConsoleCmd("sm_startpoint", Command_SetStart, "Set current position as spawn location in start zone.");
RegConsoleCmd("sm_deletestart", Command_DeleteSetStart, "Deletes the custom set start position.");
RegConsoleCmd("sm_deletesetstart", Command_DeleteSetStart, "Deletes the custom set start position.");
RegConsoleCmd("sm_delss", Command_DeleteSetStart, "Deletes the custom set start position.");
RegConsoleCmd("sm_delsp", Command_DeleteSetStart, "Deletes the custom set start position.");
RegConsoleCmd("sm_drawallzones", Command_DrawAllZones, "Toggles drawing all zones.");
RegConsoleCmd("sm_drawzones", Command_DrawAllZones, "Toggles drawing all zones.");
gH_DrawAllZonesCookie = new Cookie("shavit_drawallzones", "Draw all zones cookie", CookieAccess_Protected);
RegConsoleCmd("sm_czone", Command_CustomZones, "Customize start and end zone for each track");
RegConsoleCmd("sm_czones", Command_CustomZones, "Customize start and end zone for each track");
RegConsoleCmd("sm_customzones", Command_CustomZones, "Customize start and end zone for each track");
gH_CustomZoneCookie = new Cookie("shavit_customzones", "Cookie for storing custom zone stuff", CookieAccess_Private);
for (int i = 0; i <= 9; i++)
{
char cmd[30];
FormatEx(cmd, sizeof(cmd), "sm_s%d%cGo to stage %d", i, 0, i); // 😈
RegConsoleCmd(cmd, Command_Stages, cmd[6]);
}
// events
if(gEV_Type == Engine_TF2)
{
HookEvent("teamplay_round_start", Round_Start);
}
else
{
HookEvent("round_start", Round_Start);
}
HookEvent("player_spawn", Player_Spawn);
// forwards
gH_Forwards_EnterZone = CreateGlobalForward("Shavit_OnEnterZone", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_LeaveZone = CreateGlobalForward("Shavit_OnLeaveZone", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_LoadZonesHere = CreateGlobalForward("Shavit_LoadZonesHere", ET_Event);
gH_Forwards_StageMessage = CreateGlobalForward("Shavit_OnStageMessage", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell);
// cvars and stuff
gCV_SQLZones = new Convar("shavit_zones_usesql", "1", "Whether to automatically load zones from the database or not.\n0 - Load nothing. (You'll need a plugin to add zones with `Shavit_AddZone()`)\n1 - Load zones from database.", 0, true, 0.0, true, 1.0);
gCV_PrebuiltZones = new Convar("shavit_zones_useprebuilt", "1", "Whether to automatically hook mod_zone_* zone entities.", 0, true, 0.0, true, 1.0);
gCV_ClimbButtons = new Convar("shavit_zones_usebuttons", "1", "Whether to automatically hook climb_* buttons.", 0, true, 0.0, true, 1.0);
gCV_Interval = new Convar("shavit_zones_interval", "1.0", "Interval between each time a mapzone is being drawn to the players.", 0, true, 0.25, true, 5.0);
gCV_TeleportToStart = new Convar("shavit_zones_teleporttostart", "1", "Teleport players to the start zone on timer restart?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_TeleportToEnd = new Convar("shavit_zones_teleporttoend", "1", "Teleport players to the end zone on sm_end?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_AllowDrawAllZones = new Convar("shavit_zones_allowdrawallzones", "1", "Allow players to use !drawallzones to see all zones regardless of zone visibility settings.\n0 - nobody can use !drawallzones\n1 - admins (sm_zones access) can use !drawallzones\n2 - anyone can use !drawallzones", 0, true, 0.0, true, 2.0);
gCV_UseCustomSprite = new Convar("shavit_zones_usecustomsprite", "1", "Use custom sprite for zone drawing?\nSee `configs/shavit-zones.cfg`.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_Height = new Convar("shavit_zones_height", "128.0", "Height to use for the start zone.", 0, true, 0.0, false);
gCV_Offset = new Convar("shavit_zones_offset", "1.0", "When calculating a zone's *VISUAL* box, by how many units, should we scale it to the center?\n0.0 - no downscaling. Values above 0 will scale it inward and negative numbers will scale it outwards.\nAdjust this value if the zones clip into walls.");
gCV_EnforceTracks = new Convar("shavit_zones_enforcetracks", "1", "Enforce zone tracks upon entry?\n0 - allow every zone except for start/end to affect users on every zone.\n1 - require the user's track to match the zone's track.", 0, true, 0.0, true, 1.0);
gCV_BoxOffset = new Convar("shavit_zones_box_offset", "1", "Offset zone trigger boxes to the center of a player's bounding box or the edges.\n0 - triggers when edges of the bounding boxes touch.\n1 - triggers when the center of a player is in a zone.", 0, true, 0.0, true, 1.0);
gCV_ExtraSpawnHeight = new Convar("shavit_zones_extra_spawn_height", "0.0", "YOU DONT NEED TO TOUCH THIS USUALLY. FIX YOUR ACTUAL ZONES.\nUsed to fix some shit prebuilt zones that are in the ground like bhop_strafecontrol");
gCV_PrebuiltVisualOffset = new Convar("shavit_zones_prebuilt_visual_offset", "0", "YOU DONT NEED TO TOUCH THIS USUALLY.\nUsed to fix the VISUAL beam offset for prebuilt zones on a map.\nExample maps you'd want to use 16 on: bhop_tranquility and bhop_amaranthglow");
gCV_ForceTargetnameReset = new Convar("shavit_zones_forcetargetnamereset", "0", "Reset the player's targetname upon timer start?\nRecommended to leave disabled. Enable via per-map configs when necessary.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_ResetTargetnameMain = new Convar("shavit_zones_resettargetname_main", "", "What targetname to use when resetting the player.\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_ResetTargetnameBonus = new Convar("shavit_zones_resettargetname_bonus", "", "What targetname to use when resetting the player (on bonus tracks).\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_ResetClassnameMain = new Convar("shavit_zones_resetclassname_main", "", "What classname to use when resetting the player.\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_ResetClassnameBonus = new Convar("shavit_zones_resetclassname_bonus", "", "What classname to use when resetting the player (on bonus tracks).\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_SQLZones.AddChangeHook(OnConVarChanged);
gCV_Interval.AddChangeHook(OnConVarChanged);
gCV_UseCustomSprite.AddChangeHook(OnConVarChanged);
gCV_Offset.AddChangeHook(OnConVarChanged);
gCV_PrebuiltVisualOffset.AddChangeHook(OnConVarChanged);
gCV_BoxOffset.AddChangeHook(OnConVarChanged);
Convar.AutoExecConfig();
LoadDHooks();
// misc cvars
sv_gravity = FindConVar("sv_gravity");
for(int i = 0; i < ZONETYPES_SIZE; i++)
{
for(int j = 0; j < TRACKS_SIZE; j++)
{
gA_ZoneSettings[i][j].bVisible = true;
gA_ZoneSettings[i][j].iRed = 255;
gA_ZoneSettings[i][j].iGreen = 255;
gA_ZoneSettings[i][j].iBlue = 255;
gA_ZoneSettings[i][j].iAlpha = 255;
gA_ZoneSettings[i][j].fWidth = 2.0;
gA_ZoneSettings[i][j].bFlatZone = false;
}
}
gB_ReplayRecorder = LibraryExists("shavit-replay-recorder");
gB_Eventqueuefix = LibraryExists("eventqueuefix");
gB_AdminMenu = LibraryExists("adminmenu");
if (gB_Late)
{
GetLowercaseMapName(gS_Map); // erm...
Shavit_OnChatConfigLoaded();
Shavit_OnDatabaseLoaded();
if (gB_AdminMenu && (gH_AdminMenu = GetAdminTopMenu()) != null)
{
OnAdminMenuReady(gH_AdminMenu);
}
for(int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i))
{
OnClientConnected(i);
OnClientPutInServer(i);
if (AreClientCookiesCached(i))
{
OnClientCookiesCached(i);
}
}
}
}
}
void KillShavitZoneEnts(const char[] classname)
{
char targetname[64];
int ent = -1;
while ((ent = FindEntityByClassname(ent, classname)) != -1)
{
GetEntPropString(ent, Prop_Data, "m_iName", targetname, sizeof(targetname));
if (StrContains(targetname, "shavit_zones_") == 0)
{
AcceptEntityInput(ent, "Kill");
}
}
}
public void OnPluginEnd()
{
KillShavitZoneEnts("trigger_multiple");
KillShavitZoneEnts("player_speedmod");
}
void LoadDHooks()
{
Handle hGameData = LoadGameConfigFile("shavit.games");
if (hGameData == null)
{
SetFailState("Failed to load shavit gamedata");
}
LoadPhysicsUntouch(hGameData);
if (gEV_Type == Engine_CSGO)
{
StartPrepSDKCall(SDKCall_Entity);
}
else
{
StartPrepSDKCall(SDKCall_Static);
}
if (!PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "PhysicsRemoveTouchedList"))
{
SetFailState("Failed to find \"PhysicsRemoveTouchedList\" signature!");
}
if (gEV_Type != Engine_CSGO)
{
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
}
gH_PhysicsRemoveTouchedList = EndPrepSDKCall();
if (!gH_PhysicsRemoveTouchedList)
{
SetFailState("Failed to create sdkcall to \"PhysicsRemoveTouchedList\"!");
}
StartPrepSDKCall(SDKCall_Entity);
if (!PrepSDKCall_SetFromConf(hGameData, SDKConf_Virtual, "CBaseTrigger::PassesTriggerFilters"))
{
SetFailState("Failed to find \"CBaseTrigger::PassesTriggerFilters\" offset!");
}
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
if (!(gH_PassesTriggerFilters = EndPrepSDKCall()))
{
SetFailState("Failed to create sdkcall to \"CBaseTrigger::PassesTriggerFilters\"!");
}
delete hGameData;
hGameData = LoadGameConfigFile("sdktools.games");
if (hGameData == null)
{
SetFailState("Failed to load sdktools gamedata");
}
int iOffset = GameConfGetOffset(hGameData, "Teleport");
if (iOffset == -1)
{
SetFailState("Couldn't get the offset for \"Teleport\"!");
}
gH_TeleportDhook = new DynamicHook(iOffset, HookType_Entity, ReturnType_Void, ThisPointer_CBaseEntity);
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
gH_TeleportDhook.AddParam(HookParamType_VectorPtr);
if (GetEngineVersion() == Engine_CSGO)
{
gH_TeleportDhook.AddParam(HookParamType_Bool);
}
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hGameData, SDKConf_Virtual, "CommitSuicide");
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_ByValue); // explode
PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_ByValue); // force
if (!(gH_CommitSuicide = EndPrepSDKCall()))
{
SetFailState("Failed to create sdkcall to \"CommitSuicide\"");
}
delete hGameData;
}
public void OnLibraryAdded(const char[] name)
{
if (strcmp(name, "adminmenu") == 0)
{
gB_AdminMenu = true;
}
else if (StrEqual(name, "shavit-replay-recorder"))
{
gB_ReplayRecorder = true;
}
else if (StrEqual(name, "eventqueuefix"))
{
gB_Eventqueuefix = true;
}
}
public void OnLibraryRemoved(const char[] name)
{
if (strcmp(name, "adminmenu") == 0)
{
gB_AdminMenu = false;
gH_AdminMenu = null;
gH_TimerCommands = INVALID_TOPMENUOBJECT;
}
else if (StrEqual(name, "shavit-replay-recorder"))
{
gB_ReplayRecorder = false;
}
else if (StrEqual(name, "eventqueuefix"))
{
gB_Eventqueuefix = false;
}
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if(convar == gCV_Interval)
{
delete gH_DrawVisible;
delete gH_DrawAllZones;
gH_DrawVisible = CreateTimer(gCV_Interval.FloatValue, Timer_DrawZones, 0, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
gH_DrawAllZones = CreateTimer(gCV_Interval.FloatValue, Timer_DrawZones, 1, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
else if (convar == gCV_Offset || convar == gCV_PrebuiltVisualOffset)
{
for (int i = 0; i < gI_MapZones; i++)
{
if ((convar == gCV_Offset && gA_ZoneCache[i].iForm == ZoneForm_Box)
|| (convar == gCV_PrebuiltVisualOffset && gA_ZoneCache[i].iForm == ZoneForm_trigger_multiple))
{
gV_MapZones_Visual[i][0] = gA_ZoneCache[i].fCorner1;
gV_MapZones_Visual[i][7] = gA_ZoneCache[i].fCorner2;
CreateZonePoints(gV_MapZones_Visual[i], convar == gCV_PrebuiltVisualOffset);
}
}
}
else if(convar == gCV_UseCustomSprite && !StrEqual(oldValue, newValue))
{
LoadZoneSettings();
}
else if (convar == gCV_BoxOffset)
{
for (int i = 0; i < gI_MapZones; i++)
{
if (gA_ZoneCache[i].iForm == ZoneForm_Box && gA_ZoneCache[i].iEntity > 0)
{
SetZoneMinsMaxs(i);
}
}
}
else if (convar == gCV_SQLZones)
{
for (int i = gI_MapZones; i > 0; i++)
{
if (StrEqual(gA_ZoneCache[i-1].sSource, "sql"))
Shavit_RemoveZone(i-1);
}
if (convar.BoolValue) RefreshZones();
}
else if (convar == gCV_PrebuiltZones)
{
for (int i = gI_MapZones; i > 0; i++)
{
if (StrEqual(gA_ZoneCache[i-1].sSource, "autozone"))
Shavit_RemoveZone(i-1);
}
if (convar.BoolValue) add_prebuilts_to_cache("trigger_multiple", false);
}
else if (convar == gCV_ClimbButtons)
{
for (int i = gI_MapZones; i > 0; i++)
{
if (StrEqual(gA_ZoneCache[i-1].sSource, "autobutton"))
Shavit_RemoveZone(i-1);
}
if (convar.BoolValue) add_prebuilts_to_cache("func_button", true);
}
}
public void OnAdminMenuReady(Handle topmenu)
{
gH_AdminMenu = TopMenu.FromHandle(topmenu);
if ((gH_TimerCommands = gH_AdminMenu.FindCategory("Timer Commands")) != INVALID_TOPMENUOBJECT)
{
gH_AdminMenu.AddItem("sm_zones", AdminMenu_Zones, gH_TimerCommands, "sm_zones", ADMFLAG_RCON);
gH_AdminMenu.AddItem("sm_deletezone", AdminMenu_DeleteZone, gH_TimerCommands, "sm_deletezone", ADMFLAG_RCON);
gH_AdminMenu.AddItem("sm_deleteallzones", AdminMenu_DeleteAllZones, gH_TimerCommands, "sm_deleteallzones", ADMFLAG_RCON);
gH_AdminMenu.AddItem("sm_zoneedit", AdminMenu_ZoneEdit, gH_TimerCommands, "sm_zoneedit", ADMFLAG_RCON);
gH_AdminMenu.AddItem("sm_tptozone", AdminMenu_TpToZone, gH_TimerCommands, "sm_tptozone", ADMFLAG_RCON);
gH_AdminMenu.AddItem("sm_hookzone", AdminMenu_HookZone, gH_TimerCommands, "sm_hookzone", ADMFLAG_RCON);
}
}
public void AdminMenu_Zones(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if(action == TopMenuAction_DisplayOption)
{
FormatEx(buffer, maxlength, "%T", "AddMapZone", param);
}
else if(action == TopMenuAction_SelectOption)
{
Command_Zones(param, 0);
}
}
public void AdminMenu_DeleteZone(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if(action == TopMenuAction_DisplayOption)
{
FormatEx(buffer, maxlength, "%T", "DeleteMapZone", param);
}
else if(action == TopMenuAction_SelectOption)
{
Command_DeleteZone(param, 0);
}
}
public void AdminMenu_DeleteAllZones(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if(action == TopMenuAction_DisplayOption)
{
FormatEx(buffer, maxlength, "%T", "DeleteAllMapZone", param);
}
else if(action == TopMenuAction_SelectOption)
{
Command_DeleteAllZones(param, 0);
}
}
public void AdminMenu_ZoneEdit(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if(action == TopMenuAction_DisplayOption)
{
FormatEx(buffer, maxlength, "%T", "ZoneEdit", param);
}
else if(action == TopMenuAction_SelectOption)
{
Reset(param);
OpenEditMenu(param);
}
}
public void AdminMenu_TpToZone(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
FormatEx(buffer, maxlength, "%T", "TpToZone", param);
}
else if (action == TopMenuAction_SelectOption)
{
OpenTpToZoneMenu(param);
}
}
public void AdminMenu_HookZone(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
{
if (action == TopMenuAction_DisplayOption)
{
FormatEx(buffer, maxlength, "%T", "HookZone", param);
}
else if (action == TopMenuAction_SelectOption)
{
OpenHookMenu_Form(param);
}
}
public int Native_ZoneExists(Handle handler, int numParams)
{
return (GetZoneIndex(GetNativeCell(1), GetNativeCell(2)) != -1);
}
public int Native_GetZoneData(Handle handler, int numParams)
{
return gA_ZoneCache[GetNativeCell(1)].iData;
}
public int Native_GetZoneFlags(Handle handler, int numParams)
{
return gA_ZoneCache[GetNativeCell(1)].iFlags;
}
public int Native_InsideZone(Handle handler, int numParams)
{
return InsideZone(GetNativeCell(1), GetNativeCell(2), (numParams > 2) ? GetNativeCell(3) : -1);
}
public int Native_InsideZoneGetID(Handle handler, int numParams)
{
int client = GetNativeCell(1);
int iType = GetNativeCell(2);
int iTrack = GetNativeCell(3);
if (iTrack >= 0 && !(gI_InsideZone[client][iTrack] & (1 << iType)))
{
return false;
}
for (int i = 0; i < gI_MapZones; i++)
{
if(gB_InsideZoneID[client][i] &&
gA_ZoneCache[i].iType == iType &&
(gA_ZoneCache[i].iTrack == iTrack || iTrack == -1))
{
SetNativeCellRef(4, i);
return true;
}
}
return false;
}
public int Native_GetStageCount(Handle handler, int numParas)
{
return gI_HighestStage[GetNativeCell(1)];
}
public int Native_Zones_DeleteMap(Handle handler, int numParams)
{
char sMap[PLATFORM_MAX_PATH];
GetNativeString(1, sMap, sizeof(sMap));
LowercaseString(sMap);
char sQuery[512];
FormatEx(sQuery, sizeof(sQuery), "DELETE FROM %smapzones WHERE map = '%s';", gS_MySQLPrefix, sMap);
QueryLog(gH_SQL, SQL_DeleteMap_Callback, sQuery, StrEqual(gS_Map, sMap, false), DBPrio_High);
return 1;
}
public void SQL_DeleteMap_Callback(Database db, DBResultSet results, const char[] error, any data)
{
if(results == null)
{
LogError("Timer (zones deletemap) SQL query failed. Reason: %s", error);
return;
}
if(view_as<bool>(data))
{
//DBConnectedSoDoStuff();
}
}
bool InsideZone(int client, int type, int track)
{
if(track != -1)
{
return (gI_InsideZone[client][track] & (1 << type)) != 0;
}
else
{
int res = 0;
for(int i = 0; i < TRACKS_SIZE; i++)
{
res |= gI_InsideZone[client][i];
}
return (res & (1 << type)) != 0;
}
}
public int Native_IsClientCreatingZone(Handle handler, int numParams)
{
return (gI_MapStep[GetNativeCell(1)] != 0);
}
public int Native_SetStart(Handle handler, int numParams)
{
SetStart(GetNativeCell(1), GetNativeCell(2), view_as<bool>(GetNativeCell(3)));
return 1;
}
public int Native_DeleteSetStart(Handle handler, int numParams)
{
DeleteSetStart(GetNativeCell(1), GetNativeCell(2));
return 1;
}
public int Native_GetClientLastStage(Handle plugin, int numParams)
{
return gI_LastStage[GetNativeCell(1)];
}
public any Native_GetZoneTrack(Handle plugin, int numParams)
{
int zoneid = GetNativeCell(1);
return gA_ZoneCache[zoneid].iTrack;
}
public any Native_GetZoneType(Handle plugin, int numParams)
{
int zoneid = GetNativeCell(1);
return gA_ZoneCache[zoneid].iType;
}
public any Native_GetZoneID(Handle plugin, int numParams)
{
int entity = GetNativeCell(1);
return gI_EntityZone[entity];
}
public any Native_ReloadZones(Handle plugin, int numParams)
{
LoadZonesHere();
return 0;
}
public any Native_UnloadZones(Handle plugin, int numParams)
{
UnloadZones();
return 0;
}
public any Native_GetZoneCount(Handle plugin, int numParams)
{
return gI_MapZones;
}
public any Native_GetZone(Handle plugin, int numParams)
{
if (GetNativeCell(3) != sizeof(zone_cache_t))
{
return ThrowNativeError(200, "zone_cache_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins", GetNativeCell(3), sizeof(zone_cache_t));
}
SetNativeArray(2, gA_ZoneCache[GetNativeCell(1)], sizeof(zone_cache_t));
return 0;
}
public any Native_AddZone(Handle plugin, int numParams)
{
if (gI_MapZones >= MAX_ZONES)
{
return -1;
}
if (GetNativeCell(2) != sizeof(zone_cache_t))
{
return ThrowNativeError(200, "zone_cache_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins", GetNativeCell(2), sizeof(zone_cache_t));
}
zone_cache_t cache;
GetNativeArray(1, cache, sizeof(cache));
cache.iEntity = -1;
if (cache.iForm != ZoneForm_Box && (cache.iFlags & ZF_Origin))
{
// previously origins were "%X %X %X" instead of "%.9f %.9f %.9f"...
// so we just convert this right now...
// "C56D0000 455D0000 C3600000"
// to "-3792.000000000 3536.000000000 -224.000000000"
if (-1 == StrContains(cache.sTarget, "."))
{
Format(cache.sTarget, sizeof(cache.sTarget),
"%.9f %.9f %.9f",
StringToInt(cache.sTarget, 16),
StringToInt(cache.sTarget[9], 16),
StringToInt(cache.sTarget[18], 16)
);
}
}
// normalize zone points...
FillBoxMinMax(cache.fCorner1, cache.fCorner2, cache.fCorner1, cache.fCorner2);
gA_ZoneCache[gI_MapZones] = cache;
gV_MapZones_Visual[gI_MapZones][0] = cache.fCorner1;
gV_MapZones_Visual[gI_MapZones][7] = cache.fCorner2;
CreateZonePoints(gV_MapZones_Visual[gI_MapZones], cache.iForm == ZoneForm_trigger_multiple);
AddVectors(cache.fCorner1, cache.fCorner2, gV_ZoneCenter[gI_MapZones]);
ScaleVector(gV_ZoneCenter[gI_MapZones], 0.5);
if (cache.iType == Zone_Stage)
{
if (cache.iData > gI_HighestStage[cache.iTrack])
{
gI_HighestStage[cache.iTrack] = cache.iData;
}
}
return gI_MapZones++;
}
public any Native_RemoveZone(Handle plugin, int numParams)
{
int index = GetNativeCell(1);
if (gI_MapZones <= 0 || index >= gI_MapZones)
{
return 0;
}
zone_cache_t cache; cache = gA_ZoneCache[index];
int ent = gA_ZoneCache[index].iEntity;
ClearZoneEntity(index, true);
if (ent > MaxClients && gA_ZoneCache[index].iForm == ZoneForm_Box) // created by shavit-zones
{
AcceptEntityInput(ent, "Kill");
}
int top = --gI_MapZones;
if (index < top)
{
gI_EntityZone[gA_ZoneCache[top].iEntity] = index;
gA_ZoneCache[index] = gA_ZoneCache[top];
gV_ZoneCenter[index] = gV_ZoneCenter[top];
for (int i = 0; i < sizeof(gV_MapZones_Visual[]); i++)
{
gV_MapZones_Visual[index][i] = gV_MapZones_Visual[top][i];
}
for (int i = 1; i <= MaxClients; i++)
{
gB_InsideZoneID[i][index] = gB_InsideZoneID[i][top];
}
}
else
{
bool empty_InsideZoneID[MAX_ZONES];
for (int i = 1; i <= MaxClients; i++)
{
gB_InsideZoneID[i] = empty_InsideZoneID;
}
}
RecalcInsideZoneAll();
if (cache.iType == Zone_Stage && cache.iData == gI_HighestStage[cache.iTrack])
RecalcHighestStage();
// call EndTouchPost(zoneent, player) manually here?
return 0;
}
bool JumpToZoneType(KeyValues kv, int type, int track)
{
static const char config_keys[ZONETYPES_SIZE][2][50] = {
{"Start", ""},
{"End", ""},
{"Glitch_Respawn", "Glitch Respawn"},
{"Glitch_Stop", "Glitch Stop"},
{"Glitch_Slay", "Glitch Slay"},
{"Freestyle", ""},
{"Custom Speed Limit", "Nolimit"},
{"Teleport", ""},
{"SPAWN POINT", ""},
{"Easybhop", ""},
{"Slide", ""},
{"Airaccelerate", ""},
{"Stage", ""},