// Copyright © 2016 Vaqtincha
/**
* Credits:
*
* - Adidasman - за подсказку
* - wopox1337 - за поддержку топика
*
* CVars:
* atc_team_fast_switch = 1 = wihout kill & select class, 2 - +respawn after switch
* atc_use_limit_type = 0 - no limit, 1 - round limit, 2 - time limit
* atc_limit_seconds = use with atc_use_limit_type == 2
*
*/
///■■■■■■■■■■■■■■■■■■■■■■■ CONFIG START ■■■■■■■■■■■■■■■■■■■■■■■//
// #define SHOW_TEAM_COUNT
// #define UNLIMITE_SWITCH_FLAG ADMIN_KICK
// #define FIX_SPEC_SPAWN // fix spectator spawn
///■■■■■■■■■■■■■■■■■■■■■■■■ CONFIG END ■■■■■■■■■■■■■■■■■■■■■■■■//
#define PL_VERSION "0.1.0"
#include <amxmodx>
#include <reapi>
#define IsPlayerJoined(%1) (get_member(%1, m_iJoiningState) == JOINED)
const MENU_KEY_BITS = (MENU_KEY_1|MENU_KEY_2|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_0)
const MENU_KEY_EXIT = 10
const MAX_MENU_TEXT_LEN = 512
new bool:g_bIsPlayerSpec[MAX_CLIENTS+1], bool:g_bIsPlayerBot[MAX_CLIENTS+1], g_iLastChangedTime[MAX_CLIENTS+1]
new g_pCVarLimitType, g_pCVarLimitSeconds, g_pCVarFastSwitch
new const g_szMenuName[] = "TeamMenu"
public plugin_init()
{
register_plugin("[ReAPI] Advanced Team Chooser", PL_VERSION, "Vaqtincha")
register_clcmd("chooseteam", "ClCmd_chooseteam")
register_clcmd("jointeam", "ClCmd_chooseteam")
register_menucmd(register_menuid(g_szMenuName), MENU_KEY_BITS, "TeamMenuHandler")
g_pCVarFastSwitch = register_cvar("atc_team_fast_switch", "0")
g_pCVarLimitType = register_cvar("atc_use_limit_type", "0")
g_pCVarLimitSeconds = register_cvar("atc_limit_seconds", "10")
RegisterHookChain(RG_ShowVGUIMenu, "ShowVGUIMenu", .post = false)
#if defined FIX_SPEC_SPAWN
RegisterHookChain(RG_HandleMenu_ChooseAppearance, "HandleMenu_ChooseAppearance", .post = true)
#endif
}
public client_putinserver(pPlayer)
{
g_iLastChangedTime[pPlayer] = 0
g_bIsPlayerSpec[pPlayer] = false
g_bIsPlayerBot[pPlayer] = bool:is_user_bot(pPlayer)
}
public ClCmd_chooseteam(pPlayer)
{
if(!is_user_connected(pPlayer))
return PLUGIN_CONTINUE
g_bIsPlayerSpec[pPlayer] = bool:(get_member(pPlayer, m_iTeam) == TEAM_SPECTATOR)
#if defined UNLIMITE_SWITCH_FLAG
if(get_user_flags(pPlayer) & UNLIMITE_SWITCH_FLAG)
{
g_iLastChangedTime[pPlayer] = 0
set_member(pPlayer, m_bTeamChanged, false)
return PLUGIN_CONTINUE
}
#endif
switch(get_pcvar_num(g_pCVarLimitType))
{
case 0: set_member(pPlayer, m_bTeamChanged, false)
case 1: set_member(pPlayer, m_bTeamChanged, true)
case 2: {
new iSysTime = get_systime()
if(g_iLastChangedTime[pPlayer] > iSysTime)
{
client_print(pPlayer, print_center, "* Это команда доступно после %d секунд! *", (g_iLastChangedTime[pPlayer] - iSysTime))
return PLUGIN_HANDLED
}
g_iLastChangedTime[pPlayer] = get_systime() + get_pcvar_num(g_pCVarLimitSeconds)
set_member(pPlayer, m_bTeamChanged, false)
}
}
return PLUGIN_CONTINUE
}
public ShowVGUIMenu(const pPlayer, VGUIMenu:menuType, bitsSlots, const szOldMenu[], bool:bForceOldMenu)
{
if(menuType == VGUI_Menu_Team && !g_bIsPlayerBot[pPlayer] /* potbot/yapb fix join team*/)
{
ShowTeamMenu(pPlayer)
return HC_SUPERCEDE
}
return HC_CONTINUE
}
#if defined FIX_SPEC_SPAWN
public HandleMenu_ChooseAppearance(const pPlayer, const slot)
{
if(g_bIsPlayerSpec[pPlayer] && is_user_connected(pPlayer) && !is_user_alive(pPlayer))
{
rg_round_respawn(pPlayer)
}
}
#endif
ShowTeamMenu(const pPlayer)
{
if(!is_user_connected(pPlayer))
return PLUGIN_HANDLED
new szMenu[MAX_MENU_TEXT_LEN], iKeys
new iLen = formatex(szMenu, charsmax(szMenu), "\yВыбор команды:^n^n")
#if defined SHOW_TEAM_COUNT
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y1\w. Террористы \r[\y%d\r]^n", get_member_game(m_iNumTerrorist))
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y2\w. Контр-террористы \r[\y%d\r]^n^n", get_member_game(m_iNumCT))
#else
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y1\w. Террористы^n")
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y2\w. Контр-террористы^n^n")
#endif
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y5\w. Случайный выбор^n")
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y6\w. Наблюдение^n^n")
if(IsPlayerJoined(pPlayer))
{
if(!g_bIsPlayerSpec[pPlayer])
{
iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y7\w. Переключиться^n^n^n")
iKeys |= MENU_KEY_7
}
formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y0\w. \rВыход")
iKeys |= MENU_KEY_0
}
iKeys |= (MENU_KEY_1|MENU_KEY_2|MENU_KEY_5|MENU_KEY_6)
return show_menu(pPlayer, iKeys, szMenu, -1, g_szMenuName)
}
public TeamMenuHandler(const pPlayer, iKey)
{
iKey += 1
if(iKey == MENU_KEY_EXIT || !is_user_connected(pPlayer))
return PLUGIN_HANDLED
switch(iKey)
{
case 1: JoinTeam(pPlayer, "1")
case 2: JoinTeam(pPlayer, "2")
case 5: JoinTeam(pPlayer, "5")
case 6: {
user_kill(pPlayer, 1)
engclient_cmd(pPlayer, "jointeam", "6")
}
case 7: {
new iCVarFastSwitch = get_pcvar_num(g_pCVarFastSwitch)
if(iCVarFastSwitch >= 1)
{
rg_switch_team(pPlayer)
if(iCVarFastSwitch == 2)
rg_round_respawn(pPlayer)
}
else
rg_join_team(pPlayer, get_member(pPlayer, m_iTeam) == TEAM_CT ? TEAM_TERRORIST : TEAM_CT)
}
}
return PLUGIN_HANDLED
}
JoinTeam(const pPlayer, szString[2])
{
new iCVarFastSwitch = get_pcvar_num(g_pCVarFastSwitch)
if(iCVarFastSwitch >= 1 && IsPlayerJoined(pPlayer) && !g_bIsPlayerSpec[pPlayer])
{
rg_set_user_team(pPlayer, szString[0] == '5' ? random_num(1, 2) : str_to_num(szString))
if(iCVarFastSwitch == 2)
rg_round_respawn(pPlayer)
return
}
engclient_cmd(pPlayer, "jointeam", szString)
}