UTIL PlayerByIndex: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(spelling)
m (Formatting/Cleanup)
Line 2: Line 2:
This function will return a CBasePlayer pointer to an [[entity]] based on the networked entity index which is passed in as a first parameter. The [[edict]] indices in the range 1 to gpGlobals->maxClients are reserved for players; all networked, non-player entities will be assigned to an index higher than gpGlobals->maxClients.
This function will return a CBasePlayer pointer to an [[entity]] based on the networked entity index which is passed in as a first parameter. The [[edict]] indices in the range 1 to gpGlobals->maxClients are reserved for players; all networked, non-player entities will be assigned to an index higher than gpGlobals->maxClients.


== Shared declaration: ==
== Usage ==
<source lang=cpp>
<source lang=cpp>
CBasePlayer *UTIL_PlayerByIndex( int entindex );
CBasePlayer *UTIL_PlayerByIndex( int entindex );
</source>
</source>


== Example usage: ==
== Examples ==
The following code can be used to safely iterate all player entities:
The following code can be used to safely iterate all player entities:
<source lang=cpp>
<source lang=cpp>

Revision as of 22:12, 10 April 2011

Template:Wrongtitle This function will return a CBasePlayer pointer to an entity based on the networked entity index which is passed in as a first parameter. The edict indices in the range 1 to gpGlobals->maxClients are reserved for players; all networked, non-player entities will be assigned to an index higher than gpGlobals->maxClients.

Usage

CBasePlayer *UTIL_PlayerByIndex( int entindex );

Examples

The following code can be used to safely iterate all player entities:

for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
	CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
	if (!pPlayer || !pPlayer->IsPlayer())
		continue;
	[...]
}