[CS:GO] How to properly get the free edict count
How to properly get the free edict count
Compared to other source games CSGO has a pretty different way of handling edicts, there's 2048 slots that can be allocated and then used. Edict slots can be in 3 different states. They can be allocated or not allocated, they can be free, they can be on a timer. Because of these states it can be pretty hard to get the number of used/free edicts on a server as the engine doesn't store such number anywhere. What most plugins do to count the number of edicts is to loop over all entities and use IsValidEdict(edict);. Now here's the part why that's wrong. The first 66 edict slots will ALWAYS be reserved for players and cannot be assigned to other entities, so all edict counts in plugins are off at least by 66 - clientCount. Source The second reason why these counters will be off is because everytime an edict slot is freed an internal cooldown will be set on that slot. While this cooldown is still present that edict slot cannot be used. Source Why is GetEntityCount() not a viable option? GetEntityCount returns sv.num_edicts which represents the number of allocated edicts. Not the number of unused edicts. Once an edict is allocated once it will never be unallocated until next restart, it will only be freed. Source Proof of concept Now to the most interesting part, how to actually get the real number of free edicts. PHP Code:
PHP Code:
As a last resort the game will use edict slots even if they are in a cooldown, this is supposed to prevent some cheats in dota2. If this feature wasn't a thing many CSGO maps would crash the server on every new round. If you want to use the edict count code to prevent edict limit crashes you should remove the freetime checks as those will not be changing any edict behaviour if the server is about to hit the edict limit |
Re: [CS:GO] How to properly get the free edict count
Thanks for the research and explanation.
However, IMHO, I would call it "order of indices using" rather than "free edict count", because as you already told, they all are available for using regardless of the "timer" state. I just doubled your paraphrased source: Quote:
Are there other cases when that's not true? |
| All times are GMT -4. The time now is 22:43. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.