115 lines
2.0 KiB
SourcePawn
115 lines
2.0 KiB
SourcePawn
/* Plugin Template generated by Pawn Studio */
|
|
|
|
#include <sourcemod>
|
|
#include <sdktools_functions>
|
|
#include <tf2>
|
|
|
|
new Handle:cv_enabled, Handle:cv_unbalancelimit;
|
|
new bool:tmp_disabled = false;
|
|
|
|
public Plugin:myinfo =
|
|
{
|
|
name = "Automated Teambalancer",
|
|
author = "Chefe",
|
|
description = "Balances teams",
|
|
version = "1.0",
|
|
url = "www.chefgaming.de"
|
|
}
|
|
|
|
public OnPluginStart()
|
|
{
|
|
cv_enabled = CreateConVar("sm_atb_enabled", "1", "Enabled/Disable the ATB");
|
|
cv_unbalancelimit = CreateConVar("sm_atb_limit", "1", "The max difference beetween the teams");
|
|
HookEvent("player_team", Event_PlayerTeam);
|
|
}
|
|
|
|
public OnMapStart()
|
|
{
|
|
tmp_disabled = false;
|
|
}
|
|
|
|
public OnMapEnd()
|
|
{
|
|
tmp_disabled = true;
|
|
}
|
|
|
|
public Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
|
|
{
|
|
CheckTeams();
|
|
}
|
|
|
|
public OnClientDisconnect(client)
|
|
{
|
|
CheckTeams();
|
|
}
|
|
|
|
CheckTeams()
|
|
{
|
|
if (!tmp_disabled && GetConVarBool(cv_enabled))
|
|
{
|
|
new cred = GetTeamClientCount(2);
|
|
new cblu = GetTeamClientCount(3);
|
|
new dif = cred-cblu;
|
|
|
|
if (dif > GetConVarInt(cv_unbalancelimit))
|
|
{
|
|
DoClientMove(GetRandomPlayer(2), 3);
|
|
}
|
|
else if (dif < -GetConVarInt(cv_unbalancelimit))
|
|
{
|
|
DoClientMove(GetRandomPlayer(3), 2);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Action:TmpDis(Handle:timer, any:client)
|
|
{
|
|
tmp_disbaled = false;
|
|
CheckTeams();
|
|
}
|
|
|
|
public Action:TmpDelay(Handle:timer, any:client)
|
|
{
|
|
CheckTeams();
|
|
}
|
|
|
|
GetRandomPlayer(team)
|
|
{
|
|
new client;
|
|
new i = 0;
|
|
|
|
while (i < 1000)
|
|
{
|
|
client = GetRandomInt(1, GetClientCount(true));
|
|
|
|
if (IsClientInGame(client) && GetClientTeam(client) == team && !IsClientAdm(client) && !TF2_IsPlayerInDuel(client))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return client;
|
|
}
|
|
|
|
DoClientMove(client, team)
|
|
{
|
|
new String:teamname[50];
|
|
GetTeamName(team, teamname, sizeof(teamname));
|
|
|
|
tmp_disbaled = true;
|
|
ChangeClientTeam(client, team);
|
|
PrintToChatAll("\x04%N\x01 was moved to %s for teambalance", client, teamname);
|
|
}
|
|
|
|
IsClientAdm(client)
|
|
{
|
|
new AdminId:admid = GetUserAdmin(client);
|
|
if (admid != INVALID_ADMIN_ID)
|
|
{
|
|
return GetAdminFlag(admid, AdminFlag:Admin_Custom2);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
} |