-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathteambalance.sp
More file actions
754 lines (608 loc) · 19.3 KB
/
teambalance.sp
File metadata and controls
754 lines (608 loc) · 19.3 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
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <ctban>
#include <meitisstocks>
#include <mapvariables>
#include <teambalance>
#include <lastrequest>
// @TODO: move all IsCTBanned checks and the <ctban> out of here, that doesn't belong here imo. CT joins could be blocked in ctban plugin using teambalancer forwards
// @TODO: use OnCTBanned forward to remove from guard queue?
// @TODO: consider switching ArrayList to arrays with MAXPLAYERS size + length variable for performance? (probably not worth it)
public Plugin myinfo =
{
name = "Jailbreak Teambalancer",
author = "Meitis",
description = "This plugin makes sure the team ratio is properly kept",
version = "0.2",
url = ""
}
enum EJoinTeamReason
{
k_OneTeamChange=0,
k_TeamsFull=1,
k_TTeamFull=2,
k_CTTeamFull=3,
k_CannotBeSpectator=4,
k_HumansJoinTeamT=5,
k_HumansJoinTeamCT=6,
k_TooManyTerrorists=7,
k_TooManyCTs=8
}
bool g_bJoinedWillingly[MAXPLAYERS+1];
bool g_bNeedsInitialTeam[MAXPLAYERS+1] = { true, ...};
bool g_bLastRequestStarted;
char g_sMap[64];
int g_iTSpawnCount = -1;
int g_iCTSpawnCount = -1;
//int g_iSelectedTeam[MAXPLAYERS+1];
float g_flTeamRatio = 3.0;
ArrayList g_aCTList = null;
ArrayList g_aGuardQueue = null;
Handle g_hJoinGuardAttempt = null;
ConVar g_cDefaultRatio = null;
ConVar g_cMaxRatio = null;
ConVar g_cMinRatio = null;
ConVar g_cExpandRate = null;
ConVar g_cContractRate = null;
public void OnPluginStart()
{
g_aCTList = new ArrayList();
g_aGuardQueue = new ArrayList();
CreateConfig();
RegisterCommands();
HookEvents();
g_hJoinGuardAttempt = CreateGlobalForward("Teambalance_OnGuardJoinAttempt", ET_Event, Param_Cell);
}
void CreateConfig()
{
g_cDefaultRatio = CreateConVar("sm_teambalance_ratio", "3.0", "Set the default ratio on map start for the teambalancing");
g_cMaxRatio = CreateConVar("sm_teambalance_maxratio", "4.5", "The maximum ratio that can be reached by the dynamic teamratio calculation");
g_cMinRatio = CreateConVar("sm_teambalance_minratio", "2.0", "The minimum ratio that can be reached by the dynamic teamratio calculation");
g_cExpandRate = CreateConVar("sm_teambalance_expandratio", "0.15", "The rate at which the ratio can expand");
g_cContractRate = CreateConVar("sm_teambalance_contractratio", "0.25", "The rate at which the ratio can contract");
AutoExecConfig();
}
public void OnMapStart()
{
// As long as we haven't gotten the dynamic teamratio from the database yet, set it on a default
g_flTeamRatio = g_cDefaultRatio.FloatValue;
g_aGuardQueue.Clear();
g_aCTList.Clear();
g_iTSpawnCount = -1;
g_iCTSpawnCount = -1;
GetCurrentMap(g_sMap, sizeof(g_sMap));
// Give plugins a chance to create new spawns
CreateTimer(0.1, Timer_OnMapStart);
}
public void OnMapEnd()
{
SetMapVariableFloat("teamratio", g_flTeamRatio);
}
public void OnClientPutInServer(int client)
{
g_bNeedsInitialTeam[client] = true;
g_bJoinedWillingly[client] = true;
// Just to be sure if any of the logic messes up we don't fuck things up completely
//g_iSelectedTeam[client] = CS_TEAM_T;
}
public Action Timer_OnMapStart(Handle timer) // Passing any data as argument here is not required
{
g_iTSpawnCount = 0;
g_iCTSpawnCount = 0;
int iEnt = -1;
while((iEnt = FindEntityByClassname(iEnt, "info_player_counterterrorist")) != -1) ++g_iCTSpawnCount;
iEnt = -1;
while((iEnt = FindEntityByClassname(iEnt, "info_player_terrorist")) != -1) ++g_iTSpawnCount;
return Plugin_Stop;
}
public void OnMapVariablesFetched()
{
//LogMessage("Starting map with %f before getting mapvariables", g_flTeamRatio);
GetMapVariableFloat("teamratio", g_flTeamRatio);
//LogMessage("Starting map with %f after getting mapvariables", g_flTeamRatio);
}
Action AddGuard(int client)
{
int iUserId = GetClientUserId(client);
int iQueuePosition = g_aGuardQueue.FindValue(iUserId);
int iTargetTeamPlayerCount = GetTeamClientCount(CS_TEAM_CT);
int iCurrentTeam = GetClientTeam(client);
if (iCurrentTeam == CS_TEAM_CT)
{
// You are CT already, why would you still need to be changed to it
PrintToChat(client, "You are CT already, why would you need us to change you to it silly?");
return Plugin_Handled;
}
/*if (IsCTBanned(client)) // @TODO: Might be useful to move this to the JoinGuardAttempt forward so we have all ctban logic in one plugin
{
PrintHintText(client, "You are currently ctbanned and thus can't join CT");
return Plugin_Handled;
}*/
Action canJoin = JoinGuardAttempt(client); // Let other plugins know someone is trying to join CT and handle if necessary
if (canJoin != Plugin_Continue)
{
if (iCurrentTeam == CS_TEAM_NONE)
{
// Make sure the player at the very least has an initial team
CS_SwitchTeam(client, CS_TEAM_T);
if (GetTeamClientCount(CS_TEAM_T) == 1)
{
CS_RespawnPlayer(client);
}
}
return canJoin;
}
if (iTargetTeamPlayerCount == 0)
{
// Let the first CT join freely so we can start playing, but remove him from the queue first if he's in it
// These are normally taken care of in the Event_PlayerTeam logic
//if (iQueuePosition != -1)
//{
// g_aGuardQueue.Erase(iQueuePosition);
//}
//g_aCTList.Push(iUserId);
g_bJoinedWillingly[client] = true;
return Plugin_Continue;
}
else
{
if (iQueuePosition == -1)
{
g_aGuardQueue.Push(iUserId);
PrintToChat(client, "You have been added to the guard queue! There are %d players in the queue in total.", g_aGuardQueue.Length);
}
else
{
PrintToChat(client, "You are already waiting in the guard queue! There are %d players in the queue in total.", g_aGuardQueue.Length);
}
return Plugin_Handled;
}
}
void RemoveFromGuardQueue(int client)
{
int iUserId = GetClientUserId(client);
int iQueuePosition = g_aGuardQueue.FindValue(iUserId);
if (iQueuePosition != -1)
{
// This person is in the guard queue
g_aGuardQueue.Erase(iQueuePosition);
}
}
int SwapNextGuard()
{
if (g_aGuardQueue.Length == 0)
{
return -1;
}
int iPos = GetRandomInt(0, g_aGuardQueue.Length - 1);
int iClient = GetClientOfUserId(g_aGuardQueue.Get(iPos));
g_aGuardQueue.Erase(iPos);
if (iClient == 0)
{
LogError("[TB] Next guard is client 0!");
}
g_bJoinedWillingly[iClient] = true;
CS_SwitchTeam(iClient, CS_TEAM_CT);
return iClient;
}
Action JoinGuardAttempt(client)
{
Action result = Plugin_Continue;
// Let other plugins know this prisoner is trying to join guard
Call_StartForward(g_hJoinGuardAttempt);
Call_PushCell(client);
Call_Finish(result);
return result;
}
void SwapOnRoundEnd(int client, int iTeam)
{
SetEntProp(client, Prop_Send, "m_iPendingTeamNum", iTeam); // @TODO: Check if correct way to call this?
}
public void OnClientDisconnect(int client)
{
int iUserId = GetClientUserId(client);
int iPos;
if ((iPos = g_aGuardQueue.FindValue(iUserId)) != -1)
{
g_aGuardQueue.Erase(iPos);
}
if ((iPos = g_aCTList.FindValue(iUserId)) != -1)
{
g_aCTList.Erase(iPos);
}
}
public void OnStartLR(int iPrisonerIndex, int iGuardIndex, int iLRType)
{
g_bLastRequestStarted = true;
}
public Action Timer_SwitchTeam(Handle timer, any iUserId)
{
int client = GetClientOfUserId(iUserId);
if (client == 0 || GetClientTeam(client) != CS_TEAM_CT)
{
return Plugin_Stop;
}
CS_SwitchTeam(client, CS_TEAM_T);
if (IsPlayerAlive(client))
{
// If the player was alive already, move him back to his team's spawn
CS_RespawnPlayer(client);
}
return Plugin_Stop;
}
/************************ COMMANDS *************************/
void RegisterCommands()
{
RegConsoleCmd("sm_guard", Command_Guard);
RegConsoleCmd("sm_unguard", Command_Unguard);
RegConsoleCmd("sm_swapme", Command_SwapMe); // For some LR nubs that don't understand how to get back on CT off of their own server
//AddCommandListener(Command_JoinTeam, "autoteam"); // Doesn't seem to get fired on CS:GO
AddCommandListener(Command_JoinTeam, "jointeam");
}
public Action Command_Guard(int client, int args)
{
if (AddGuard(client) == Plugin_Continue)
{
// @TODO: clean up this logic! This gets fired when the player is allowed to join CT while skipping the queue
CS_SwitchTeam(client, CS_TEAM_CT);
/*int iCTCount = GetTeamClientCount(CS_TEAM_CT);
if (iCTCount == 0)
{*/
CS_TerminateRound(0.0, CSRoundEnd_GameStart);
//}
CS_RespawnPlayer(client);
}
return Plugin_Handled;
}
public Action Command_Unguard(int client, int args)
{
if (GetClientTeam(client) == CS_TEAM_CT)
{
SwapOnRoundEnd(client, CS_TEAM_T);
ReplyToCommand(client, "You will be switched to the other team on round end so you don't miss the current round.");
return Plugin_Handled;
}
RemoveFromGuardQueue(client);
return Plugin_Handled;
}
public Action Command_SwapMe(int client, int args)
{
if (GetClientTeam(client) != CS_TEAM_CT)
{
ReplyToCommand(client, "You don't need to be switched to the prisoner team");
return Plugin_Handled;
}
SwapOnRoundEnd(client, CS_TEAM_T);
ReplyToCommand(client, "You will be swapped to the prisoner team on round end");
return Plugin_Handled;
}
public Action Command_JoinTeam(int client, const char[] command, int args)
{
if (args < 1)
{
// Player didn't say what team they wanted to join, so let the normal jointeam information be returned
return Plugin_Continue;
}
// We can't do GetClientTeam of client -1 and we can't set their teamnum either, how do we solve this?
char sTeam[2];
GetCmdArg(1, sTeam, sizeof(sTeam));
int iTargetTeam = StringToInt(sTeam);
if (!IsValidClient(client))
{
if (iTargetTeam == CS_TEAM_CT || iTargetTeam == CS_TEAM_NONE)
{
// Let's hope in the Event_PlayerTeam they'll have a proper client ID already since then they shouldn't be able to join CT manually anyways, but notify admins to be sure
PrintToAdminChat("One of the players was possibly able to manually join CT when they shouldn't.");
}
return Plugin_Continue;
}
int iCurrentTeam = GetClientTeam(client);
if (iTargetTeam == CS_TEAM_NONE)
{
/*PrintToChatAll("Target team NONE, switching to T");
// Manually clicking autoteam (disconnect doesn't fire jointeam)
CS_SwitchTeam(client, CS_TEAM_T);
return Plugin_Handled;*/
return Plugin_Continue;
}
//g_iSelectedTeam[client] = iTargetTeam;
// Player isn't joining through autoteam
g_bNeedsInitialTeam[client] = false;
if (iCurrentTeam == iTargetTeam)
{
if (iTargetTeam == CS_TEAM_T)
{
RemoveFromGuardQueue(client);
}
SwapOnRoundEnd(client, iCurrentTeam);
// Let's not have suicides because of stupid people joining same team
return Plugin_Handled;
}
if (iCurrentTeam == CS_TEAM_CT && iTargetTeam == CS_TEAM_T && IsPlayerAlive(client))
{
PrintToChat(client, "You will be switched to the other team on round end so you don't miss the current round.");
SwapOnRoundEnd(client, CS_TEAM_T);
return Plugin_Handled;
}
if (iTargetTeam != CS_TEAM_CT || iCurrentTeam == iTargetTeam)
{
// @TODO: maybe if there's a CT already, check g_bNeedsInitialTeam and if that's set to true allow it?
// People are able to join any team except CT freely (or ct if they were already in it, blocking joining same team is stupid)
return Plugin_Continue;
}
return AddGuard(client);
}
/************************* EVENTS **************************/
void HookEvents()
{
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Post);
HookEvent("teamchange_pending", Event_TeamchangePending, EventHookMode_Pre);
HookEvent("jointeam_failed", Event_JoinTeamFailed, EventHookMode_Pre);
HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_Pre);
HookEvent("round_prestart", Event_RoundPreStart, EventHookMode_Post);
HookEvent("round_end", Event_RoundEnd, EventHookMode_Post);
}
public Action Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
{
int iUserId = event.GetInt("userid");
int iClient = GetClientOfUserId(iUserId);
int iTeam = event.GetInt("team");
int iOldTeam = event.GetInt("oldteam");
if (iTeam == CS_TEAM_CT)
{
if (g_bNeedsInitialTeam[iClient])
{
g_bNeedsInitialTeam[iClient] = false;
dontBroadcast = true;
//CS_SwitchTeam(iClient, CS_TEAM_T);
// would it be possible to event.SetInt("iTeam", CS_TEAM_T); here? Probably best to just change teams again
CreateTimer(0.0, Timer_SwitchTeam, iUserId);
//return Plugin_Changed;
return Plugin_Handled;
}
int iQueuePos = g_aGuardQueue.FindValue(iUserId);
if (iQueuePos != -1)
{
g_aGuardQueue.Erase(iQueuePos);
}
g_aCTList.Push(iUserId);
if (!g_bJoinedWillingly[iClient])
{
return Plugin_Continue;
}
}
else if (iOldTeam == CS_TEAM_CT)
{
int iCTCount = GetTeamClientCount(CS_TEAM_CT);
int iTCount = GetTeamClientCount(CS_TEAM_T);
if (iCTCount == 0 && iTCount > 0)
{
// Let the teambalancer do it's job
CS_TerminateRound(5.0, CSRoundEnd_CTSurrender);
}
int iCTPos = g_aCTList.FindValue(iUserId);
if (iCTPos != -1)
{
g_aCTList.Erase(iCTPos);
}
}
g_bJoinedWillingly[iClient] = true;
return Plugin_Continue;
}
public Action Event_TeamchangePending(Event event, const char[] name, bool dontBroadcast)
{
int iClient = GetClientOfUserId(event.GetInt("userid"));
int iPendingTeam = event.GetInt("toteam");
if (iPendingTeam == CS_TEAM_CT)
{
SetEntProp(iClient, Prop_Send, "m_iPendingTeamNum", CS_TEAM_T);
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action Event_JoinTeamFailed(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if(!client)
return Plugin_Continue;
int iReason = GetEventInt(event, "reason");
int iTPlayerCount = GetTeamClientCount(CS_TEAM_T);
int iCTPlayerCount = GetTeamClientCount(CS_TEAM_CT);
switch(iReason)
{
case k_OneTeamChange:
{
//return Plugin_Continue;
}
case k_TeamsFull:
{
if (iCTPlayerCount == g_iCTSpawnCount && iTPlayerCount == g_iTSpawnCount)
{
LogError("There are not enough spawnpoints for both teams on %s", g_sMap);
return Plugin_Continue;
}
}
case k_TTeamFull:
{
if (iTPlayerCount == g_iTSpawnCount)
{
LogError("There are not enough spawnpoints for the T team on %s", g_sMap);
return Plugin_Continue;
}
}
case k_CTTeamFull:
{
/*if (iCTPlayerCount == g_iCTSpawnCount)
{
LogeError("There are not enough spawnpoints for the CT team on %s", g_sMap);
return Plugin_Continue;
}*/
return Plugin_Continue;
}
case k_TooManyTerrorists:
{
}
default:
{
return Plugin_Continue;
}
}
CS_SwitchTeam(client, CS_TEAM_T);
return Plugin_Handled;
}
public Action Event_RoundPreStart(Event event, const char[] name, bool dontBroadcast)
{
g_bLastRequestStarted = false;
if(GameRules_GetProp("m_bWarmupPeriod") == 1)
{
return Plugin_Continue;
}
int iCTCount = GetTeamClientCount(CS_TEAM_CT);
int iTCount = GetTeamClientCount(CS_TEAM_T);
int iPlayerCount = iCTCount + iTCount;
//float flTargetRatio = FloatAdd(g_flTeamRatio, 1.0);
//float flCTTargetCount = FloatDiv(view_as<float>(iPlayerCount), flTargetRatio);
//int iCTTargetCount = RoundFloat(flCTTargetCount);
int iCTTargetCount = RoundToCeil(iPlayerCount / (g_flTeamRatio + 1));
if (iCTTargetCount == 0)
{
iCTTargetCount = 1;
}
int iNewCTs = iCTTargetCount - iCTCount;
if (iNewCTs > 0)
{
ArrayList g_aTList = null;
if (iNewCTs > g_aGuardQueue.Length)
{
// We will need more CT's than we have in the queue so prepare by getting all eligible T's
g_aTList = new ArrayList();
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && GetClientTeam(i) == CS_TEAM_T && !IsCTBanned(i))
{
g_aTList.Push(i);
}
}
}
// We need to move some people to CT, let's start with the guard queue
while (iNewCTs > 0)
{
int iGuard = SwapNextGuard();
if (iGuard != -1)
{
PrintToChat(iGuard, "You have been swapped to CT because there were not enough of them.");
}
else
{
if (g_aTList.Length == 0)
{
// We've got no more eligible Terrorists to go to CT, abort
break;
}
// Swap normal non-guard queue'ing player
int iTargetIndex = GetRandomInt(0, g_aTList.Length - 1);
iGuard = g_aTList.Get(iTargetIndex);
g_aTList.Erase(iTargetIndex);
g_bJoinedWillingly[iGuard] = false;
CS_SwitchTeam(iGuard, CS_TEAM_CT);
}
iNewCTs--;
}
}
else if (iNewCTs < 0)
{
while (iNewCTs < 0)
{
// @TODO: switch random CT?
int iTargetIndex = g_aCTList.Length - 1;
int iUserId = g_aCTList.Get(iTargetIndex);
g_aCTList.Erase(iTargetIndex);
int client = GetClientOfUserId(iUserId);
if (client == 0)
{
LogError("[TB] Something went wrong while teambalancing, we've got a client 0 in CT list");
continue;
}
// Should never be 0, but just to be sure
CS_SwitchTeam(client, CS_TEAM_T);
if (g_bJoinedWillingly[client])
{
// Add this client to the front of the queue
g_aGuardQueue.ShiftUp(0);
g_aGuardQueue.Set(0, iUserId);
PrintToChat(client, "Since you were one of the last to join CT and we have too many currently, you have been switched back to the prisoner team and re-added to the guard queue.");
}
else
{
PrintToChat(client, "Since you were one of the last to join CT and we have too many currently, you have been switched back to the prisoner team.");
}
iNewCTs++;
}
}
return Plugin_Continue;
}
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
if(GameRules_GetProp("m_bWarmupPeriod") == 1)
{
return Plugin_Continue;
}
// @TODO: Save round result and do calculations in RoundPreStart event so we have less duplicated code?
// @TODO: clean this up, it looks shitty as fuck
// Ratio change depends on how close / far we were from the target ratio
int iWinner = g_bLastRequestStarted ? CS_TEAM_CT : event.GetInt("winner");
int iCTCount = GetTeamClientCount(CS_TEAM_CT);
int iPlayerCount = GetTeamClientCount(CS_TEAM_T) + iCTCount;
int iCTTargetCount = RoundToCeil(iPlayerCount / (g_flTeamRatio + 1));
if (iCTTargetCount == 0)
{
iCTTargetCount = 1;
}
int iDifference = iCTCount - iCTTargetCount;
if (iDifference < 0)
{
iDifference = -iDifference;
}
float flRate = 1.0 - (iDifference / iCTTargetCount);
if (iWinner == CS_TEAM_T)
{
// We want less T's for every CT
//g_flTeamRatio -= iCTCount / iPlayerCount;
g_flTeamRatio -= flRate * g_cContractRate.FloatValue;
//g_flTeamRatio -= TEAM_CONTRACT_RATE;
}
else if (iWinner == CS_TEAM_CT)
{
// We want more T's for every CT
//g_flTeamRatio += iCTCount / IPlayerCount;
g_flTeamRatio += flRate * g_cExpandRate.FloatValue;
//g_flTeamRatio += TEAM_EXPAND_RATE;
}
if (g_flTeamRatio > g_cMaxRatio.FloatValue)
{
g_flTeamRatio = g_cMaxRatio.FloatValue;
}
else if (g_flTeamRatio < g_cMinRatio.FloatValue)
{
g_flTeamRatio = g_cMinRatio.FloatValue;
}
return Plugin_Continue;
}
public Action Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast)
{
// Easier way may be to Event.GetInt("index");
int iUserId = event.GetInt("userid");
int iClient = GetClientOfUserId(iUserId);
if (iClient != 0)
{
return Plugin_Continue;
}
int iCTCount = GetTeamClientCount(CS_TEAM_CT);
if (iCTCount > 1)
{
return Plugin_Continue;
}
SwapNextGuard();
return Plugin_Continue;
}