UTIL PlayerByIndex: Difference between revisions
Jump to navigation
Jump to search
Biohazard 90 (talk | contribs) No edit summary |
Biohazard 90 (talk | contribs) m (title) |
||
Line 1: | Line 1: | ||
{{wrongtitle|UTIL_PlayerByIndex}} | |||
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. | ||
Revision as of 17:47, 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.
CBasePlayer *UTIL_PlayerByIndex( int entindex );
Example usage:
The following code can be used to savely iterate all player entities:
for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || !pPlayer->IsPlayer())
continue;
[...]
}