AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=58)
-   -   GetEntityCount problem. (https://forums.alliedmods.net/showthread.php?t=179204)

Electr000999 02-27-2012 04:46

GetEntityCount problem.
 
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.

thetwistedpanda 02-27-2012 09:18

Re: GetEntityCount problem.
 
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++;
    }
}


Electr000999 02-27-2012 14:02

Re: GetEntityCount problem.
 
Quote:

Originally Posted by thetwistedpanda (Post 1658457)
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

thetwistedpanda 02-27-2012 14:24

Re: GetEntityCount problem.
 
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.

devilesk 10-22-2019 11:50

Re: GetEntityCount problem.
 
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.


All times are GMT -4. The time now is 18:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.