maxplayers
CVAR (Console VARiable) which is always "1" on singleplayer games/mods and likely a higher number for multiplayer ones.soundent
which is used to store "sound cues" (combat, danger...) for the AI. In Source, an example would be the "gamerules proxy entity" mostly used by multiplayer games/mods to transfer some information between the server and clients.maxplayers
) because they are reserved, be careful when using them for other entities. Examples on GoldSrc: various environment effects/entities like beams refer to the starting/ending entities through entity indexes which might be fine. But when it comes to "ownership" like tracking who fired this rocket, threw this grenade and similar stuff, it would be more prudent to use EHANDLE
(GoldSrc) and CHandle
(Source) instead as they are designed for these kinds of purposes. Class pointers might be an alternative depending on the context. When in doubt, try to seek directions from existing code.Use
(GoldSrc) / inputs and outputs (Source), try to query the "activator" first and eventually "caller" if you need it instead. Using the "owner" system (pev->owner
for GoldSrc, dedicated "owner" methods for Source) might also be an alternative depending on the context.struct cl_entity_s* gEngfuncs.GetEntityByIndex(int idx);
which returns the entity (or NULL
) that uses the index in parameter. Do note that you can just use cl_entity_t*
instead of struct cl_entity_s*
.// From "dlls/util.h"
inline int ENTINDEX(edict_t* pEdict) { return (*g_engfuncs.pfnIndexOfEdict)(pEdict); }
inline edict_t* INDEXENT(int iEdictNum) { return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum); }
The first function returns the entity index of the entity's edict_t*
you're passing as parameter. The second function is the opposite way (retrieve the edict_t*
from a specific entity index).pfnPEntityOfEntIndex
for a moment because there is a similar but different version called pfnPEntityOfEntIndexAllEntities
. Both functions returns the edict_t*
of the entity that has the entity index iEntIndex
(or NULL
if there is no entity at the desired entity index). The difference between these two functions is that the first one (pfnPEntityOfEntIndex
) has a "bug" where the engine has a bogus "client check" and the last player in a multiplayer game/mod cannot be retrieved (the result is always NULL
).pfnPEntityOfEntIndexAllEntities
) is a duplicate of the first one but with the "fix" applied. This way, games/mods that relied on the "bug" works without requiring an update and new mods can use the "fixed" variant.// Client
C_BaseEntity* ClientEntityList().GetBaseEntity(int);
// Server
edict_t* INDEXENT(int iEdictNum);
int ENTINDEX(edict_t* pEdict);
CEntInfo* gEntList.GetEntInfoPtrByIndex(int);
// These two below are not available on Source 2010 (aka "Alien Swarm" branch)
int engine->IndexOfEdict(edict_t*);
edict_t* engine->PEntityOfEntIndex(int); // Only works for networked entities
// Shared
int CBaseEntity::entindex();
You must log in to post a comment. You can login or register a new account.