-
Notifications
You must be signed in to change notification settings - Fork 35
/
filtertools.inc
1394 lines (1269 loc) · 38.9 KB
/
filtertools.inc
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
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: filtertools.inc
* Type: Core
* Description: Class system tools; validating, getting indexes or lists
*
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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/>.
*
* ============================================================================
*/
/**
* Validates the team requirements in a class cache and check that theres at
* least one class for each team. Minium team requirements are zombies and
* humans. The admin team is optinal and not validated.
*
* @param cachetype Optional. Specifies what class cache to validate. Options:
* ZR_CLASS_CACHE_ORIGINAL (default, unchanged class data),
* ZR_CLASS_CACHE_MODIFIED (modified class data).
* @return True if validation was successful, false otherwise.
*/
stock bool:ClassValidateTeamRequirements(cachetype = ZR_CLASS_CACHE_ORIGINAL)
{
new zombieindex;
new humanindex;
// Check if there are no classes.
if (ClassCount == 0)
{
return false;
}
// Test if a zombie and human class was found.
zombieindex = ClassGetFirstClass(ZR_CLASS_TEAM_ZOMBIES, _, cachetype);
humanindex = ClassGetFirstClass(ZR_CLASS_TEAM_HUMANS, _, cachetype);
// Validate indexes.
if (ClassValidateIndex(zombieindex) && ClassValidateIndex(humanindex))
{
return true;
}
return false;
}
/**
* Validates that there's a class marked as team default for each team.
*
* @param cachetype Optional. Specifies what class cache to validate. Options:
* ZR_CLASS_CACHE_ORIGINAL (default, unchanged class data),
* ZR_CLASS_CACHE_MODIFIED (modified class data).
* @return True if validation was successful, false otherwise.
*/
stock bool:ClassValidateTeamDefaults(cachetype = ZR_CLASS_CACHE_ORIGINAL)
{
new zombieindex;
new humanindex;
// Check if there are no classes.
if (ClassCount == 0)
{
return false;
}
// Test if a default zombie and human class was found.
zombieindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ZOMBIES, _, cachetype);
humanindex = ClassGetDefaultClass(ZR_CLASS_TEAM_HUMANS, _, cachetype);
// Validate indexes.
if (ClassValidateIndex(zombieindex) && ClassValidateIndex(humanindex))
{
return true;
}
else
{
return false;
}
}
/**
* Validates all the class attributes in the original class data array, to
* check if they have invalid values. Boolean settings are not validated.
*
* @param classindex The index of the class to validate.
* @param logErrors Log invalid attributes.
* @return A value with attribute error flags.
*/
stock ClassValidateAttributes(classindex, bool:logErrors = false)
{
new flags;
// Team.
new team = ClassData[classindex][Class_Team];
if (team < ZR_CLASS_TEAM_MIN || team > ZR_CLASS_TEAM_MAX)
{
flags += ZR_CLASS_TEAM;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid team at index %d: %d", classindex, team);
}
}
// Class flags.
new class_flags = ClassData[classindex][Class_Flags];
if (class_flags < ZR_CLASS_FLAGS_MIN || class_flags > ZR_CLASS_FLAGS_MAX)
{
flags += ZR_CLASS_FLAGS;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid flags at index %d: %d", classindex, class_flags);
}
}
// Group.
decl String:group[64];
group[0] = 0;
if (strcopy(group, sizeof(group), ClassData[classindex][Class_Group]) > 0)
{
// Check if the group exist.
if (FindAdmGroup(group) == INVALID_GROUP_ID)
{
flags += ZR_CLASS_GROUP;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid group at index %d: \"%s\"", classindex, group);
}
}
}
// Name.
decl String:name[64];
name[0] = 0;
if (strcopy(name, sizeof(name), ClassData[classindex][Class_Name]) < ZR_CLASS_NAME_MIN)
{
flags += ZR_CLASS_NAME;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Missing name at index %d.", classindex);
}
}
else
{
// Check for reserved name keyworks. These aren't allowed as names.
if (StrEqual(name, "all", false) ||
StrEqual(name, "humans", false) ||
StrEqual(name, "zombies", false) ||
StrEqual(name, "admins", false))
{
flags += ZR_CLASS_NAME;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid name at index %d. Cannot be a team name: \"%s\"", classindex, name);
}
}
}
// Description.
if (strlen(ClassData[classindex][Class_Description]) < ZR_CLASS_DESCRIPTION_MIN)
{
flags += ZR_CLASS_DESCRIPTION;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Missing description at index %d.", classindex);
}
}
// Model path.
decl String:model_path[PLATFORM_MAX_PATH];
if (strcopy(model_path, sizeof(model_path), ClassData[classindex][Class_ModelPath]) == 0)
{
flags += ZR_CLASS_MODEL_PATH;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Missing model_path at index %d.", classindex, model_path);
}
}
else
{
// Validate only if not a pre-defined setting.
if (!StrEqual(model_path, "random", false) &&
!StrEqual(model_path, "random_public", false) &&
!StrEqual(model_path, "random_hidden", false) &&
!StrEqual(model_path, "random_admin", false) &&
!StrEqual(model_path, "random_mother_zombie", false) &&
!StrEqual(model_path, "default", false) &&
!StrEqual(model_path, "no_change", false))
{
// Check if the file exists.
if (!FileExists(model_path, true))
{
flags += ZR_CLASS_MODEL_PATH;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid model_path at index %d. File not found: \"%s\"", classindex, model_path);
}
}
}
}
// Model skin index.
new model_skin_index = ClassData[classindex][Class_ModelSkinIndex];
if (model_skin_index < ZR_CLASS_MODEL_SKIN_INDEX_MIN)
{
flags += ZR_CLASS_MODEL_SKIN_INDEX;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid model_skin_index at index %d: %d", classindex, model_skin_index);
}
}
// Alpha, initial.
new alpha_initial = ClassData[classindex][Class_AlphaInitial];
if (!(alpha_initial >= ZR_CLASS_ALPHA_INITIAL_MIN && alpha_initial <= ZR_CLASS_ALPHA_INITIAL_MAX))
{
flags += ZR_CLASS_ALPHA_INITIAL;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid alpha_inital at index %d: %d", classindex, alpha_initial);
}
}
// Alpha, damaged.
new alpha_damaged = ClassData[classindex][Class_AlphaDamaged];
if (!(alpha_damaged >= ZR_CLASS_ALPHA_DAMAGED_MIN && alpha_damaged <= ZR_CLASS_ALPHA_DAMAGED_MAX))
{
flags += ZR_CLASS_ALPHA_DAMAGED;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid alpha_damaged at index %d: %d", classindex, alpha_damaged);
}
}
// Alpha, damage.
new alpha_damage = ClassData[classindex][Class_AlphaDamage];
if (!(alpha_damage >= ZR_CLASS_ALPHA_DAMAGE_MIN && alpha_damage <= ZR_CLASS_ALPHA_DAMAGE_MAX))
{
flags += ZR_CLASS_ALPHA_DAMAGE;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid alpha_damage at index %d: %d", classindex, alpha_damage);
}
}
// Overlay path.
decl String:overlay_path[PLATFORM_MAX_PATH];
decl String:overlay[PLATFORM_MAX_PATH];
if (strcopy(overlay_path, sizeof(overlay_path), ClassData[classindex][Class_OverlayPath]) > 0)
{
// Check if the file exists.
Format(overlay, sizeof(overlay), "materials/%s.vmt", overlay_path);
if (!FileExists(overlay, true))
{
flags += ZR_CLASS_OVERLAY_PATH;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid overlay_path at index %d. File not found: \"%s\"", classindex, overlay_path);
}
}
}
// Field of view.
new fov = ClassData[classindex][Class_Fov];
if (!(fov >= ZR_CLASS_FOV_MIN && fov <= ZR_CLASS_FOV_MAX))
{
flags += ZR_CLASS_FOV;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid fov at index %d: %d", classindex, fov);
}
}
// Napalm time.
new Float:napalm_time = ClassData[classindex][Class_NapalmTime];
if (!(napalm_time >= ZR_CLASS_NAPALM_TIME_MIN && napalm_time <= ZR_CLASS_NAPALM_TIME_MAX))
{
flags += ZR_CLASS_NAPALM_TIME;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid napalm_time at index %d: %0.2f", classindex, napalm_time);
}
}
// Immunity mode.
new ImmunityMode:immunityMode = ClassData[classindex][Class_ImmunityMode];
if (immunityMode == Immunity_Invalid)
{
flags += ZR_CLASS_IMMUNITY_MODE;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid immunity_mode at index %d.", classindex);
}
}
// Immunity amount.
new immunityAmount = ClassData[classindex][Class_ImmunityAmount];
if (!ImmunityIsValidAmount(immunityMode, immunityAmount))
{
flags += ZR_CLASS_IMMUNITY_AMOUNT;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid immunity_amount at index %d.", classindex);
}
}
// Immunity cooldown.
new immunityCooldown = ClassData[classindex][Class_ImmunityCooldown];
if (!ImmunityIsValidCooldown(immunityMode, immunityCooldown))
{
flags += ZR_CLASS_IMMUNITY_COOLDOWN;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid immunity_cooldown at index %d.", classindex);
}
}
// Health.
new health = ClassData[classindex][Class_Health];
if (!(health >= ZR_CLASS_HEALTH_MIN && health <= ZR_CLASS_HEALTH_MAX))
{
flags += ZR_CLASS_HEALTH;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid health at index %d: %d", classindex, health);
}
}
// Health regen interval.
new Float:regen_interval = ClassData[classindex][Class_HealthRegenInterval];
if (!(regen_interval >= ZR_CLASS_REGEN_INTERVAL_MIN && regen_interval <= ZR_CLASS_REGEN_INTERVAL_MAX))
{
flags += ZR_CLASS_HEALTH_REGEN_INTERVAL;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid health_regen_interval at index %d: %0.2f", classindex, regen_interval);
}
}
// Health regen amount.
new regen_amount = ClassData[classindex][Class_HealthRegenAmount];
if (!(regen_amount >= ZR_CLASS_REGEN_AMOUNT_MIN && regen_amount <= ZR_CLASS_REGEN_AMOUNT_MAX))
{
flags += ZR_CLASS_HEALTH_REGEN_AMOUNT;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid health_regen_amount at index %d: %d", classindex, regen_amount);
}
}
// Health infect gain.
new infect_gain = ClassData[classindex][Class_HealthInfectGain];
if (!(infect_gain >= ZR_CLASS_HEALTH_INFECT_GAIN_MIN && infect_gain <= ZR_CLASS_HEALTH_INFECT_GAIN_MAX))
{
flags += ZR_CLASS_HEALTH_INFECT_GAIN;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid health_infect_gain at index %d: %d", classindex, infect_gain);
}
}
// Kill bonus.
new kill_bonus = ClassData[classindex][Class_KillBonus];
if (!(kill_bonus >= ZR_CLASS_KILL_BONUS_MIN && kill_bonus <= ZR_CLASS_KILL_BONUS_MAX))
{
flags += ZR_CLASS_KILL_BONUS;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid kill_bonus at index %d: %d", classindex, kill_bonus);
}
}
// Speed.
new Float:speed = ClassData[classindex][Class_Speed];
new Float:min;
new Float:max;
switch (ClassSpeedMethod)
{
case ClassSpeed_LMV:
{
min = ZR_CLASS_SPEED_LMV_MIN;
max = ZR_CLASS_SPEED_LMV_MAX;
}
case ClassSpeed_Prop:
{
min = ZR_CLASS_SPEED_PROP_MIN;
max = ZR_CLASS_SPEED_PROP_MAX;
}
}
if (!(speed >= min && speed <= max))
{
flags += ZR_CLASS_SPEED;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid speed at index %d: %0.2f", classindex, speed);
}
}
// Knockback.
new Float:knockback = ClassData[classindex][Class_KnockBack];
if (!(knockback >= ZR_CLASS_KNOCKBACK_MIN && knockback <= ZR_CLASS_KNOCKBACK_MAX))
{
flags += ZR_CLASS_KNOCKBACK;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid knockback at index %d: %0.2f", classindex, knockback);
}
}
// Jump height.
new Float:jump_height = ClassData[classindex][Class_JumpHeight];
if (!(jump_height >= ZR_CLASS_JUMP_HEIGHT_MIN && jump_height <= ZR_CLASS_JUMP_HEIGHT_MAX))
{
flags += ZR_CLASS_JUMP_HEIGHT;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid jump_height at index %d: %0.2f", classindex, jump_height);
}
}
// Jump distance.
new Float:jump_distance = ClassData[classindex][Class_JumpDistance];
if (!(jump_distance >= ZR_CLASS_JUMP_DISTANCE_MIN && jump_distance <= ZR_CLASS_JUMP_DISTANCE_MAX))
{
flags += ZR_CLASS_JUMP_DISTANCE;
if (logErrors)
{
LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Config Validation", "Warning: Invalid jump_distance at index %d: %0.2f", classindex, jump_distance);
}
}
return flags;
}
/**
* Validates a set of editable attributes.
*
* @param attributes Attribute set to validate.
* @return 0 if successful, or a bit field (positivie number) of
* failed attributes.
*/
stock ClassValidateEditableAttributes(attributes[ClassEditableAttributes])
{
new flags;
// Model skin index.
new model_skin_index = attributes[ClassEdit_ModelSkinIndex];
if (model_skin_index < ZR_CLASS_MODEL_SKIN_INDEX_MIN)
{
flags += ZR_CLASS_MODEL_SKIN_INDEX;
}
// Alpha initial.
new alphaInitial = attributes[ClassEdit_AlphaInitial];
if (alphaInitial >= 0)
{
if (!(alphaInitial >= ZR_CLASS_ALPHA_INITIAL_MIN && alphaInitial <= ZR_CLASS_ALPHA_INITIAL_MAX))
{
flags += ZR_CLASS_ALPHA_INITIAL;
}
}
// Alpha damaged.
new alphaDamaged = attributes[ClassEdit_AlphaDamaged];
if (alphaDamaged >= 0)
{
if (!(alphaDamaged >= ZR_CLASS_ALPHA_DAMAGED_MIN && alphaDamaged <= ZR_CLASS_ALPHA_DAMAGED_MAX))
{
flags += ZR_CLASS_ALPHA_DAMAGED;
}
}
// Alpha damage.
new alphaDamage = attributes[ClassEdit_AlphaDamage];
if (alphaDamage >= 0)
{
if (!(alphaDamage >= ZR_CLASS_ALPHA_DAMAGE_MIN && alphaDamage <= ZR_CLASS_ALPHA_DAMAGE_MAX))
{
flags += ZR_CLASS_ALPHA_DAMAGE;
}
}
// Overlay.
if (!StrEqual(attributes[ClassEdit_OverlayPath], "nochange", false))
{
decl String:overlay_path[PLATFORM_MAX_PATH];
decl String:overlay[PLATFORM_MAX_PATH];
if (strcopy(overlay_path, sizeof(overlay_path), attributes[ClassEdit_OverlayPath]) > 0)
{
// Check if the file exists.
Format(overlay, sizeof(overlay), "materials/%s.vmt", overlay_path);
if (!FileExists(overlay, true))
{
flags += ZR_CLASS_OVERLAY_PATH;
}
}
}
// Fov.
new fov = attributes[ClassEdit_Fov];
if (fov >= 0)
{
if (!(fov >= ZR_CLASS_FOV_MIN && fov <= ZR_CLASS_FOV_MAX))
{
flags += ZR_CLASS_FOV;
}
}
// Napalm time.
new Float:napalmTime = attributes[ClassEdit_NapalmTime];
if (napalmTime >= 0.0)
{
if (!(napalmTime >= ZR_CLASS_NAPALM_TIME_MIN && napalmTime <= ZR_CLASS_NAPALM_TIME_MAX))
{
flags += ZR_CLASS_NAPALM_TIME;
}
}
// Immunity mode.
new ImmunityMode:immunityMode = attributes[ClassEdit_ImmunityMode];
if (immunityMode == Immunity_Invalid)
{
flags += ZR_CLASS_IMMUNITY_MODE;
}
// Immunity amount.
// TODO: Validate amount value. This depends on the immunity mode.
// Health regen interval.
new Float:healthRegenInterval = attributes[ClassEdit_RegenInterval];
if (healthRegenInterval >= 0.0)
{
if (!(healthRegenInterval >= ZR_CLASS_REGEN_INTERVAL_MIN && healthRegenInterval <= ZR_CLASS_REGEN_INTERVAL_MAX))
{
flags += ZR_CLASS_REGEN_INTERVAL;
}
}
// Health regen amount.
new healthRegenAmount = attributes[ClassEdit_RegenAmount];
if (healthRegenAmount >= 0)
{
if (!(healthRegenAmount >= ZR_CLASS_REGEN_AMOUNT_MIN && healthRegenAmount <= ZR_CLASS_REGEN_AMOUNT_MAX))
{
flags += ZR_CLASS_REGEN_AMOUNT;
}
}
// Infect gain.
new infectGain = attributes[ClassEdit_InfectGain];
if (infectGain >= 0)
{
if (!(infectGain >= ZR_CLASS_HEALTH_INFECT_GAIN_MIN && infectGain <= ZR_CLASS_HEALTH_INFECT_GAIN_MAX))
{
flags += ZR_CLASS_HEALTH_INFECT_GAIN;
}
}
// Kill bonus.
new killBonus = attributes[ClassEdit_KillBonus];
if (killBonus >= 0)
{
if (!(killBonus >= ZR_CLASS_KILL_BONUS_MIN && killBonus <= ZR_CLASS_KILL_BONUS_MAX))
{
flags += ZR_CLASS_KILL_BONUS;
}
}
// Speed.
new Float:speed = attributes[ClassEdit_Speed];
if (speed >= 0)
{
new Float:min;
new Float:max;
switch (ClassSpeedMethod)
{
case ClassSpeed_LMV:
{
min = ZR_CLASS_SPEED_LMV_MIN;
max = ZR_CLASS_SPEED_LMV_MAX;
}
case ClassSpeed_Prop:
{
min = ZR_CLASS_SPEED_PROP_MIN;
max = ZR_CLASS_SPEED_PROP_MAX;
}
}
if (!(speed >= min && speed <= max))
{
flags += ZR_CLASS_SPEED;
}
}
// Knock back.
new Float:knockBack = attributes[ClassEdit_KnockBack];
if (knockBack > ZR_CLASS_KNOCKBACK_IGNORE)
{
if (!(knockBack >= ZR_CLASS_KNOCKBACK_MIN && knockBack <= ZR_CLASS_KNOCKBACK_MAX))
{
flags += ZR_CLASS_KNOCKBACK;
}
}
// Jump heigt.
new Float:jumpHeight = attributes[ClassEdit_JumpHeight];
if (jumpHeight >= 0.0)
{
if (!(jumpHeight >= ZR_CLASS_JUMP_HEIGHT_MIN && jumpHeight <= ZR_CLASS_JUMP_HEIGHT_MAX))
{
flags += ZR_CLASS_JUMP_HEIGHT;
}
}
// Jump distance.
new Float:jumpDistance = attributes[ClassEdit_JumpDistance];
if (jumpDistance >= 0.0)
{
if (!(jumpDistance >= ZR_CLASS_JUMP_DISTANCE_MIN && jumpDistance <= ZR_CLASS_JUMP_DISTANCE_MAX))
{
flags += ZR_CLASS_JUMP_DISTANCE;
}
}
return flags;
}
/**
* Checks if the specified class index is a valid index.
*
* @param classIndex The class index to validate.
* @return True if the class exist, false otherwise.
*/
stock bool:ClassValidateIndex(classIndex)
{
if (classIndex >= 0 && classIndex < ClassCount)
{
return true;
}
else
{
return false;
}
}
/**
* Compares the class team ID with a team ID.
*
* @param index Index of the class in a class cache or a client index,
* depending on the cache type specified.
* @param teamid The team ID to compare with the class.
* @param cachetype Optional. Specifies what class cache to read from. Options:
* ZR_CLASS_CACHE_ORIGINAL - Unchanced class data.
* ZR_CLASS_CACHE_MODIFIED (default) - Changed/newest class
* data.
* ZR_CLASS_CACHE_PLAYER - Player cache. If this one is used,
* index will be used as a client index.
* @return True if equal, false otherwise.
*/
stock bool:ClassTeamCompare(index, teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
{
switch (cachetype)
{
case ZR_CLASS_CACHE_ORIGINAL:
{
if (ClassData[index][Class_Team] == teamid)
{
return true;
}
}
case ZR_CLASS_CACHE_MODIFIED:
{
if (ClassDataCache[index][Class_Team] == teamid)
{
return true;
}
}
case ZR_CLASS_CACHE_PLAYER:
{
if (ClassPlayerCache[index][Class_Team] == teamid)
{
return true;
}
}
}
return false;
}
/**
* Gets the first class index of a class with the specified name (not a case
* sensitive search).
*
* @param name The name to search for.
* @param cachetype Optional. Specifies what class cache to read from. Options:
* ZR_CLASS_CACHE_ORIGINAL - Unchanced class data.
* ZR_CLASS_CACHE_MODIFIED (default) - Changed/newest class
* data.
* @return The class index if successful, -1 otherwise.
*/
stock ClassGetIndex(const String:name[], cachetype = ZR_CLASS_CACHE_MODIFIED)
{
decl String:current_name[64];
// Check if there are no classes, or reading from player cache.
if (ClassCount == 0 || cachetype == ZR_CLASS_CACHE_PLAYER)
{
return -1;
}
// Loop through all classes.
for (new classindex = 0; classindex < ClassCount; classindex++)
{
// Get its name and compare it with the specified class name.
ClassGetName(classindex, current_name, sizeof(current_name), cachetype);
if (strcmp(name, current_name, false) == 0)
{
return classindex;
}
}
// The class index wasn't found.
return -1;
}
/**
* Gets the currently active class index that the player is using.
* Note: Does not check if the player is dead.
*
* @param client The client index.
* @return The active class index. -1 on error or if a spectactor.
*/
stock ClassGetActiveIndex(client)
{
new teamid;
if (!ZRIsClientOnTeam(client))
{
// No active team.
return -1;
}
// Check if the player currently is in admin mode.
if (ClassPlayerInAdminMode[client])
{
teamid = ZR_CLASS_TEAM_ADMINS;
}
else
{
// Not in admin mode, check if player is human or zombie.
if (InfectIsClientHuman(client))
{
teamid = ZR_CLASS_TEAM_HUMANS;
}
else
{
teamid = ZR_CLASS_TEAM_ZOMBIES;
}
}
// Return the active class for the active team.
return ClassSelected[client][teamid];
}
/**
* Gets the multiplier for the specified team and attribute.
*
* @param client The client index.
* @param attribute Specifies what attribute multiplier to get.
* @return Multiplier for the specified team and attribute. 1.0 if the
* client is in admin mode.
*/
stock Float:ClassGetAttributeMultiplier(client, ClassMultipliers:attribute)
{
new teamid;
// Check if player is not in admin mode.
if (!ClassPlayerInAdminMode[client])
{
// Not in admin mode, check if player is human or zombie.
if (InfectIsClientHuman(client))
{
teamid = ZR_CLASS_TEAM_HUMANS;
}
else
{
teamid = ZR_CLASS_TEAM_ZOMBIES;
}
// Get multiplier for the specified team and attribute.
return Float:ClassMultiplierCache[teamid][attribute];
}
else
{
// Do not use multipliers on admin classes.
return 1.0;
}
}
/**
* Check if a class pass the specified filter.
*
* @param index Index of the class in a class cache or a client index,
* depending on the cache type specified.
* @param filter Structure with filter settings.
* @param cachetype Optional. Specifies what class cache to read from.
* ZR_CLASS_CACHE_ORIGINAL - Unchanced class data.
* ZR_CLASS_CACHE_MODIFIED (default) - Changed/newest
* class data.
* ZR_CLASS_CACHE_PLAYER - Player cache. If this one is
* used index will be used as a client index.
* @return True if passed, false otherwise.
*/
stock bool:ClassFilterMatch(index, filter[ClassFilter], cachetype = ZR_CLASS_CACHE_MODIFIED)
{
// Check if the class is disabled and the enabled attribute is NOT ignored.
if (!filter[ClassFilter_IgnoreEnabled] && !ClassIsEnabled(index, cachetype))
{
return false;
}
// Check if class flags pass the flag filter.
if (!ClassFlagFilterMatch(index, filter[ClassFilter_RequireFlags], filter[ClassFilter_DenyFlags], cachetype))
{
return false;
}
// Get class group name.
decl String:groupname[64];
groupname[0] = 0;
ClassGetGroup(index, groupname, sizeof(groupname), cachetype);
// Get class sm_flags.
decl String:sm_flags[64];
sm_flags[0] = 0;
ClassGetSM_Flags(index, sm_flags, sizeof(sm_flags), cachetype);
// Check if a client is specified in the filter.
new client = filter[ClassFilter_Client];
if (ZRIsClientValid(client))
{
// Check if a group is set on the class.
if (strlen(groupname))
{
// Check if the client is not a member of that group.
if (!ZRIsClientInGroup(client, groupname))
{
return false;
}
}
// Check if there are any sm_flags set.
if (strlen(sm_flags))
{
int flags = ReadFlagString(sm_flags);
// No valid flag, blocked for everyone.
if(!flags)
return false;
// Check if user doesn't have the required flags.
if(GetUserFlagBits(client) & flags != flags)
return false;
}
}
// Check if classes with groups are set to be excluded.
if (client < 0)
{
// Exclude class if it has a group name.
if (strlen(groupname))
{
return false;
}
// Exclude class if it requires flags.
if (strlen(sm_flags))
{
return false;
}
}
// The class passed the filter.
return true;
}
/**
* Check if a class pass the specified flag filters.
*
* @param index Index of the class in a class cache or a client index,
* depending on the cache type specified.
* @param require Class flags to require. 0 for no filter.
* @param deny Class flags to exclude. 0 for no filter.
* @param cachetype Specifies what class cache to read from. Options:
* ZR_CLASS_CACHE_ORIGINAL - Unchanced class data.
* ZR_CLASS_CACHE_MODIFIED (default) - Changed/newest
* class data.
* ZR_CLASS_CACHE_PLAYER - Player cache. If this one is
* used index will be used as a client index.
* @return True if passed, false otherwise.
*/
stock bool:ClassFlagFilterMatch(index, require, deny, cachetype)
{
new flags;
new bool:requirepassed = false;
new bool:denypassed = false;
// Do quick check for optimization reasons: Check if no flags are specified.
if (require == 0 && deny == 0)
{
return true;
}
// Cache flags.
flags = ClassGetFlags(index, cachetype);
// Match require filter.
if (require == 0 || flags & require)
{
// All required flags are set.
requirepassed = true;
}
// Match deny filter.
if (deny == 0 || !(flags & deny))
{
// No denied flags are set.
denypassed = true;
}
// Check if required and denied flags passed the filter.
if (requirepassed && denypassed)
{
// The class pass the filter.
return true;
}
// The class didn't pass the filter.
return false;
}
/**
* Decides whether a class selection menu should be enabled. The decision is
* based on zr_class_allow_* console variables.
*
* @param team Optional. Team ID to match. Default is all.
* @param filter Optional. Filter to use on classes.
* @return True if allowed, false otherwise.
*/
bool:ClassAllowSelection(client, team = -1, filter[ClassFilter] = ClassNoFilter)
{
// Get selection settings.
new bool:zombie = GetConVarBool(g_hCvarsList[CVAR_CLASSES_ZOMBIE_SELECT]);
new bool:human = GetConVarBool(g_hCvarsList[CVAR_CLASSES_HUMAN_SELECT]);
new bool:admin = GetConVarBool(g_hCvarsList[CVAR_CLASSES_ADMIN_SELECT]);
// Since admin mode classes are optional they must be counted to verify
// that they exist.
new bool:adminexist;
// Check if player is admin.
new bool:isadmin = ZRIsClientAdmin(client);
// Only count admin mode classes if client is admin.
if (isadmin)
{
adminexist = ClassCountTeam(ZR_CLASS_TEAM_ADMINS, filter) > 0;
}
// Check if a team id is specified.
if (team >= 0)
{
// Check team and return the corresponding selection setting.
switch (team)
{
case ZR_CLASS_TEAM_ZOMBIES:
{
return zombie;
}
case ZR_CLASS_TEAM_HUMANS:
{
return human;
}
case ZR_CLASS_TEAM_ADMINS:
{
// Player must be admin to select admin mode classes.
return admin && isadmin && adminexist;
}
}