Raised This Month: $87 Target: $400
 21% 

GetEntityCount problem.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Electr000999
Senior Member
Join Date: Aug 2011
Location: Russia, Perm
Old 02-27-2012 , 05:46   GetEntityCount problem.
Reply With Quote #1

i am write check to the number of entity and used GetEntityCount () she is gives only one number, and when you create a new entity that number does not change at all. Tested this with the output message in chat
Code message in chat.
Code:
    PrintToChat(client, "%d", GetEntityCount());
For example typing command "report_entities" the console I got the report: "Total 575 entities (0 empty, 489 edicts)"
i got in chat 712 and if the creation of new entity is the number does not change. And it was repeated again and again..


I have tested this issue on left 4 dead 2 dedicated server on snapshots 1.5.0-dev (Sourcemod) / 1.9.0-dev (Metamod).
help.

Last edited by Electr000999; 02-27-2012 at 06:36.
Electr000999 is offline
Send a message via Skype™ to Electr000999
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 02-27-2012 , 10:18   Re: GetEntityCount problem.
Reply With Quote #2

This is the method I use, it seems to be fairly accurate.
Code:
new g_iCurEntities;

public OnMapStart()
{
    g_iCurEntities = 0;
    for(new i = 1; i <= MaxEntities; i++)
        if(IsValidEntity(i))
            g_iCurEntities++;
}

public OnEntityDestroyed(entity)
{
    if(entity >= 0)
    {
         g_iCurEntities--;
    }
}

public OnEntityCreated(entity, const String:classname[])
{
    if(entity >= 0)
    {
        g_iCurEntities++;
    }
}
__________________

Last edited by thetwistedpanda; 02-27-2012 at 10:19.
thetwistedpanda is offline
Electr000999
Senior Member
Join Date: Aug 2011
Location: Russia, Perm
Old 02-27-2012 , 15:02   Re: GetEntityCount problem.
Reply With Quote #3

Quote:
Originally Posted by thetwistedpanda View Post
This is the method I use, it seems to be fairly accurate.
Code:
new g_iCurEntities;

public OnMapStart()
{
    g_iCurEntities = 0;
    for(new i = 1; i <= MaxEntities; i++)
        if(IsValidEntity(i))
            g_iCurEntities++;
}

public OnEntityDestroyed(entity)
{
    if(entity >= 0)
    {
         g_iCurEntities--;
    }
}

public OnEntityCreated(entity, const String:classname[])
{
    if(entity >= 0)
    {
        g_iCurEntities++;
    }
}
interesting method, but the difference is at about -100

example : in server entities "Total 643 entities (0 empty, 557 edicts)" (Report from the console)
in chat message used your method "Entities number: 556"

hmmm "edicts" and "Entities number" are very close

Last edited by Electr000999; 02-27-2012 at 15:07.
Electr000999 is offline
Send a message via Skype™ to Electr000999
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 02-27-2012 , 15:24   Re: GetEntityCount problem.
Reply With Quote #4

There must be something going on that's L4D specific; for CS:S it's accurate to within ~5 props depending on the map. You could try changing OnMapStart to OnMapEnd, and not decreasing g_iCurEntities on destruction if == 0.
__________________
thetwistedpanda is offline
devilesk
New Member
Join Date: May 2019
Old 10-22-2019 , 12:50   Re: GetEntityCount problem.
Reply With Quote #5

From KyleS's comment on the API page for GetEntityCount:
Quote:
This isn't what you think it is. This function will return the highest edict index in use on the server, not the true number of active entities.
Another discussion where this came up https://forums.alliedmods.net/showpo...68&postcount=6

EDIT: I know this is an old thread but it's also the first search result for "sourcemod GetEntityCount" and I was also wondering about the behavior of GetEntityCount, because I often see code that loops through all entities using GetEntityCount as an upper bound.

Last edited by devilesk; 10-22-2019 at 12:52.
devilesk is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:35.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode