This repository has been archived by the owner on Jan 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast teambalance.sp
82 lines (72 loc) · 2.34 KB
/
fast teambalance.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
#pragma semicolon 1
#define PLUGIN_AUTHOR "[W]atch [D]ogs" // Respect ;)
#define PLUGIN_VERSION "1.0.6"
#include <sourcemod>
#include <cstrike>
#include <sdktools_functions>
#include <smlib>
#pragma newdecls required
Handle h_bEnable;
public Plugin myinfo =
{
name = "Fast Team Balancer",
author = PLUGIN_AUTHOR,
description = "Balances teams at start of every rounds",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=298717"
};
public void OnPluginStart()
{
h_bEnable = CreateConVar("sm_ftb_enable", "1", "Enable / Disable fast team balancing", _, true, 0.0, true, 1.0);
if(GetEngineVersion() == Engine_CSGO)
HookEvent("round_prestart", Event_PreRoundStart);
else
HookEvent("round_end", Event_PreRoundStart);
}
public Action Event_PreRoundStart(Handle event, const char[] name, bool dontBroadcast)
{
int T_Count = GetTeamClientCount(CS_TEAM_T);
int CT_Count = GetTeamClientCount(CS_TEAM_CT);
if(!GetConVarBool(h_bEnable) || T_Count == CT_Count || T_Count + 1 == CT_Count || CT_Count + 1 == T_Count)
return Plugin_Continue;
while(T_Count > CT_Count && T_Count != CT_Count + 1)
{
int client = GetRandomPlayer(CS_TEAM_T);
int oldmoney = Client_GetMoney(client);
CS_SwitchTeam(client, CS_TEAM_CT);
int newmoney = Client_GetMoney(client);
T_Count--;
CT_Count++;
if(newmoney != oldmoney)
{
Client_SetMoney(client, oldmoney);
}
}
while(T_Count < CT_Count && CT_Count != T_Count + 1)
{
int client = GetRandomPlayer(CS_TEAM_CT);
int oldmoney = Client_GetMoney(client);
CS_SwitchTeam(client, CS_TEAM_T);
int newmoney = Client_GetMoney(client);
CT_Count--;
T_Count++;
if(newmoney != oldmoney)
{
Client_SetMoney(client, oldmoney);
}
}
return Plugin_Continue;
}
stock int GetRandomPlayer(int team)
{
int[] clients = new int[MaxClients];
int clientCount;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && GetClientTeam(i) == team)
{
clients[clientCount++] = i;
}
}
return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount - 1)];
}