-
Notifications
You must be signed in to change notification settings - Fork 0
/
TeamBalancerByFrags.sma
2406 lines (1988 loc) · 67.9 KB
/
TeamBalancerByFrags.sma
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 tabsize 0
#pragma semicolon 0
#pragma dynamic 4194304
// Use "\"some quoted string inside a string\"" instead of the default "^"some quoted string inside a string^""
//
#pragma ctrlchar '\'
/*** ----------------------------------------------------------------------------------------------------------------------- ***/
#include < amxmodx > // register_cvar, ...
#include < cstrike > // cs_set_user_team, ... /* If you are not running `CS:DM` you can avoid the use of the `CSTRIKE` module by commenting this line */
#include < hamsandwich > // RegisterHam, ... /* If you are running `CS:DM` you can avoid the use of the `HAMSANDWICH` module by commenting this line */
// Use the `FAKEMETA` module if the `CSTRIKE` module is excluded by the user
//
#if !defined _cstrike_included
#include < fakemeta > // set_pdata_int, ...
#endif
/*** ----------------------------------------------------------------------------------------------------------------------- ***/
// If the `FAKEMETA` module isn't included
//
#if !defined _fakemeta_included
native dllfunc( const nType, const any: ... ); /* Optional */ // The game server does not need to have this function [ `FAKEMETA` module ]
#endif
// If the `FUN` module isn't included
//
#if !defined _fun_included
native spawn( const nEntity ); /* Optional */ // The game server does not need to have this function [ `FUN` module ]
#endif
// If the `CSTRIKE` module isn't included
//
#if !defined _cstrike_included
native cs_user_spawn( const nPlayer ); /* Optional */ // The game server does not need to have this function [ `CSTRIKE` module ]
#endif
// If the `CS:DM` module isn't included
//
#if !defined _csdm_included
native bool: csdm_active( ); /* Optional */ // The game server does not need to have this function [ `CS:DM` module ]
native Float: csdm_get_spawnwait( ); /* Optional */ // The game server does not need to have this function [ `CS:DM` module ]
native csdm_set_spawnwait( const Float: fTime ); /* Optional */ // The game server does not need to have this function [ `CS:DM` module ]
native csdm_respawn( const nPlayer ); /* Optional */ // The game server does not need to have this function [ `CS:DM` module ]
#endif
/*** ----------------------------------------------------------------------------------------------------------------------- ***/
// If the `CSTRIKE` module isn't included
//
#if !defined _cstrike_included
#if !defined CsTeams
#if !defined CS_TEAM_UNASSIGNED
// CS/ CZ teams
//
enum CsTeams
{
CS_TEAM_UNASSIGNED = 0,
CS_TEAM_T = 1,
CS_TEAM_CT = 2,
CS_TEAM_SPECTATOR = 3,
};
#endif
#endif
// `get_pdata_int` as `cs_get_user_team`
//
#define cs_get_user_team(%0) CsTeams: get_pdata_int( %0, 114 /* CS/ CZ team member offset */ )
// `set_pdata_int` as `cs_set_user_team`
//
#define cs_set_user_team(%0,%1) set_pdata_int( %0, 114 /* CS/ CZ team member offset */, any: %1 )
#endif
/*** ----------------------------------------------------------------------------------------------------------------------- ***/
// The plugin version
//
static const g_szPluginVersion[ ] = "8.1";
// The game sound directory name
//
static const g_szSoundDirectoryName[ ] = "sound";
// The wave audio file path (optional to be uploaded to the game server & then downloaded by the players)
//
static const g_szWaveAudioFilePath[ ] = "team_balancer_by_frags/transfer.wav";
// A random number
//
static const g_nRandomNumber = -7105824;
/*** ----------------------------------------------------------------------------------------------------------------------- ***/
// Check whether the server is running `CS:DM` (has valid `csdm_active` console variable)
//
static g_nCsdmActive;
// For performance, use a variable for `CS:DM` active status storage
//
static bool: g_bCsdmActive;
// Console variable to set the checking frequency in seconds
//
static g_nFrequency;
// Console variable to allow bots computation delay after humans are computed to avoid chat spamming (humans are computed first)
//
static g_nBotsDelay;
// Console variable to control whether or not the player should be respawned when transferred
//
static g_nRespawn;
// Console variable to control whether or not to use `csdm_respawn` function if it exists
//
static g_nRespawnType;
// Console variable to control the delay between the player respawn moment and the announcements and the screen fade execution
//
static g_nRespawnDelay;
// Console variable to set the maximum difference between terrorists and counter terrorists
//
static g_nDifference_TE;
// Console variable to set maximum difference between counter terrorists and terrorists
//
static g_nDifference_CT;
// Console variable to set whether these transferrings are made by low frags or by high frags
//
static g_nSetting;
// Cached for performance
//
static bool: g_bSetting;
// Console variable intended to store the plugin version
//
static g_nVersion;
// The plugin chat (talk) tag
//
static g_nTag;
// The plugin chat (talk) tag cached for performance
//
static g_szTag[ 64 ];
// Console variable to set whether this plugin auto decides if the player picked up for transfer has the lowest or the highest score (frags)
// from his team depending on the enemy team overall scoring
//
static g_nAuto;
// Cached for performance
//
static g_nAutoNum;
// Console variable to allow sorting (by using this feature we allow the game server to transfer the second or the third best player for example),
// in order to transfer the one that is the most appropiate based on their score (frags)
//
static g_nSorting;
// Cached for performance
//
static g_nSortingNum;
// Console variable to set whether or not to use audio alert when transferring a player
//
static g_nAudio;
// Cached for performance
//
static g_nAudioNum;
// Console variable to control how the audio alert is sent
//
// 0 speak into the transferred player ears only (a teleport like sound effect)
// 1 that player emits the sound (a teleport like sound effect) globally and other close positioned players are able to hear that too at a lower volume
// 2 speak into the transferred player ears only (a man speaking words "YOUR NOW [ T / C T ] FORCE")
//
static g_nAudioType;
// Cached for performance
//
static g_nAudioTypeNum;
// Console variable to control whether or not to consider bots humans
//
// 1 consider bots humans
// 0 bots are balanced half T force & half CT force
//
static g_nBots;
// For performance reasons cache the 'team_balancer_bots' value
//
static bool: g_bBotsAreLikeHumans;
// Console variable to allow a global chat message announcing the transfer
//
// 0 off
// 1 on
// 2 on & colored
//
static g_nAnnounceAll;
// Cached for performance
//
static g_nAnnounceAllNum;
// Console variable to announce the player on their screen when transferred
//
static g_nAnnounce;
// Cached for performance
//
static g_nAnnounceNum;
// Console variable to set the transferred player screen announce type
//
// 0 print_center (screen middle)
// 1 print_chat (print_talk [screen left bottom])
// 2 print_chat (print_talk [screen left bottom]) colored
//
static g_nAnnounceType;
// Cached for performance
//
static g_nAnnounceTypeNum;
// Console variable to set a screen fade for the transferred player
//
static g_nScreenFade;
// Console variable to set the duration for the screen fade
//
static g_nScreenFadeDuration;
// Console variable to set the hold time for the screen fade
//
static g_nScreenFadeHoldTime;
// Console variable to set the RGBA color for the terrorist force screen fade
//
static g_nScreenFadeRGBA_TE[ 4 ];
// Console variable to set the RGBA color for the counter terrorist force screen fade
//
static g_nScreenFadeRGBA_CT[ 4 ];
// The `ScreenFade` game message index
//
static g_nScreenFadeMsg;
// The `SayText` game message index
//
static g_nSayTextMsg;
// Console variable to set the immune admin flag
//
static g_nFlag;
// Variable to store the immune admin flag (for performance)
//
static g_nFlagNum;
// Total T team score (frags)
//
static g_nScoring_TE;
// Total CT team score (frags)
//
static g_nScoring_CT;
// Variable used to reveal whether or not the actual round has ended, useful if the `CS:DM` extension is disabled
//
static bool: g_bCanBalance;
// If enabled, balance only during round end if `CS:DM` is disabled
//
static g_nRoundEndOnly;
// Cached for performance
//
static bool: g_bRoundEndOnly;
// If enabled, when balancing the teams only during round end while the `CS:DM` extension is disabled or missing,
// ignore the `team_balancer_frequency` and `team_balancer_bots_delay` console variables and perform everything very quick
//
static g_nRoundEndQuick;
// Cached for performance
//
static bool: g_bRoundEndQuick;
// Do not respawn if the `CS:DM` extension is missing or disabled
//
static g_nNoRespawn;
// If the `HAMSANDWICH` module is included
//
#if defined _hamsandwich_included
// Whether or not the players can kill each other if they are enemies
//
static bool: g_bAreThePlayersImmune;
// The player is taking damage
//
static HamHook: g_eOnTakeDamage;
// The player is being attacked
//
static HamHook: g_eOnTraceAttack;
// Check whether or not the script is compiled with a recent AMX Mod X edition
//
#if defined amxclient_cmd && defined RegisterHamPlayer
// On recent AMX Mod X editions, CS/ CZ original bots are already registered
//
#else // defined amxclient_cmd && defined RegisterHamPlayer
// Whether or not the CS/ CZ original bots are registered
//
static bool: g_bAreTheFakePlayersRegistered;
// The fake player is taking damage
//
static HamHook: g_eOnTakeDamage_BOTS;
// The fake player is being attacked
//
static HamHook: g_eOnTraceAttack_BOTS;
// `bot_quota` console variable index
//
static g_nQuota;
#endif
#endif
// Console variable to also allow the transfer of alive players in game servers which are not `CS:DM` or are `CS:DM` but `csdm_active` disabled
//
static g_nAlsoTransferAlive;
// Maximum players the game server can handle
//
static g_nMaximumPlayers;
// Do not execute two bot transfers consecutively
//
static bool: g_bHaveManagedTheBots;
// Round start time
//
static Float: g_fRoundStartTime;
// Executes after a map starts
//
public plugin_init( )
{
register_plugin( "Team Balancer by Frags", g_szPluginVersion, "Hattrick (claudiuhks)" );
{
// Register the version console variable
//
g_nVersion = register_cvar( "team_balancer_by_frags", g_szPluginVersion, FCVAR_SERVER | FCVAR_UNLOGGED | FCVAR_EXTDLL );
}
g_nFrequency = register_cvar( "team_balancer_frequency", "5.0" );
g_nBotsDelay = register_cvar( "team_balancer_bots_delay", "2.5" );
g_nDifference_TE = register_cvar( "team_balancer_te_difference", "1" );
g_nDifference_CT = register_cvar( "team_balancer_ct_difference", "1" );
g_nSetting = register_cvar( "team_balancer_by_low_frags", "1" );
g_nAuto = register_cvar( "team_balancer_auto", "1" );
g_nBots = register_cvar( "team_balancer_bots", "0" );
g_nAnnounce = register_cvar( "team_balancer_announce", "1" );
g_nAnnounceType = register_cvar( "team_balancer_announce_type", "0" );
g_nAnnounceAll = register_cvar( "team_balancer_announce_all", "2" );
g_nFlag = register_cvar( "team_balancer_admin_flag", "a" );
g_nTag = register_cvar( "team_balancer_talk_tag", "[Team Balancer]" );
g_nAudio = register_cvar( "team_balancer_audio", "1" );
g_nAudioType = register_cvar( "team_balancer_audio_type", "0" );
g_nScreenFade = register_cvar( "team_balancer_screen_fade", "1" );
g_nScreenFadeDuration = register_cvar( "team_balancer_sf_duration", "1.0" );
g_nScreenFadeHoldTime = register_cvar( "team_balancer_sf_hold_time", "0.1" );
g_nSorting = register_cvar( "team_balancer_sorting", "1" );
g_nRespawn = register_cvar( "team_balancer_respawn", "1" );
g_nRespawnType = register_cvar( "team_balancer_respawn_type", "1" );
g_nRespawnDelay = register_cvar( "team_balancer_respawn_delay", "0.25" );
g_nRoundEndOnly = register_cvar( "team_balancer_round_end_only", "1" );
g_nRoundEndQuick = register_cvar( "team_balancer_round_end_quick", "1" );
g_nNoRespawn = register_cvar( "team_balancer_no_respawn", "1" );
g_nAlsoTransferAlive = register_cvar( "team_balancer_transfer_alive", "1" );
g_nScreenFadeRGBA_TE[ 0 ] = register_cvar( "team_balancer_sf_te_r", "200" ); // Red
g_nScreenFadeRGBA_TE[ 1 ] = register_cvar( "team_balancer_sf_te_g", "40" ); // Green
g_nScreenFadeRGBA_TE[ 2 ] = register_cvar( "team_balancer_sf_te_b", "0" ); // Blue
g_nScreenFadeRGBA_TE[ 3 ] = register_cvar( "team_balancer_sf_te_a", "240" ); // Alpha
g_nScreenFadeRGBA_CT[ 0 ] = register_cvar( "team_balancer_sf_ct_r", "0" ); // Red
g_nScreenFadeRGBA_CT[ 1 ] = register_cvar( "team_balancer_sf_ct_g", "40" ); // Green
g_nScreenFadeRGBA_CT[ 2 ] = register_cvar( "team_balancer_sf_ct_b", "200" ); // Blue
g_nScreenFadeRGBA_CT[ 3 ] = register_cvar( "team_balancer_sf_ct_a", "240" ); // Alpha
set_task( 0.25, "T_Install", get_systime( 0 ) );
register_event( "HLTV", "E_OnRoundLaunch", "a", "1=0", "2=0" );
{
register_logevent( "LE_OnRoundEnd", 2, "1=Round_End" );
}
return PLUGIN_CONTINUE;
}
// Executes when a new round begins
//
public E_OnRoundLaunch( const nValue )
{
g_bCanBalance = false;
g_fRoundStartTime = get_gametime( );
// If the `HAMSANDWICH` module is included
//
#if defined _hamsandwich_included
#if defined DisableHamForward
DisableHamForward( g_eOnTakeDamage );
DisableHamForward( g_eOnTraceAttack );
// Check whether or not the script is compiled with a recent AMX Mod X edition
//
#if defined amxclient_cmd && defined RegisterHamPlayer
// On recent AMX Mod X editions, CS/ CZ original bots are already registered
//
#else // defined amxclient_cmd && defined RegisterHamPlayer
if( g_bAreTheFakePlayersRegistered )
{
DisableHamForward( g_eOnTakeDamage_BOTS );
DisableHamForward( g_eOnTraceAttack_BOTS );
}
#endif
#endif
g_bAreThePlayersImmune = false;
#endif
return PLUGIN_CONTINUE;
}
// Can start balancing the teams now at the end of the round (after 1.6 seconds the round has ended)
//
public T_RunBalancing( const nTask )
{
// A protection to not balance the teams during the round
//
if( g_fRoundStartTime > 0.0 )
{
if( ( get_gametime( ) - g_fRoundStartTime ) < 2.0 )
{
g_bCanBalance = false;
return PLUGIN_CONTINUE;
}
}
// Do not start balancing if there were no new rounds at all
//
else
{
g_bCanBalance = false;
return PLUGIN_CONTINUE;
}
g_bCanBalance = true;
return PLUGIN_CONTINUE;
}
// Executes when a round ends
//
public LE_OnRoundEnd( )
{
static nSysTime;
nSysTime = get_systime( 0 );
{
set_task( 1.6, "T_RunBalancing", nSysTime );
{
set_task( 3.9, "T_StopBalancing", nSysTime );
}
}
// If the `HAMSANDWICH` module is included
//
#if defined _hamsandwich_included
#if defined EnableHamForward
EnableHamForward( g_eOnTakeDamage );
EnableHamForward( g_eOnTraceAttack );
// Check whether or not the script is compiled with a recent AMX Mod X edition
//
#if defined amxclient_cmd && defined RegisterHamPlayer
// On recent AMX Mod X editions, CS/ CZ original bots are already registered
//
#else // defined amxclient_cmd && defined RegisterHamPlayer
if( g_bAreTheFakePlayersRegistered )
{
EnableHamForward( g_eOnTakeDamage_BOTS );
EnableHamForward( g_eOnTraceAttack_BOTS );
}
#endif
#endif
g_bAreThePlayersImmune = true;
#endif
return PLUGIN_CONTINUE;
}
// If the `HAMSANDWICH` module is included
//
#if defined _hamsandwich_included
// The player or the fake player is taking damage
//
public OnPlayerTakeDamage_PRE( const nPlayer, const nInflictor, const nAttacker, const Float: fDamage, const nDamageType )
{
if( !g_bAreThePlayersImmune )
{
return HAM_IGNORED;
}
if( nAttacker < 1 )
{
return HAM_IGNORED;
}
if( nAttacker > g_nMaximumPlayers )
{
return HAM_IGNORED;
}
if( nAttacker == nPlayer )
{
return HAM_IGNORED;
}
if( cs_get_user_team( nPlayer ) == cs_get_user_team( nAttacker ) )
{
return HAM_IGNORED;
}
return HAM_SUPERCEDE;
}
// The player or the fake player is being attacked
//
public OnPlayerTraceAttack_PRE( const nPlayer, const nAttacker, const Float: fDamage, const Float: pfVelocity[3], const nTrace, const nDamageType )
{
if( !g_bAreThePlayersImmune )
{
return HAM_IGNORED;
}
if( nAttacker < 1 )
{
return HAM_IGNORED;
}
if( nAttacker > g_nMaximumPlayers )
{
return HAM_IGNORED;
}
if( nAttacker == nPlayer )
{
return HAM_IGNORED;
}
if( cs_get_user_team( nPlayer ) == cs_get_user_team( nAttacker ) )
{
return HAM_IGNORED;
}
return HAM_SUPERCEDE;
}
#endif
// Executes before `plugin_init`
//
public plugin_precache( )
{
new szBuffer[ 256 ];
{
formatex( szBuffer, charsmax( szBuffer ), "%s/%s", g_szSoundDirectoryName, g_szWaveAudioFilePath );
{
// If the file exists
//
if( file_exists( szBuffer ) )
{
// The players will then download it
//
precache_sound( g_szWaveAudioFilePath );
}
}
}
return PLUGIN_CONTINUE;
}
// Executes after `plugin_init`
//
public plugin_cfg( )
{
g_nScreenFadeMsg = get_user_msgid( "ScreenFade" );
g_nSayTextMsg = get_user_msgid( "SayText" );
g_nCsdmActive = get_cvar_pointer( "csdm_active" );
g_nMaximumPlayers = get_maxplayers( );
// If the `HAMSANDWICH` module is included
//
#if defined _hamsandwich_included
// Check whether or not the script is compiled with a recent AMX Mod X edition
//
#if defined amxclient_cmd && defined RegisterHamPlayer
g_eOnTakeDamage = RegisterHam( Ham_TakeDamage, "player", "OnPlayerTakeDamage_PRE", 0, true );
g_eOnTraceAttack = RegisterHam( Ham_TraceAttack, "player", "OnPlayerTraceAttack_PRE", 0, true );
#else // defined amxclient_cmd && defined RegisterHamPlayer
g_eOnTakeDamage = RegisterHam( Ham_TakeDamage, "player", "OnPlayerTakeDamage_PRE" );
g_eOnTraceAttack = RegisterHam( Ham_TraceAttack, "player", "OnPlayerTraceAttack_PRE" );
g_nQuota = get_cvar_pointer( "bot_quota" );
#endif
#if defined DisableHamForward
DisableHamForward( g_eOnTakeDamage );
DisableHamForward( g_eOnTraceAttack );
#endif
#endif
if( g_nVersion > 0 )
{
set_pcvar_string( g_nVersion, g_szPluginVersion );
}
return PLUGIN_CONTINUE;
}
// If the `HAMSANDWICH` module is included
//
#if defined _hamsandwich_included
// Check whether or not the script is compiled with a recent AMX Mod X edition
//
#if defined amxclient_cmd && defined RegisterHamPlayer
// On recent AMX Mod X editions, CS/ CZ original bots are already registered
//
#else // defined amxclient_cmd && defined RegisterHamPlayer
// The player connects
//
public client_connect( nPlayer )
{
static nThePlayerUserIndex;
if( g_bAreTheFakePlayersRegistered )
{
return PLUGIN_CONTINUE;
}
if( 1 > g_nQuota )
{
return PLUGIN_CONTINUE;
}
if( nPlayer < 1 )
{
return PLUGIN_CONTINUE;
}
if( nPlayer > g_nMaximumPlayers )
{
return PLUGIN_CONTINUE;
}
if( 1 > get_pcvar_num( g_nQuota ) )
{
return PLUGIN_CONTINUE;
}
if( is_user_hltv( nPlayer ) )
{
return PLUGIN_CONTINUE;
}
if( !is_user_bot( nPlayer ) )
{
return PLUGIN_CONTINUE;
}
nThePlayerUserIndex = get_user_userid( nPlayer );
if( nThePlayerUserIndex < 0 )
{
return PLUGIN_CONTINUE;
}
set_task( 0.0, "RegisterHamForTheFakePlayer", nThePlayerUserIndex );
return PLUGIN_CONTINUE;
}
public RegisterHamForTheFakePlayer( const nTheTaskIndexAsThePlayerUserId )
{
static nTheFakePlayer;
if( g_bAreTheFakePlayersRegistered )
{
return PLUGIN_CONTINUE;
}
if( nTheTaskIndexAsThePlayerUserId < 0 )
{
return PLUGIN_CONTINUE;
}
#if defined FindPlayer_IncludeConnecting
nTheFakePlayer = find_player_ex( FindPlayer_MatchUserId | FindPlayer_IncludeConnecting, nTheTaskIndexAsThePlayerUserId );
#else // defined FindPlayer_IncludeConnecting
nTheFakePlayer = RetrievePlayerIdByPlayerUserId( nTheTaskIndexAsThePlayerUserId );
#endif
if( nTheFakePlayer < 1 )
{
return PLUGIN_CONTINUE;
}
if( nTheFakePlayer > g_nMaximumPlayers )
{
return PLUGIN_CONTINUE;
}
if( !is_user_connected( nTheFakePlayer ) )
{
#if defined is_user_connecting
if( !is_user_connecting( nTheFakePlayer ) )
{
return PLUGIN_CONTINUE;
}
#else // defined is_user_connecting
return PLUGIN_CONTINUE;
#endif
}
if( is_user_hltv( nTheFakePlayer ) )
{
return PLUGIN_CONTINUE;
}
if( !is_user_bot( nTheFakePlayer ) )
{
return PLUGIN_CONTINUE;
}
g_eOnTakeDamage_BOTS = RegisterHamFromEntity( Ham_TakeDamage, nTheFakePlayer, "OnPlayerTakeDamage_PRE" );
g_eOnTraceAttack_BOTS = RegisterHamFromEntity( Ham_TraceAttack, nTheFakePlayer, "OnPlayerTraceAttack_PRE" );
#if defined DisableHamForward
if( !g_bAreThePlayersImmune )
{
DisableHamForward( g_eOnTakeDamage_BOTS );
DisableHamForward( g_eOnTraceAttack_BOTS );
}
#endif
g_bAreTheFakePlayersRegistered = true;
return PLUGIN_CONTINUE;
}
#if !defined FindPlayer_IncludeConnecting
static RetrievePlayerIdByPlayerUserId( const &nThePlayerUserIndex )
{
static nPlayer;
if( nThePlayerUserIndex < 0 )
{
return 0;
}
for( nPlayer = 1; nPlayer <= g_nMaximumPlayers; nPlayer++ )
{
if( nThePlayerUserIndex == get_user_userid( nPlayer ) )
{
return nPlayer;
}
}
return 0;
}
#endif
#endif
#endif
// When a native is being computed
//
public F_Natives( const szNative[ ], const nNative, const bool: bFound )
{
// Not found on the game server
//
if( !bFound )
{
if( strcmp( szNative, "dllfunc", true ) == 0 || /* FAKEMETA module */
strcmp( szNative, "spawn", true ) == 0 || /* FUN module */
strcmp( szNative, "cs_user_spawn", true ) == 0 || /* CSTRIKE module */
strcmp( szNative, "csdm_respawn", true ) == 0 || /* CS:DM module */
strcmp( szNative, "csdm_active", true ) == 0 || /* CS:DM module */
strcmp( szNative, "csdm_get_spawnwait", true ) == 0 || /* CS:DM module */
strcmp( szNative, "csdm_set_spawnwait", true ) == 0 ) /* CS:DM module */
{
return PLUGIN_HANDLED; /* I understand that for some reason this native does not exist on the game server so don't throw any error to the logging system */
}
}
return PLUGIN_CONTINUE;
}
// When the plugin computes the natives
//
public plugin_natives( )
{
set_native_filter( "F_Natives" );
return PLUGIN_CONTINUE;
}
// A task to stop the team balancing when needed
//
public T_StopBalancing( const nTask )
{
g_bCanBalance = false;
return PLUGIN_CONTINUE;
}
// Get ready
//
public T_Install( const nTask )
{
set_task( get_pcvar_float( g_nFrequency ), "T_CheckTeams", get_systime( 0 ), "", 0, "b" ); // Repeat indefinitely
return PLUGIN_CONTINUE;
}
// Check the teams
//
public T_CheckTeams( const nTask )
{
// Data
//
static szName[ 32 ], szFlag[ 2 ], pnPlayers_TE[ 32 ], pnPlayers_CT[ 32 ], nNum_TE, nNum_CT, nPlayer, Float: fTime, nUserId;
// Erase the bots management stamp, managing humans now
//
g_bHaveManagedTheBots = false;
// Cache global data for performance
//
g_bBotsAreLikeHumans = bool: get_pcvar_num( g_nBots );
{
g_nAnnounceTypeNum = get_pcvar_num( g_nAnnounceType );
{
g_nAnnounceNum = get_pcvar_num( g_nAnnounce );
{
g_nAudioTypeNum = get_pcvar_num( g_nAudioType );
{
g_nAudioNum = get_pcvar_num( g_nAudio );
{
g_nAnnounceAllNum = get_pcvar_num( g_nAnnounceAll );
{
g_bRoundEndQuick = bool: get_pcvar_num( g_nRoundEndQuick );
{
g_bRoundEndOnly = bool: get_pcvar_num( g_nRoundEndOnly );
{
g_bSetting = bool: get_pcvar_num( g_nSetting );
{
g_nAutoNum = get_pcvar_num( g_nAuto );
{
g_nSortingNum = get_pcvar_num( g_nSorting );
{
get_pcvar_string( g_nTag, g_szTag, charsmax( g_szTag ) );
{
get_pcvar_string( g_nFlag, szFlag, charsmax( szFlag ) );
{
g_nFlagNum = read_flags( szFlag );
}
if( g_nCsdmActive > 0 )
{
g_bCsdmActive = ( get_pcvar_num( g_nCsdmActive ) && module_exists( "csdm" ) && csdm_active( ) );
}
else
{
g_bCsdmActive = false;
}
}
}
}
}
}
}
}
}
}
}
}
}
if( !g_bCsdmActive )
{
if( g_bRoundEndQuick )
{
if( g_bRoundEndOnly )
{
// Perform the transfers very quick
//