View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-21-2023 , 18:24   Re: Pick A Random Player Bug on Start
Reply With Quote #6

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_CTid )
{
    new 
iPlayersMAX_PLAYERS ] , iPlayingPlayersMAX_PLAYERS ][ PlayerData ] , iNum;
    new 
iRandomIndex iPlayer iRandom CsTeams:cstTeam iPlayingPlayersCount;
    
    
//Get all players in the iPlayers array.
    
get_playersiPlayers iNum );
    
    
//Loop through players and load iPlayingPlayers array with those who are on a team
    
for ( new iNum i++ )
    {
        
iPlayer iPlayers];
        
        
//If player is on a team, add to iPlayingPlayers array and increment iPlayingPlayersCount counter
        
if ( CS_TEAM_T <= ( cstTeam cs_get_user_teamiPlayer ) ) <= CS_TEAM_CT )
        {
            
iPlayingPlayersiPlayingPlayersCount ][ SlotID ] = iPlayer;
            
iPlayingPlayersiPlayingPlayersCount ][ CSTeam ] = cstTeam;
            
iPlayingPlayersCount++;
        }
    }
    
    
//We need at least 2 players
    
if ( iPlayingPlayersCount )
    {
        
//Select a random player who will be the solo T
        
iRandomIndex randomiPlayingPlayersCount );
        
iRandom iPlayingPlayersiRandomIndex ][ SlotID ];
        
        
//Move randomly selected solo T to T only if not already a T
        
if ( iPlayingPlayersiRandomIndex ][ CSTeam ] != CS_TEAM_T )
            
cs_set_user_teamiRandom CS_TEAM_T );
        
        
//Loop through remaining players and send them to CT, or do nothing if already CT
        
for ( new iNum i++ )
        {
            
iPlayer iPlayingPlayers][ 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][ CSTeam ] != CS_TEAM_CT )
                    
cs_set_user_teamiPlayer CS_TEAM_CT );
            }
        }
    }
    else
    {
        
client_printid print_chat "* There is not enough players to set solo T vs all CT." );
    }
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 12-21-2023 at 19:47.
Bugsy is offline