![]() |
Safe to keep edict_t pointers ?
Some edict_t are indeed useful, like listenserver or worldspawn.
Clients edict_t (Bots or players) is also obviously useful. These edicts can be acquired by pfnPEntityOfEntIndex() (or INDEXENT macro), however I don't like idea of calling HL engine if we don't have to. My question is, is it safe to keep these entities and use them within your plugin ? Of course every map change I shall update listenserver, worldspawn and remove all player edicts. I don't know what could replace listenserver (acquired in ClientConnect()) and worldspawn (acquired in Spawn()). Client edicts could be replaced by client indexes and every time I will need edict, I call pfnPEntityOfEntIndex(). I shall think of "new client is here, add it to your list" in ClientPutInServer() and of "client left, remove it from your list" in ClientDisconnect() and on map change. So is this approach with using edicts OK ? Is it safe to think location of edicts doesn't change as long as client is connected ? (It really helps to understand the problem when you write everything down :) ) |
Re: Safe to keep edict_t pointers ?
Sure as long as you check if their still valid(ie not kicked or removed):
Code:
bool IsNull (edict_t *pEdict) Code:
// Check if a player is valid |
Re: Safe to keep edict_t pointers ?
In the HL1 engine, it is safe to keep track of entities either by pointer, or by index. Entities (at least their edict_t) don't get relocated by the engine in memory. However, some slots in the entity list may be empty, because of entities that are created and destroyed dynamically. Typically, entity #0 is worldspawn, entities #1 to #maxClients are player slots (the listenserver being NOT NECESSARILY entity #1), entities from #maxClients+1 are the map's entities, beyond are the dynamically spawned ones and even beyond are the temporary entities.
Be aware that the HL1 engine can leave bad entity pointers around, i.e. edict_t pointers that are not NULL, that do point to somewhere, but where there's no more edict_t structure behind. That's why I highly recommend to check your edict_t pointers with FNullEnt() as often as possible. BE AWARE AGAIN though, that the FNullEnt() provided in the HL1 SDK is itself buggy! it does NOT make enough checks to test for an edict pointer's validity! You also have to check if the entity classname is defined, like this: Code:
// fixed FNullEnt(). You can trust this one. |
All times are GMT +2. The time now is 09:20. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.