Command Callback Helpers

From Valve Developer Community
Jump to navigation Jump to search
CBasePlayer *UTIL_PlayerByIndex( int playerIndex )
This is a function that returns a CBasePlayer pointer to a player by index. It only returns if the player is spawned and connected, otherwise it returns NULL.
CBasePlayer* UTIL_PlayerByName( const char *name )
This is a function that returns a CBasePlayer pointer to a player by name. It only returns if the player is spawned and connected, otherwise it returns NULL.
CBasePlayer* UTIL_PlayerByUserId( int userID )
This is a function that returns a CBasePlayer pointer to a player by user ID. It only returns if the player is spawned and connected, otherwise it returns NULL.
bool UTIL_IsCommandIssuedByServerAdmin( void )
This is a function that takes no parameters and returns true if the current command is issued by an admin. This function returns true when a command is issued by a dedicated server console or a listen server host.
int UTIL_GetCommandClientIndex( void )
This is a function that returns the client index of the current command. This function returns 0 when the command is issued by a dedicated server console; Otherwise, it returns an integer [1, maxplayers] for the player.
CBasePlayer *UTIL_GetCommandClient( void )
This is a function that retrieves the client index and gets the player by the returned index for you. It returns a CBasePlayer pointer; the returned value is null if the command is issued by a dedicated server console.