PHP Code:
/* Formatright @ 2011, ConnorMcLeod
This plugin is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this plugin; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#define VERSION "0.0.1"
#define PLUGIN "Teams Limiter"
const m_iMenu = 205
const Menu_Team_Select = 1
new g_pCvarMax[CsTeams]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, "ConnorMcLeod")
g_pCvarMax[CS_TEAM_T] = register_cvar("amx_max_terrorists", "3")
g_pCvarMax[CS_TEAM_CT] = register_cvar("amx_max_cts", "0")
g_pCvarMax[CS_TEAM_SPECTATOR] = register_cvar("amx_max_spectators", "0")
register_clcmd("jointeam", "ClCmd_JoinTeam")
register_clcmd("menuselect", "ClCmd_MenuSelect")
}
public ClCmd_JoinTeam( id )
{
new szArg[3]
if( read_argv(1, szArg, charsmax(szArg)) != 1 )
{
return PLUGIN_CONTINUE
}
new iSlot = szArg[0] - '0'
if( iSlot == 3 ) // vip queue // exists with jointeam ????
{
return PLUGIN_CONTINUE
}
if( iSlot == 5 ) // auto-assign
{
new iCanJoin = CanJoinTeam(id, iSlot)
switch( iCanJoin )
{
case -1:
{
client_print(id, print_chat, "#Cstrike_TitlesTXT_All_Teams_Full")
return PLUGIN_HANDLED
}
case 5:
{
return PLUGIN_CONTINUE
}
case 6:
{
set_pev(id, pev_deadflag, DEAD_DEAD)
engclient_cmd(id, "jointeam", "6")
return PLUGIN_HANDLED
}
default:
{
szArg[0] = iCanJoin + '0'
engclient_cmd(id, "jointeam", szArg)
return PLUGIN_HANDLED
}
}
}
else if( !CanJoinTeam(id, iSlot) )
{
switch( iSlot )
{
case 1:client_print(id, print_chat, "#Cstrike_TitlesTXT_Terrorists_Full")
case 2:client_print(id, print_chat, "#Cstrike_TitlesTXT_CTs_Full")
//case 3:client_print(id, print_chat, "%L", id, "Spectators_Full")
case 3:client_print(id, print_chat, "The spectator team is full!")
}
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public ClCmd_MenuSelect(id)
{
if( get_pdata_int(id, m_iMenu) == Menu_Team_Select )
{
new szArg[3]
if( read_argv(1, szArg, charsmax(szArg)) != 1 )
{
return PLUGIN_CONTINUE
}
new iSlot = szArg[0] - '0'
if( iSlot == 3 ) // vip queue
{
return PLUGIN_CONTINUE
}
if( iSlot == 5 ) // auto-assign
{
new iCanJoin = CanJoinTeam(id, iSlot)
switch( iCanJoin )
{
case -1:
{
client_print(id, print_chat, "#Cstrike_TitlesTXT_All_Teams_Full")
client_cmd(id, "slot10")
return PLUGIN_HANDLED
}
case 5:
{
return PLUGIN_CONTINUE
}
case 6:
{
set_pev(id, pev_deadflag, DEAD_DEAD)
engclient_cmd(id, "menuselect", "6")
return PLUGIN_HANDLED
}
default:
{
szArg[0] = iCanJoin + '0'
engclient_cmd(id, "menuselect", szArg)
return PLUGIN_HANDLED
}
}
}
else if( !CanJoinTeam(id, iSlot) )
{
switch( iSlot )
{
case 1:client_print(id, print_chat, "#Cstrike_TitlesTXT_Terrorists_Full")
case 2:client_print(id, print_chat, "#Cstrike_TitlesTXT_CTs_Full")
//case 3:client_print(id, print_chat, "%L", id, "Spectators_Full")
case 3:client_print(id, print_chat, "The spectator team is full!")
}
return PLUGIN_HANDLED
}
}
return PLUGIN_CONTINUE
}
CanJoinTeam(id, iSlot)
{
new CsTeams:iTeam
switch( iSlot )
{
case 1,2:
{
iTeam = CsTeams:iSlot
}
case 5:
{
iTeam = CS_TEAM_UNASSIGNED
}
case 6:
{
iTeam = CS_TEAM_SPECTATOR
}
}
new iLimit[CsTeams]
if( iTeam )
{
if( !( iLimit[iTeam] = get_pcvar_num( g_pCvarMax[ iTeam ] ) ) )
{
return 3
}
}
for(new CsTeams:t=CS_TEAM_T; t<=CS_TEAM_SPECTATOR; t++)
{
if( iTeam && t==iTeam )
{
continue
}
if( !(iLimit[iTeam] = get_pcvar_num( g_pCvarMax[ iTeam ] )) )
{
iLimit[iTeam] = 32
}
}
new CsTeams:iPlayerTeam = cs_get_user_team(id)
if( iTeam == iPlayerTeam )
{
return 3
}
new iPlayers[32], iNum, iTeamCount[CsTeams], iPlayer
get_players(iPlayers, iNum, "h")
for(--iNum; iNum>=0; iNum++)
{
iPlayer = iPlayers[ iNum ]
if( iPlayer == id ) // either it's auto-assigned, either id is not in the wanted team, don't need to count, musn't count for auto-assigned
{
continue
}
iTeamCount[ cs_get_user_team(iPlayers[iNum]) ]++
}
if( iTeam == CS_TEAM_UNASSIGNED ) // auto assigned
{
new iTsSlotsLeft = iLimit[ CS_TEAM_T ] - iTeamCount[ CS_TEAM_T ]
new iCTsSlotsLeft = iLimit[ CS_TEAM_CT ] - iTeamCount[ CS_TEAM_CT ]
if( iTsSlotsLeft && iTsSlotsLeft >= iCTsSlotsLeft )
{
if( iTsSlotsLeft == iCTsSlotsLeft )
{
return 5
}
return 1
}
else if( iCTsSlotsLeft ) // && ( !iTsSlotsLeft || iTsSlotsLeft < iCTsSlotsLeft )
{
return 2
}
else if( iLimit[ CS_TEAM_SPECTATOR ] - iTeamCount[ CS_TEAM_SPECTATOR ] )
{
return 6
}
return -1 // wrong settings...
}
return iLimit[ iTeam ] - iTeamCount[ iTeam ] > 0
}