-
Notifications
You must be signed in to change notification settings - Fork 3
/
rpg_devzones.sp
1304 lines (1172 loc) · 34.1 KB
/
rpg_devzones.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
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
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <smlib>
#define VERSION "3.0"
#pragma newdecls required
#define MAX_ZONES 256
int beamColorT[4] = { 255, 0, 0, 255 };
int beamColorCT[4] = { 0, 0, 255, 255 };
int beamColorN[4] = { 255, 255, 0, 255 };
int beamColorM[4] = { 0, 255, 0, 255 };
int g_CurrentZoneTeam[MAXPLAYERS + 1];
int g_CurrentZoneVis[MAXPLAYERS + 1];
char g_CurrentZoneName[MAXPLAYERS + 1][64];
// VARIABLES
Handle g_Zones = INVALID_HANDLE;
int g_Editing[MAXPLAYERS + 1] = { 0, ... };
float g_Positions[MAXPLAYERS + 1][2][3];
int g_ClientSelectedZone[MAXPLAYERS + 1] = { -1, ... };
bool g_bFixName[MAXPLAYERS + 1];
int g_BeamSprite;
int g_HaloSprite;
Handle hOnClientEntry = INVALID_HANDLE;
Handle hOnClientLeave = INVALID_HANDLE;
enum g_eList {
String:liName[64],
bool:liThis
};
int g_iZones[MAXPLAYERS + 1][MAX_ZONES][g_eList]; // max zones = 256
// cvars
Handle cvar_filter;
Handle cvar_mode;
Handle cvar_checker;
Handle cvar_model;
bool g_bfilter;
float checker;
bool mode_plugin;
char model[192];
Handle cvar_timer = INVALID_HANDLE;
// PLUGIN INFO
public Plugin myinfo =
{
name = "[T-RP] Zones",
author = "Totenfluch",
description = "Adds Custom Zones for T-RP",
version = VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart() {
cvar_filter = CreateConVar("sm_devzones_filter", "1", "0 = Only allow valid alive clients to be detected in the native zones. 1 = Detect entities and all (you need to add more checkers in the third party plugins).");
cvar_mode = CreateConVar("sm_devzones_mode", "1", "0 = Use checks every X seconds for check if a player join or leave a zone, 1 = hook zone entities with OnStartTouch and OnEndTouch (less CPU consume)");
cvar_checker = CreateConVar("sm_devzones_checker", "5.0", "checks and beambox refreshs per second, low value = more precise but more CPU consume, More hight = less precise but less CPU consume");
cvar_model = CreateConVar("sm_devzones_model", "models/error.mdl", "Use a model for zone entity (IMPORTANT: change this value only on map start)");
g_Zones = CreateArray(256);
RegAdminCmd("sm_zones", Command_CampZones, ADMFLAG_CUSTOM6);
RegConsoleCmd("say", fnHookSay);
HookEventEx("round_start", Event_OnRoundStart);
HookEventEx("teamplay_round_start", Event_OnRoundStart);
//HookEvent("round_start", OnRoundStart);
ReadZones();
HookConVarChange(cvar_filter, CVarChange);
HookConVarChange(cvar_checker, CVarChange);
HookConVarChange(cvar_mode, CVarChange);
HookConVarChange(cvar_model, CVarChange);
}
public void resetClient(int client) {
for (int i = 0; i < MAX_ZONES; i++)
g_iZones[client][i][liThis] = false;
}
public void CVarChange(Handle convar_hndl, const char[] oldValue, const char[] newValue) {
GetCVars();
}
// Get int values of cvars if they has being changed
public void GetCVars() {
g_bfilter = GetConVarBool(cvar_filter);
mode_plugin = GetConVarBool(cvar_mode);
checker = GetConVarFloat(cvar_checker);
GetConVarString(cvar_model, model, 192);
if (cvar_timer != INVALID_HANDLE) {
KillTimer(cvar_timer);
cvar_timer = INVALID_HANDLE;
}
cvar_timer = CreateTimer(checker, BeamBoxAll, _, TIMER_REPEAT);
}
public void OnClientPostAdminCheck(int client) {
g_ClientSelectedZone[client] = -1;
g_Editing[client] = 0;
g_bFixName[client] = false;
resetClient(client);
}
public Action Event_OnRoundStart(Handle event, const char[] name, bool dontBroadcast) {
if (mode_plugin)
RefreshZones();
}
public int CreateZoneEntity(float fMins[3], float fMaxs[3], char sZoneName[64]) {
float fMiddle[3];
int iEnt = CreateEntityByName("trigger_multiple");
DispatchKeyValue(iEnt, "spawnflags", "64");
Format(sZoneName, sizeof(sZoneName), "sm_devzone %s", sZoneName);
DispatchKeyValue(iEnt, "targetname", sZoneName);
DispatchKeyValue(iEnt, "wait", "0");
DispatchSpawn(iEnt);
ActivateEntity(iEnt);
SetEntProp(iEnt, Prop_Data, "m_spawnflags", 64);
GetMiddleOfABox(fMins, fMaxs, fMiddle);
TeleportEntity(iEnt, fMiddle, NULL_VECTOR, NULL_VECTOR);
SetEntityModel(iEnt, model);
// Have the mins always be negative
fMins[0] = fMins[0] - fMiddle[0];
if (fMins[0] > 0.0)
fMins[0] *= -1.0;
fMins[1] = fMins[1] - fMiddle[1];
if (fMins[1] > 0.0)
fMins[1] *= -1.0;
fMins[2] = fMins[2] - fMiddle[2];
if (fMins[2] > 0.0)
fMins[2] *= -1.0;
// And the maxs always be positive
fMaxs[0] = fMaxs[0] - fMiddle[0];
if (fMaxs[0] < 0.0)
fMaxs[0] *= -1.0;
fMaxs[1] = fMaxs[1] - fMiddle[1];
if (fMaxs[1] < 0.0)
fMaxs[1] *= -1.0;
fMaxs[2] = fMaxs[2] - fMiddle[2];
if (fMaxs[2] < 0.0)
fMaxs[2] *= -1.0;
SetEntPropVector(iEnt, Prop_Send, "m_vecMins", fMins);
SetEntPropVector(iEnt, Prop_Send, "m_vecMaxs", fMaxs);
SetEntProp(iEnt, Prop_Send, "m_nSolidType", 2);
int iEffects = GetEntProp(iEnt, Prop_Send, "m_fEffects");
iEffects |= 32;
SetEntProp(iEnt, Prop_Send, "m_fEffects", iEffects);
HookSingleEntityOutput(iEnt, "OnStartTouch", EntOut_OnStartTouch);
HookSingleEntityOutput(iEnt, "OnEndTouch", EntOut_OnEndTouch);
return iEnt;
}
public void EntOut_OnStartTouch(const char[] output, int caller, int activator, float delay) {
// Ignore dead players
if (g_bfilter)
if (activator < 1 || activator > MaxClients || !IsClientInGame(activator) || !IsPlayerAlive(activator))
return;
char sTargetName[256];
GetEntPropString(caller, Prop_Data, "m_iName", sTargetName, sizeof(sTargetName));
ReplaceString(sTargetName, sizeof(sTargetName), "sm_devzone ", "");
// entra
char nBuf[64];
Entity_GetGlobalName(caller, nBuf, sizeof(nBuf));
int callerId = StringToInt(nBuf);
g_iZones[activator][callerId][liThis] = true;
Format(g_iZones[activator][callerId][liName], 64, sTargetName);
//PrintToChatAll("E::%i::%s::", callerId, sTargetName);
Call_StartForward(hOnClientEntry);
Call_PushCell(activator);
Call_PushString(sTargetName);
Call_Finish();
}
public void EntOut_OnEndTouch(const char[] output, int caller, int activator, float delay) {
// Ignore dead players
if (g_bfilter)
if (activator < 1 || activator > MaxClients || !IsClientInGame(activator) || !IsPlayerAlive(activator))
return;
char sTargetName[256];
GetEntPropString(caller, Prop_Data, "m_iName", sTargetName, sizeof(sTargetName));
ReplaceString(sTargetName, sizeof(sTargetName), "sm_devzone ", "");
// sale
char nBuf[64];
Entity_GetGlobalName(caller, nBuf, sizeof(nBuf));
int callerId = StringToInt(nBuf);
g_iZones[activator][callerId][liThis] = false;
Format(g_iZones[activator][callerId][liName], 64, "");
//PrintToChatAll("EX::%i::%s::", callerId, sTargetName);
Call_StartForward(hOnClientLeave);
Call_PushCell(activator);
Call_PushString(sTargetName);
Call_Finish();
}
public void OnMapStart() {
OnConfigsExecuted();
for (int i = 1; i < MAXPLAYERS; i++)
resetClient(i);
}
public void OnConfigsExecuted() {
GetCVars();
g_BeamSprite = PrecacheModel("sprites/laserbeam.vmt");
g_HaloSprite = PrecacheModel("materials/sprites/halo.vmt");
PrecacheModel(model);
ReadZones();
}
public void OnMapEnd() {
SaveZones(0);
}
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon) {
BeamBox_OnPlayerRunCmd(client);
}
public Action Command_CampZones(int client, int args) {
ZoneMenu(client);
}
public void getZoneTeamColor(int team, int color[4]) {
switch (team)
{
case 1:
{
color = beamColorM;
}
case 2:
{
color = beamColorT;
}
case 3:
{
color = beamColorCT;
}
default:
{
color = beamColorN;
}
}
}
public void ReadZones() {
ClearArray(g_Zones);
char Path[512];
BuildPath(Path_SM, Path, sizeof(Path), "configs/dev_zones");
if (!DirExists(Path))
CreateDirectory(Path, 0777);
char map[64];
GetCurrentMap(map, sizeof(map));
if (StrContains(map, "workshop") != -1) {
char mapPart[3][64];
ExplodeString(map, "/", mapPart, 3, 64);
strcopy(map, sizeof(map), mapPart[2]);
}
BuildPath(Path_SM, Path, sizeof(Path), "configs/dev_zones/%s.zones.txt", map);
if (!FileExists(Path))
{
//Handle file = OpenFile(Path, "w");
//CloseHandle(file);
Handle kv = CreateKeyValues("Zones");
KeyValuesToFile(kv, Path);
}
Handle kv = CreateKeyValues("Zones");
FileToKeyValues(kv, Path);
if (!KvGotoFirstSubKey(kv))
{
PrintToServer("[ERROR] Config file is corrupted: %s", Path);
return;
}
float pos1[3];
float pos2[3];
char nombre[64];
do
{
KvGetVector(kv, "cordinate_a", pos1);
KvGetVector(kv, "cordinate_b", pos2);
KvGetString(kv, "name", nombre, 64);
Handle trie = CreateTrie();
SetTrieArray(trie, "corda", pos1, 3);
SetTrieArray(trie, "cordb", pos2, 3);
SetTrieValue(trie, "team", KvGetNum(kv, "team", 0));
SetTrieValue(trie, "vis", KvGetNum(kv, "vis", 0));
SetTrieString(trie, "name", nombre);
PushArrayCell(g_Zones, trie);
//CloseHandle(trie);
} while (KvGotoNextKey(kv));
CloseHandle(kv);
}
public void SaveZones(int client) {
char Path[512];
char map[64];
GetCurrentMap(map, sizeof(map));
if (StrContains(map, "workshop") != -1) {
char mapPart[3][64];
ExplodeString(map, "/", mapPart, 3, 64);
strcopy(map, sizeof(map), mapPart[2]);
}
BuildPath(Path_SM, Path, sizeof(Path), "configs/dev_zones/%s.zones.txt", map);
Handle file = OpenFile(Path, "w+");
CloseHandle(file);
float pos1[3];
float pos2[3];
char SectName[64];
int Team;
int Vis;
char nombre[64];
int size = GetArraySize(g_Zones);
Handle kv = CreateKeyValues("Zones");
for (int i = 0; i < size; ++i)
{
IntToString(i, SectName, sizeof(SectName));
Handle trie = GetArrayCell(g_Zones, i);
GetTrieArray(trie, "corda", pos1, sizeof(pos1));
GetTrieArray(trie, "cordb", pos2, sizeof(pos2));
GetTrieValue(trie, "team", Team);
GetTrieValue(trie, "vis", Vis);
GetTrieString(trie, "name", nombre, 64);
//Format(Nombre, 64, "Zone %i", i);
//SetTrieString(trie, "name", Nombre, true);
KvJumpToKey(kv, SectName, true);
KvSetString(kv, "name", nombre);
KvSetVector(kv, "cordinate_a", pos1);
KvSetVector(kv, "cordinate_b", pos2);
KvSetNum(kv, "vis", Vis);
KvSetNum(kv, "team", Team);
KvGoBack(kv);
}
KeyValuesToFile(kv, Path);
CloseHandle(kv);
if (client != 0)
PrintToChat(client, "All zones are saved in file.");
}
public bool TraceRayDontHitSelf(int entity, int mask, any data) {
if (entity == data)
return false;
return true;
}
public Action fnHookSay(int client, int args) {
if (!g_bFixName[client])return;
char sArgs[192];
GetCmdArgString(sArgs, sizeof(sArgs));
StripQuotes(sArgs);
ReplaceString(sArgs, 192, "'", ".");
ReplaceString(sArgs, 192, "<", ".");
//ReplaceString(sArgs, 192, "\"", ".");
if (strlen(sArgs) > 45)
{
PrintToChat(client, "the name is too long, try other name");
return;
}
if (StrEqual(sArgs, "!cancel"))
{
PrintToChat(client, "Set name action canceled");
EditorMenu(client);
return;
}
char ZoneId[64];
int size = GetArraySize(g_Zones);
for (int i = 0; i < size; ++i)
{
Handle trie = GetArrayCell(g_Zones, i);
GetTrieString(trie, "name", ZoneId, 64);
if (StrEqual(ZoneId, sArgs))
{
PrintToChat(client, "The name already exist, write other name");
return;
}
}
Format(g_CurrentZoneName[client], 64, sArgs);
PrintToChat(client, "Zone name set to %s", sArgs);
g_bFixName[client] = false;
EditorMenu(client);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
hOnClientEntry = CreateGlobalForward("Zone_OnClientEntry", ET_Ignore, Param_Cell, Param_String);
hOnClientLeave = CreateGlobalForward("Zone_OnClientLeave", ET_Ignore, Param_Cell, Param_String);
CreateNative("Zone_IsClientInZone", Native_InZone);
CreateNative("Zone_GetZonePosition", Native_Teleport);
CreateNative("Zone_CheckIfZoneExists", Native_ZoneExist);
CreateNative("Zone_isPositionInZone", Native_isPositionInZone);
/*
@Param1 -> int client
@Param2 -> char[64] zoneBuffer
@return true if zone found false if not
*/
CreateNative("Zone_getMostRecentActiveZone", Native_getMostRecentActiveZone);
return APLRes_Success;
}
public int Native_InZone(Handle plugin, int argc) {
char name[64];
GetNativeString(2, name, 64);
int client = GetNativeCell(1);
bool same = GetNativeCell(3);
bool sensitive = GetNativeCell(4);
int size = GetArraySize(g_Zones);
for (int i = 0; i < size; ++i)
{
if (same)
{
if (StrEqual(g_iZones[client][i][liName], name, sensitive) && g_iZones[client][i][liThis])
return true;
}
else
{
if (StrContains(g_iZones[client][i][liName], name, sensitive) == 0 && g_iZones[client][i][liThis])
return true;
}
}
return false;
}
public int Native_getMostRecentActiveZone(Handle plugin, int argc) {
int client = GetNativeCell(1);
int size = GetArraySize(g_Zones);
for (int i = 0; i < size; ++i) {
if (g_iZones[client][i][liThis]) {
SetNativeString(2, g_iZones[client][i][liName], 64);
return true;
}
}
return false;
}
public int Native_Teleport(Handle plugin, int argc) {
char name[64];
char namezone[64];
float posA[3];
float posB[3];
GetNativeString(1, name, 64);
bool sensitive = GetNativeCell(2);
int size = GetArraySize(g_Zones);
if (size > 0)
{
for (int i = 0; i < size; ++i)
{
GetTrieString(GetArrayCell(g_Zones, i), "name", namezone, 64);
if (StrEqual(name, namezone, sensitive))
{
GetTrieArray(GetArrayCell(g_Zones, i), "corda", posA, sizeof(posA));
GetTrieArray(GetArrayCell(g_Zones, i), "cordb", posB, sizeof(posB));
float ZonePos[3];
AddVectors(posA, posB, ZonePos);
ZonePos[0] = FloatDiv(ZonePos[0], 2.0);
ZonePos[1] = FloatDiv(ZonePos[1], 2.0);
ZonePos[2] = FloatDiv(ZonePos[2], 2.0);
SetNativeArray(3, ZonePos, 3);
return true;
}
}
}
return false;
}
public int Native_ZoneExist(Handle plugin, int argc) {
char name[64];
char namezone[64];
GetNativeString(1, name, 64);
bool same = GetNativeCell(2);
bool sensitive = GetNativeCell(3);
int size = GetArraySize(g_Zones);
if (size > 0)
{
for (int i = 0; i < size; ++i)
{
GetTrieString(GetArrayCell(g_Zones, i), "name", namezone, 64);
if (same)if (StrEqual(name, namezone, sensitive))return true;
else if (StrContains(name, namezone, sensitive) == 0)return true;
}
}
return false;
}
public int Native_isPositionInZone(Handle plugin, int numParams) {
char zonename[64];
float pos[3];
GetNativeString(1, zonename, 64);
pos[0] = view_as<float>(GetNativeCell(2));
pos[1] = view_as<float>(GetNativeCell(3));
pos[2] = view_as<float>(GetNativeCell(4));
int size = GetArraySize(g_Zones);
if (size > 0) {
for (int i = 0; i < size; ++i) {
char name[64];
GetTrieString(GetArrayCell(g_Zones, i), "name", name, sizeof(name));
if (StrEqual(name, zonename)) {
float posA[3];
float posB[3];
GetTrieArray(GetArrayCell(g_Zones, i), "corda", posA, sizeof(posA));
GetTrieArray(GetArrayCell(g_Zones, i), "cordb", posB, sizeof(posB));
return IsbetweenRect(pos, posA, posB, 0);
}
}
}
return 0;
}
public void DrawBeamBox(int client) {
int zColor[4];
getZoneTeamColor(g_CurrentZoneTeam[client], zColor);
TE_SendBeamBoxToClient(client, g_Positions[client][1], g_Positions[client][0], g_BeamSprite, g_HaloSprite, 0, 30, 1.0, 5.0, 5.0, 2, 1.0, zColor, 0);
CreateTimer(1.0, BeamBox, client, TIMER_REPEAT);
}
public Action BeamBox(Handle timer, any client) {
if (IsClientInGame(client))
{
if (g_Editing[client] == 2)
{
int zColor[4];
getZoneTeamColor(g_CurrentZoneTeam[client], zColor);
TE_SendBeamBoxToClient(client, g_Positions[client][1], g_Positions[client][0], g_BeamSprite, g_HaloSprite, 0, 30, 1.0, 5.0, 5.0, 2, 1.0, zColor, 0);
return Plugin_Continue;
}
}
return Plugin_Stop;
}
public Action BeamBoxAll(Handle timer, any data) {
int size = GetArraySize(g_Zones);
float posA[3];
float posB[3];
int zColor[4];
int Team;
int Vis;
char nombre[64];
for (int i = 0; i < size; ++i)
{
Handle trie = GetArrayCell(g_Zones, i);
GetTrieArray(trie, "corda", posA, sizeof(posA));
GetTrieArray(trie, "cordb", posB, sizeof(posB));
GetTrieValue(trie, "team", Team);
GetTrieValue(trie, "vis", Vis);
GetTrieString(trie, "name", nombre, 64);
//CloseHandle(trie);
for (int p = 1; p <= MaxClients; p++)
{
if (IsClientInGame(p))
{
if (g_ClientSelectedZone[p] != i && (Vis == 1 || GetClientTeam(p) == Vis)) {
getZoneTeamColor(Team, zColor);
TE_SendBeamBoxToClient(p, posA, posB, g_BeamSprite, g_HaloSprite, 0, 30, checker, 5.0, 5.0, 2, 1.0, zColor, 0);
}
if (mode_plugin)continue;
if (IsPlayerAlive(p))
{
if (IsbetweenRect(NULL_VECTOR, posA, posB, p))
{
if (!g_iZones[p][i][liThis])
{
// entra
g_iZones[p][i][liThis] = true;
Format(g_iZones[p][i][liName], 64, nombre);
Call_StartForward(hOnClientEntry);
Call_PushCell(p);
Call_PushString(g_iZones[p][i][liName]);
Call_Finish();
}
}
else
{
if (g_iZones[p][i][liThis])
{
// sale
g_iZones[p][i][liThis] = false;
Format(g_iZones[p][i][liName], 64, nombre);
Call_StartForward(hOnClientLeave);
Call_PushCell(p);
Call_PushString(g_iZones[p][i][liName]);
Call_Finish();
}
}
}
}
}
}
return Plugin_Continue;
}
public void BeamBox_OnPlayerRunCmd(int client) {
if (g_Editing[client] == 1 || g_Editing[client] == 3)
{
float pos[3];
float ang[3];
int zColor[4];
getZoneTeamColor(g_CurrentZoneTeam[client], zColor);
if (g_Editing[client] == 1)
{
GetClientEyePosition(client, pos);
GetClientEyeAngles(client, ang);
TR_TraceRayFilter(pos, ang, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, client);
TR_GetEndPosition(g_Positions[client][1]);
}
TE_SendBeamBoxToClient(client, g_Positions[client][1], g_Positions[client][0], g_BeamSprite, g_HaloSprite, 0, 30, 0.1, 5.0, 5.0, 2, 1.0, zColor, 0);
}
}
stock void TE_SendBeamBoxToClient(int client, float uppercorner[3], const float bottomcorner[3], int ModelIndex, int HaloIndex, int StartFrame, int FrameRate, float Life, float Width, float EndWidth, int FadeLength, float Amplitude, const int Color[4], int Speed) {
// Create the additional corners of the box
float tc1[3];
AddVectors(tc1, uppercorner, tc1);
tc1[0] = bottomcorner[0];
float tc2[3];
AddVectors(tc2, uppercorner, tc2);
tc2[1] = bottomcorner[1];
float tc3[3];
AddVectors(tc3, uppercorner, tc3);
tc3[2] = bottomcorner[2];
float tc4[3];
AddVectors(tc4, bottomcorner, tc4);
tc4[0] = uppercorner[0];
float tc5[3];
AddVectors(tc5, bottomcorner, tc5);
tc5[1] = uppercorner[1];
float tc6[3];
AddVectors(tc6, bottomcorner, tc6);
tc6[2] = uppercorner[2];
// Draw all the edges
TE_SetupBeamPoints(uppercorner, tc1, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(uppercorner, tc2, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(uppercorner, tc3, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc6, tc1, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc6, tc2, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc6, bottomcorner, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc4, bottomcorner, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc5, bottomcorner, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc5, tc1, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc5, tc3, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc4, tc3, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
TE_SetupBeamPoints(tc4, tc2, ModelIndex, HaloIndex, StartFrame, FrameRate, Life, Width, EndWidth, FadeLength, Amplitude, Color, Speed);
TE_SendToClient(client);
}
public bool IsbetweenRect(float Pos[3], float Corner1[3], float Corner2[3], int client)
{
float Entity[3];
float field1[2];
float field2[2];
float field3[2];
if (!client)
{
Entity = Pos;
}
else
GetClientAbsOrigin(client, Entity);
Entity[2] = FloatAdd(Entity[2], 25.0);
// Sort Floats...
if (FloatCompare(Corner1[0], Corner2[0]) == -1)
{
field1[0] = Corner1[0];
field1[1] = Corner2[0];
}
else
{
field1[0] = Corner2[0];
field1[1] = Corner1[0];
}
if (FloatCompare(Corner1[1], Corner2[1]) == -1)
{
field2[0] = Corner1[1];
field2[1] = Corner2[1];
}
else
{
field2[0] = Corner2[1];
field2[1] = Corner1[1];
}
if (FloatCompare(Corner1[2], Corner2[2]) == -1)
{
field3[0] = Corner1[2];
field3[1] = Corner2[2];
}
else
{
field3[0] = Corner2[2];
field3[1] = Corner1[2];
}
// Check the Vectors ...
if (Entity[0] < field1[0] || Entity[0] > field1[1])
{
//PrintToChat(client, "first");
return false;
}
if (Entity[1] < field2[0] || Entity[1] > field2[1])
{
//PrintToChat(client, "second");
return false;
}
if (Entity[2] < field3[0] || Entity[2] > field3[1])
{
//PrintToChat(client, "third");
return false;
}
return true;
}
// menus.sp
public void ZoneMenu(int client)
{
g_ClientSelectedZone[client] = -1;
g_Editing[client] = 0;
Handle Menu2 = CreateMenu(Handle_ZoneMenu);
SetMenuTitle(Menu2, "Zones");
AddMenuItem(Menu2, "", "Create Zone");
AddMenuItem(Menu2, "", "Edit Zones");
AddMenuItem(Menu2, "", "Save Zones");
AddMenuItem(Menu2, "", "Reload Zones");
AddMenuItem(Menu2, "", "Clear Zones");
SetMenuExitBackButton(Menu2, true);
DisplayMenu(Menu2, client, MENU_TIME_FOREVER);
}
public int Handle_ZoneMenu(Handle tMenu, MenuAction action, int client, int item) {
switch (action)
{
case MenuAction_Select:
{
switch (item)
{
case 0:
{
EditorMenu(client);
}
case 1:
{
ListZones(client, MenuHandler_ZoneModify);
}
case 2:
{
SaveZones(client);
ZoneMenu(client);
}
case 3:
{
ReadZones();
PrintToChat(client, "Zones are reloaded");
ZoneMenu(client);
}
case 4:
{
ClearZonesMenu(client);
}
}
}
case MenuAction_End:
{
CloseHandle(tMenu);
}
}
}
public void ListZones(int client, MenuHandler handler)
{
Handle Menu2 = CreateMenu(handler);
SetMenuTitle(Menu2, "Avaliable Zones");
char ZoneName[256];
char ZoneId[64];
char Id[64];
int TeamId;
int size = GetArraySize(g_Zones);
if (size > 0)
{
for (int i = 0; i < size; ++i)
{
GetTrieValue(GetArrayCell(g_Zones, i), "team", TeamId);
GetTrieString(GetArrayCell(g_Zones, i), "name", ZoneId, 64);
IntToString(i, Id, sizeof(Id));
Format(ZoneName, sizeof(ZoneName), ZoneId);
AddMenuItem(Menu2, Id, ZoneId);
}
} else {
AddMenuItem(Menu2, "", "No zones are avaliable", ITEMDRAW_DISABLED);
}
SetMenuExitBackButton(Menu2, true);
DisplayMenu(Menu2, client, MENU_TIME_FOREVER);
}
public void EditorMenu(int client) {
if (g_Editing[client] == 3)
{
DrawBeamBox(client);
g_Editing[client] = 2;
}
Handle Menu2 = CreateMenu(MenuHandler_Editor);
if (g_ClientSelectedZone[client] != -1)
SetMenuTitle(Menu2, "Zone Editor (MODIFY)");
else
SetMenuTitle(Menu2, "Zone Editor");
if (g_Editing[client] == 0)
AddMenuItem(Menu2, "", "Start Zone");
else
AddMenuItem(Menu2, "", "RliThisrt Zone");
if (g_Editing[client] > 0)
{
AddMenuItem(Menu2, "", "Set Zone name");
if (g_Editing[client] == 2)
AddMenuItem(Menu2, "", "Continue Editing");
else
AddMenuItem(Menu2, "", "Pause Editing");
AddMenuItem(Menu2, "", "Cancel Zone");
AddMenuItem(Menu2, "", "Save Zone");
switch (g_CurrentZoneTeam[client])
{
case 0:
{
AddMenuItem(Menu2, "", "Set Zone Yellow");
}
case 1:
{
AddMenuItem(Menu2, "", "Set Zone Green");
}
case 2:
{
AddMenuItem(Menu2, "", "Set Zone Red");
}
case 3:
{
AddMenuItem(Menu2, "", "Set Zone Blue");
}
}
AddMenuItem(Menu2, "", "Go to Zone");
AddMenuItem(Menu2, "", "Strech Zone");
switch (g_CurrentZoneVis[client])
{
case 0:
{
AddMenuItem(Menu2, "", "Visibility: No One");
}
case 1:
{
AddMenuItem(Menu2, "", "Visibility: All");
}
case 2:
{
AddMenuItem(Menu2, "", "Visibility: T");
}
case 3:
{
AddMenuItem(Menu2, "", "Visibility: CT");
}
}
}
SetMenuExitBackButton(Menu2, true);
DisplayMenu(Menu2, client, MENU_TIME_FOREVER);
}
public int MenuHandler_Editor(Handle tMenu, MenuAction action, int client, int item) {
switch (action)
{
case MenuAction_Select:
{
switch (item)
{
case 0:
{
// Start
g_Editing[client] = 1;
float pos[3];
float ang[3];
GetClientEyePosition(client, pos);
GetClientEyeAngles(client, ang);
TR_TraceRayFilter(pos, ang, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, client);
TR_GetEndPosition(g_Positions[client][0]);
EditorMenu(client);
}
case 1:
{
PrintToChat(client, "Write in chat the name for the zone\nType !cancel for cancel the operation");
g_bFixName[client] = true;
//EditorMenu(client);
}
case 2:
{
// Pause
if (g_Editing[client] == 2)
{
g_Editing[client] = 1;
} else {
DrawBeamBox(client);
g_Editing[client] = 2;
}
EditorMenu(client);
}
case 3:
{
// Delete
if (g_ClientSelectedZone[client] != -1)
RemoveFromArray(g_Zones, g_ClientSelectedZone[client]);
g_Editing[client] = 0;
g_ClientSelectedZone[client] = -1;
ZoneMenu(client);
if (mode_plugin)RefreshZones();
}
case 4:
{
// Save
g_Editing[client] = 2;
Handle trie = CreateTrie();
SetTrieArray(trie, "corda", g_Positions[client][0], 3);
SetTrieArray(trie, "cordb", g_Positions[client][1], 3);
SetTrieValue(trie, "team", g_CurrentZoneTeam[client]);
SetTrieValue(trie, "vis", g_CurrentZoneVis[client]);
if (g_ClientSelectedZone[client] != -1)
{
SetTrieString(trie, "name", g_CurrentZoneName[client]);
SetArrayCell(g_Zones, g_ClientSelectedZone[client], trie);
}
else