This is the code I rewrite from warmod to limit 12 players. Please look at this @@.
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <tf2>
#define TEAM_SPEC 1
#define TEAM_RED 2
#define TEAM_BLUE 3
new Handle:g_h_max_players;
public Plugin:myinfo =
{
name = "TF2 Limit 12 Players",
author = "duydangle, noobcannonlol",
description = "For use on competitive server",
version = "1.0",
url = "Xtremezone.VN"
}
public OnPluginStart()
{
g_h_max_players = CreateConVar("sm_maxplayers", "12", "Limit max players to this value");
RegConsoleCmd("jointeam", ChooseTeam);
RegConsoleCmd("spectate", ChooseTeam);
}
public Action:ChooseTeam(client, args)
{
if (client == 0)
{
return Plugin_Continue;
}
new max_players = GetConVarInt(g_h_max_players);
if (max_players != 0 && GetClientTeam(client) <= 1 && CS_GetPlayingCount() >= max_players)
{
PrintToChat(client, "%s players already!", max_players);
ChangeClientTeam(client, TEAM_SPEC);
return Plugin_Stop;
}
return Plugin_Continue;
}
stock CS_GetPlayingCount()
{
new count;
new max_clients = GetMaxClients();
for (new i = 1; i <= max_clients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1)
{
count++;
}
}
return count;
}