PHP Code:
#include <amxmodx>
#include <cstrike>
new const Version[] = "0.1";
enum PlayerData
{
SlotID,
CsTeams:CSTeam
}
public plugin_init()
{
register_plugin( "Solo T vs CT" , Version , "bugsy" );
register_clcmd( "say setteams" , "Set_Solo_T_vs_CT" );
}
public Set_Solo_T_vs_CT( id )
{
new iPlayers[ MAX_PLAYERS ] , iPlayingPlayers[ MAX_PLAYERS ][ PlayerData ] , iNum;
new iRandomIndex , iPlayer , iRandom , CsTeams:cstTeam , iPlayingPlayersCount;
//Get all players in the iPlayers array.
get_players( iPlayers , iNum );
//Loop through players and load iPlayingPlayers array with those who are on a team
for ( new i = 0 ; i < iNum ; i++ )
{
iPlayer = iPlayers[ i ];
//If player is on a team, add to iPlayingPlayers array and increment iPlayingPlayersCount counter
if ( CS_TEAM_T <= ( cstTeam = cs_get_user_team( iPlayer ) ) <= CS_TEAM_CT )
{
iPlayingPlayers[ iPlayingPlayersCount ][ SlotID ] = iPlayer;
iPlayingPlayers[ iPlayingPlayersCount ][ CSTeam ] = cstTeam;
iPlayingPlayersCount++;
}
}
//We need at least 2 players
if ( iPlayingPlayersCount > 1 )
{
//Select a random player who will be the solo T
iRandomIndex = random( iPlayingPlayersCount );
iRandom = iPlayingPlayers[ iRandomIndex ][ SlotID ];
//Move randomly selected solo T to T only if not already a T
if ( iPlayingPlayers[ iRandomIndex ][ CSTeam ] != CS_TEAM_T )
cs_set_user_team( iRandom , CS_TEAM_T );
//Loop through remaining players and send them to CT, or do nothing if already CT
for ( new i = 0 ; i < iNum ; i++ )
{
iPlayer = iPlayingPlayers[ i ][ SlotID ];
//Only move the player to CT if its not therandom player
if ( iPlayer != iRandom )
{
//Only move to CT if not already a CT
if ( iPlayingPlayers[ i ][ CSTeam ] != CS_TEAM_CT )
cs_set_user_team( iPlayer , CS_TEAM_CT );
}
}
}
else
{
client_print( id , print_chat , "* There is not enough players to set solo T vs all CT." );
}
return PLUGIN_HANDLED;
}
__________________