Player Slot Manager v0.0.4
Status: Working | Bug Testing
Description:
Allows you to specify an amount of allowed players for each team (excluding spectator or unassigned)
Cvars:
psm_ctslots <amount> - How many players allowed to be a CT
<default: 16>
psm_tslots <amount> - How many players allowed to be a T
<default: 16>
psm_version <version> - I suggest you not edit this, this is just so you know what version of the plugin you have.
History:
Version 0.0.4 (9/11/2010): Huge update to block team change if slots are maxed.
Version 0.0.3 (9/11/2010): Message on spawn fix (thanks
wrecked_)
Version 0.0.2 (9/11/2010): Removed Engine include
Version 0.0.1 (9/11/2010): Released
Trinkets:
HUD message displayed bottom left at all times
Special Thanks:
PHP Code:
/* Special Thanks */
// Exolent[jNr] - For the suggestion that I create a global variable to hold players team.
// Wrecked_ - For explaining shit/bug fix/retrieve arguments example
// Drekes - Team change event hook
// Fysiks - Suggesting I hook jointeam and retrieve arguments
Code:
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#define PLUGIN "Player Slots Manager"
#define AUTHOR "Shadow"
#define VERSION "0.0.4"
new maxslots_ct, maxslots_t;
new ctcount, tcount, ucount, scount;
new Team[33]
enum
{
UNASSIGNED,
CT,
T,
SPECTATOR
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
//hamsandwich
RegisterHam( Ham_Spawn, "player", "player_spawn", 1 )
//thanks to drekes for the event :)
register_event( "TeamInfo", "join_team", "a")
//thanks to fysik/wrecked for hook func and retrieving arguments
register_clcmd( "jointeam", "cmdJoinTeam" )
//cvars
register_cvar( "psm_version", VERSION )
maxslots_ct = register_cvar( "psm_ctslots", "16" )
maxslots_t = register_cvar( "psm_tslots", "16" )
set_task( 1.0, "show_hud", .flags="b" )
}
public client_putinserver(id)
{
Team[id] = UNASSIGNED
}
public client_disconnect(id)
{
switch( cs_get_user_team(id) )
{
case CS_TEAM_T:
{
tcount++
}
case CS_TEAM_CT:
{
ctcount++
}
case CS_TEAM_UNASSIGNED:
{
ucount++
}
case CS_TEAM_SPECTATOR:
{
scount++
}
}
}
public show_hud(id)
{
set_hudmessage(255, 255, 255, 0.01, 0.92, 0, 0.0, 2.0, 0.1, 0.2, -1);
show_hudmessage( 0, "CT: %d | T: %d | Spec: %d | Unassigned: %d", ctcount, tcount, scount, ucount );
}
public player_spawn(id)
{
new iPlayers[32], iNum, plr;
get_players( iPlayers, iNum )
ctcount = 0;
tcount = 0;
ucount = 0;
scount = 0;
for( new i = 0; i < iNum; i++ )
{
plr = iPlayers[i]
switch( cs_get_user_team(plr) )
{
case CS_TEAM_T:
{
tcount++
}
case CS_TEAM_CT:
{
ctcount++
}
case CS_TEAM_UNASSIGNED:
{
ucount++
}
case CS_TEAM_SPECTATOR:
{
scount++
}
}
}
return PLUGIN_HANDLED;
}
public cmdJoinTeam( id )
{
new teamstr[2]
read_argv( 1, teamstr, 1 )
new teamnum = str_to_num( teamstr )
if( teamnum == 1 )
{
if( tcount > get_pcvar_num( maxslots_t ) )
{
client_print( id, print_chat, "[Slots] The maximum players allowed on T is %d, sorry!", get_pcvar_num( maxslots_ct ) )
return PLUGIN_HANDLED;
} else {
switch( Team[id] )
{
case UNASSIGNED:
{
ucount--
}
case T:
{
tcount--
}
case CT:
{
ctcount--
}
case SPECTATOR:
{
scount--
}
}
new szName[32];
get_user_name( id, szName, 32 )
tcount++
new slotsleft = get_pcvar_num( maxslots_t ) - tcount
if( Team[id] != T )
{
client_print( 0, print_chat, "[Slots] %s joined the Terrorists! Slots left: %d", szName, slotsleft )
}
Team[id] = T
return PLUGIN_CONTINUE;
}
}
if( teamnum == 2 )
{
if( ctcount > get_pcvar_num( maxslots_ct ) )
{
client_print( id, print_chat, "[Slots] The maximum players allowed on CT is %d, sorry!", get_pcvar_num( maxslots_ct ) )
return PLUGIN_HANDLED;
} else {
switch( Team[id] )
{
case UNASSIGNED:
{
ucount--
}
case T:
{
tcount--
}
case CT:
{
ctcount--
}
case SPECTATOR:
{
scount--
}
}
new szName[32];
get_user_name( id, szName, 32 )
ctcount++
new slotsleft = get_pcvar_num( maxslots_ct ) - ctcount
if( Team[id] != CT )
{
client_print( 0, print_chat, "[Slots] %s joined the Counter-Terrorists! Slots left: %d", szName, slotsleft )
}
Team[id] = CT
return PLUGIN_CONTINUE;
}
}
return PLUGIN_CONTINUE;
}
public join_team()
{
new id = read_data(1)
static user_team[32]
read_data( 2, user_team, 31 )
if( !is_user_connected(id) )
{
return PLUGIN_CONTINUE
}
switch( user_team[0] )
{
case 'C':
{
if( ctcount > get_pcvar_num( maxslots_ct ) )
{
client_print( id, print_chat, "[Slots] The maximum players allowed on CT is %d, sorry!", get_pcvar_num( maxslots_ct ) )
return PLUGIN_HANDLED;
} else {
switch( Team[id] )
{
case UNASSIGNED:
{
ucount--
}
case T:
{
tcount--
}
case CT:
{
ctcount--
}
case SPECTATOR:
{
scount--
}
}
new szName[32];
get_user_name( id, szName, 32 )
ctcount++
new slotsleft = get_pcvar_num( maxslots_ct ) - ctcount
if( Team[id] != CT )
{
client_print( 0, print_chat, "[Slots] %s joined the Counter-Terrorists! Slots left: %d", szName, slotsleft )
}
Team[id] = CT
}
}
case 'S':
{
switch( Team[id] )
{
case UNASSIGNED:
{
ucount--
}
case T:
{
tcount--
}
case CT:
{
ctcount--
}
case SPECTATOR:
{
scount--
}
}
new szName[32];
get_user_name( id, szName, 32 )
scount++
Team[id] = SPECTATOR;
client_print( 0, print_chat, "[Slots] %s is now spectating the game!", szName )
}
}
return PLUGIN_HANDLED;
}
Bug Fixed! Below:
Displays this message not only when the player joins a team, but every time they spawn:
If you have any suggestions, please post them!