//----------------------------------------------------------------------------- // Returns a BaseEntity instance from the given index. //----------------------------------------------------------------------------- bool BaseEntityFromIndex( unsigned int iEntityIndex, CBaseEntity*& output ) { edict_t* pEdict; if (!EdictFromIndex(iEntityIndex, pEdict)) return false; return BaseEntityFromEdict(pEdict, output); }
//----------------------------------------------------------------------------- // Returns an Edict instance from the given IntHandle. //----------------------------------------------------------------------------- bool EdictFromIntHandle( unsigned int iEntityHandle, edict_t*& output ) { unsigned int iIndex; if (!IndexFromIntHandle(iEntityHandle, iIndex)) return false; return EdictFromIndex(iIndex, output); }
//----------------------------------------------------------------------------- // Returns an Edict instance from the given BaseHandle instance. //----------------------------------------------------------------------------- bool EdictFromBaseHandle( CBaseHandle hBaseHandle, edict_t*& output ) { unsigned int iIndex; if (!IndexFromBaseHandle(hBaseHandle, iIndex)) return false; return EdictFromIndex(iIndex, output); }
void CSourcePython::OnEntityCreated( CBaseEntity *pEntity ) { int iIndex = IndexFromBaseEntity(pEntity); edict_t *pEdict = EdictFromIndex(iIndex); if (pEdict) { IServerUnknown* pServerUnknown = pEdict->GetUnknown(); if (pServerUnknown) pEdict->m_pNetworkable = pServerUnknown->GetNetworkable(); } CALL_LISTENERS(OnEntityCreated, iIndex, ptr((CBaseEntityWrapper*) pEntity)); }
//----------------------------------------------------------------------------- // Returns the next valid edict_t instance. //----------------------------------------------------------------------------- edict_t *CPlayerGenerator::getNext() { edict_t* pEdict = NULL; while(m_iEntityIndex < gpGlobals->maxClients) { m_iEntityIndex++; pEdict = EdictFromIndex(m_iEntityIndex); if (pEdict) break; } return pEdict; }
void MRecipientFilter::AddAllPlayers() { m_Recipients.RemoveAll(); for(int i = 1; i <= gpGlobals->maxClients; i++) { // Make sure the player is valid edict_t* pPlayer; if(!EdictFromIndex(i, pPlayer)) continue; m_Recipients.AddToTail(i); } }
void MRecipientFilter::AddRecipient(int iPlayer) { // Return if the recipient is already in the vector if(m_Recipients.Find(iPlayer) != m_Recipients.InvalidIndex()) return; // Make sure the player is valid edict_t* pPlayer; if(!EdictFromIndex(iPlayer, pPlayer)) return; // Skip non-player entities. if (iPlayer > WORLD_ENTITY_INDEX && iPlayer <= gpGlobals->maxClients) m_Recipients.AddToTail(iPlayer); }
//----------------------------------------------------------------------------- // Returns an Edict instance from the given UserID. //----------------------------------------------------------------------------- bool EdictFromUserid( unsigned int iUserID, edict_t*& output ) { for (int iCurrentIndex = 1; iCurrentIndex <= gpGlobals->maxClients; iCurrentIndex++) { edict_t* pEdict; if (!EdictFromIndex(iCurrentIndex, pEdict)) continue; if (engine->GetPlayerUserId(pEdict) == iUserID) { output = pEdict; return true; } } return false; }
//----------------------------------------------------------------------------- // Returns an index from the given IntHandle. //----------------------------------------------------------------------------- bool IndexFromIntHandle( unsigned int iEntityHandle, unsigned int& output ) { if (iEntityHandle == (int) INVALID_EHANDLE_INDEX) return false; CBaseHandle hBaseHandle(iEntityHandle); unsigned int iEntityIndex; if (!IndexFromBaseHandle(hBaseHandle, iEntityIndex)) return false; edict_t* pEdict; if (!EdictFromIndex(iEntityIndex, pEdict)) return false; CBaseHandle hTestHandle; if (!BaseHandleFromEdict(pEdict, hTestHandle)) return false; if (!hTestHandle.IsValid() || hBaseHandle.GetSerialNumber() != hTestHandle.GetSerialNumber()) return false; output = iEntityIndex; return true; }