#include <amxmodx>
#include <reapi>
#define ACCESS_IMMUNITY ADMIN_IMMUNITY // Иммунитет для админов при балансе
#define DIFF_PLAYERS 2 // разница в количестве игроков в командах
#define IGNORE_CHECKS 10 // сколько раз пропускать игрока при балансе (маленькое значение не ставьте. игроки ваш сервер нах..й пошлют =)))
#define REPLACED_MENU // Кастомное меню с 2-мя пунктами.
#if !defined MAX_PLAYERS
#define MAX_PLAYERS 32
#endif
#if AMXX_VERSION_NUM < 183
new MaxClients;
#endif
enum _:Teams { TT = 1, CT }
new g_iNewTeam[MAX_PLAYERS+1];
new g_iIgnoreChecks[MAX_PLAYERS+1];
#define msgSayText 76
#define msgTeamInfo 86
#define msgShowOldMenu 96
#define msgShowVGUIMenu 114
public plugin_init()
{
register_plugin("NoRound Balancer", "1.3", "neygomon");
RegisterHookChain(RG_CBasePlayer_Spawn, "fwdPlayerSpawnPre", true);
RegisterHookChain(RG_CBasePlayer_Killed, "fwdPlayerKilledPost", true);
#if defined REPLACED_MENU
register_clcmd("chooseteam", "ShowMenu");
register_menucmd(register_menuid("Team Menu"), MENU_KEY_0|MENU_KEY_1|MENU_KEY_6, "TeamMenuHandler");
register_message(msgShowOldMenu, "mShowMenu");
register_message(msgShowVGUIMenu, "mShowMenu");
#endif
#if AMXX_VERSION_NUM < 183
MaxClients = get_maxplayers();
#endif
}
public client_putinserver(id)
g_iNewTeam[id] = g_iIgnoreChecks[id] = 0;
public fwdPlayerSpawnPre(const ClientIndex)
{
if(g_iNewTeam[ClientIndex]-- && ~get_user_flags(ClientIndex) & ACCESS_IMMUNITY)
{
//rg_set_user_team(ClientIndex, g_iNewTeam[ClientIndex]);
client_printc(ClientIndex, "^1[^4Баланс^1] ^4Вы перемещены в команду ^3%s", g_iNewTeam[ClientIndex] == TT ? "террористов" : "контр-террористов");
g_iNewTeam[ClientIndex] = 0;
}
}
public fwdPlayerKilledPost(const VictimIndex)
{
if(!(1 <= VictimIndex <= MaxClients))
return;
static iCachedTime, iCurrentTime;
static iPlayersNum[Teams];
if((iCurrentTime = get_systime()) >= iCachedTime)
{
GetPlayersTeam(iPlayersNum[TT], iPlayersNum[CT]);
iCachedTime = iCurrentTime + 2;
}
if(abs(iPlayersNum[TT] - iPlayersNum[CT]) >= DIFF_PLAYERS)
{
if(iPlayersNum[TT] > iPlayersNum[CT])
{
if(get_member(VictimIndex, m_iTeam) == TT && !g_iIgnoreChecks[VictimIndex]--)
{
g_iNewTeam[VictimIndex] = CT;
g_iIgnoreChecks[VictimIndex] = IGNORE_CHECKS;
rg_set_user_team(VictimIndex, g_iNewTeam[VictimIndex]);
}
}
else if(iPlayersNum[CT] > iPlayersNum[TT])
{
if(get_member(VictimIndex, m_iTeam) == CT && !g_iIgnoreChecks[VictimIndex]--)
{
g_iNewTeam[VictimIndex] = TT;
g_iIgnoreChecks[VictimIndex] = IGNORE_CHECKS;
rg_set_user_team(VictimIndex, g_iNewTeam[VictimIndex]);
}
}
}
}
#if defined REPLACED_MENU
public mShowMenu(msgId, msgDest, msgEnt)
{
if(msgId == msgShowOldMenu)
{
static szArg4[20]; get_msg_arg_string(4, szArg4, charsmax(szArg4));
if(contain(szArg4, "Team_Select") == -1)
return PLUGIN_CONTINUE;
}
else if(get_msg_arg_int(1) != 2)
return PLUGIN_CONTINUE;
set_member(msgEnt, m_iMenu, Menu_OFF);
ShowMenu(msgEnt);
return PLUGIN_HANDLED;
}
public ShowMenu(id)
return show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_6, "\d[\rCSDM\d] \yВыберите действие:^n^n\y1. \rВойти в игру^n\y6. \wНаблюдение^n^n\y0. \wВыход", -1, "Team Menu");
public TeamMenuHandler(id, iKey)
{
switch(iKey)
{
case 0:
{
static tt, ct; GetPlayersTeam(tt, ct);
set_member(id, m_bTeamChanged, false);
engclient_cmd(id, "jointeam", (tt > ct) ? "2" : "1");
}
case 5: user_silentkill(id), engclient_cmd(id, "jointeam", "6");
}
return PLUGIN_HANDLED;
}
#endif
stock GetPlayersTeam(&tt, &ct, players[32]="", pnum=0)
{
tt = ct = 0;
get_players(players, pnum);
for(new i; i < pnum; i++)
{
switch(get_member(players[i], m_iTeam))
{
case 1: tt++;
case 2: ct++;
}
}
}
stock client_printc(const ClientIndex, const szMessage[], any:...)
{
static szMsg[190]; vformat(szMsg, charsmax(szMsg), szMessage, 3);
message_begin(MSG_ONE_UNRELIABLE, msgSayText, .player = ClientIndex);
write_byte(ClientIndex);
write_string(szMsg);
message_end();
}