Is there an easy way to count all temporary entities? Basically those that are created during gameplay (player entities, weapons, props, effects, etc).
I know I could use the entity listeners OnEntityCreated and OnEntityDeleted and count manually, but I hoped there is a function in the engine, is there?
Count temp entities
Maybe get the entities on LevelInit and then compare that with EntityIter at a later time? I don't really know what you are trying to accomplish by the vagueness of the question. Also, "temp entities" makes it sound like temp_entities, which is not what you are talking about.
I just saw that there was a misunderstanding on my side. I actually meant "entities with associated edicts" (basically all I can create an Entity instance of ?).
Sorry, for the vagueness, I'll explain what my goal is: I'm working on a mod where I place loads of prop_dynamics(_override), along with other entities.
Those entities have a "special" limit which is only 2048, and if I exceed this limit the server just crashes with an engine error instead of preventing the creation or anything.
I also just remembered this article, which shows me the report_entities command. I tried it out, and as far as I understand it, I will only need the edict count in the report.
Is there a way I can get this via my script?
Checking the length of EntityIter() should be a solution (if it does not iterate over non-networed entities), but I'm afraid that this might be too slow as I create entities quite frequently. I hope there is a way to read out the report as that should be way faster.
Sorry, for the vagueness, I'll explain what my goal is: I'm working on a mod where I place loads of prop_dynamics(_override), along with other entities.
Those entities have a "special" limit which is only 2048, and if I exceed this limit the server just crashes with an engine error instead of preventing the creation or anything.
I also just remembered this article, which shows me the report_entities command. I tried it out, and as far as I understand it, I will only need the edict count in the report.
Is there a way I can get this via my script?
Checking the length of EntityIter() should be a solution (if it does not iterate over non-networed entities), but I'm afraid that this might be too slow as I create entities quite frequently. I hope there is a way to read out the report as that should be way faster.
I doubt parsing the output of report_entities will be faster than using EntityIter(). You could even skip EntityIter() and use EntityGenerator() directly. As you can see it doesn't do very much if you just want to iterate over all entities.
But why do you think that it might be too slow? Did you experience any performance issues? If not I wouldn't search for another approach, because that doesn't make sense.
But why do you think that it might be too slow? Did you experience any performance issues? If not I wouldn't search for another approach, because that doesn't make sense.
I'm not sure which way would be faster. I don't think len(EntityIter()) would be too costly. Here is what report_entities does internally:
https://github.com/alliedmodders/hl2sdk/blob/sdk2013/game/server/entitylist.cpp#L1570
One issue, though, either way, is that they only account for "player" entities that are already on the server. I don't think you can utilize a possible "player" index with any other entity type. Therefore, you would need to use global_vars.max_clients to know how many client slots to account for.
*Edit: too slow.
https://github.com/alliedmodders/hl2sdk/blob/sdk2013/game/server/entitylist.cpp#L1570
One issue, though, either way, is that they only account for "player" entities that are already on the server. I don't think you can utilize a possible "player" index with any other entity type. Therefore, you would need to use global_vars.max_clients to know how many client slots to account for.
*Edit: too slow.
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Thanks for the responses!
I haven't tried any method yet because I'm not that far in my code yet, so I was just guessing that EntityIter() might be slower and I want the fastest possible method because in the end I will need to do a lot of stuff every second and even tick.
I think using entity listeners like L'In20Cible suggested would be the best approach then, I will need to use that for other things anyways. But I wasn't too sure if it could "detect" entities without associated edicts, could it? Because I don't want to count those.
I haven't tried any method yet because I'm not that far in my code yet, so I was just guessing that EntityIter() might be slower and I want the fastest possible method because in the end I will need to do a lot of stuff every second and even tick.
I think using entity listeners like L'In20Cible suggested would be the best approach then, I will need to use that for other things anyways. But I wasn't too sure if it could "detect" entities without associated edicts, could it? Because I don't want to count those.
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 117 guests