Code:
/* Copyright © 2009, SkubiDu
DeathRun Team- Ration 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 DeathRun Team Ratio; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <fakemeta>
#define PLUGIN "DeathRun Team-ration"
#define AUTHOR "SkubiDu"
#define VERSION "0.1.0"
#define MAX_PLAYERS 32
#define TEAM_T 1
#define TEAM_CT 2
#define CS_OFFSET_TEAM 114
#define cs_get_user_team(%1) get_pdata_int(%1, CS_OFFSET_TEAM)
#define cs_set_user_team_fast(%1,%2) set_pdata_int(%1, CS_OFFSET_TEAM, %2)
new g_iMaxPlayers
new g_pCvarRatio
new sv_restart
new g_bIsConnected[MAX_PLAYERS+1]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
g_pCvarRatio = register_cvar("dr_terrorists_ratio", "0.25")
g_iMaxPlayers = get_maxplayers()
sv_restart = get_cvar_pointer("sv_restart" "1")
}
public client_putinserver( id )
{
g_bIsConnected[id] = true
}
public client_disconnect( id )
{
g_bIsConnected[id] = false
}
public Event_HLTV_New_Round()
{
new iPlayers[MAX_PLAYERS], iNum, id, iTeam
for(id=1; id<=g_iMaxPlayers; id++)
{
if( g_bIsConnected[id] && ( TEAM_T <= cs_get_user_team(id) <= TEAM_CT ) )
{
iPlayers[iNum++] = id
}
}
if( iNum < 2 )
{
return
}
new iTerroristsNum = max(1, floatround( get_pcvar_float(g_pCvarRatio) * iNum , floatround_floor ))
new iRand
new szName[32]
while( iTerroristsNum )
{
iRand = random_num(0, iNum)
if( (id = iPlayers[iRand]) )
{
cs_set_user_team_fast(id, TEAM_T)
if( iNum-1 > iRand )
{
iPlayers[iRand] = iPlayers[iNum-1]
}
--iNum
--iTerroristsNum
get_user_name(id, szName, charsmax(szName))
client_print(0, print_chat, "[Dr] %s has be choosen to be a terrorist.", szName)
}
}
for(new i; i<iNum; i++)
{
if( (id = iPlayers[i]) )
{
cs_set_user_team_fast(id, TEAM_CT)
}
}
}