AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [H3LP] FindEntityInSphere (https://forums.alliedmods.net/showthread.php?t=314162)

DarthMan 02-06-2019 05:47

[H3LP] FindEntityInSphere
 
Hello. Can someone show me how to use FindEntityInSphere using sdktools?
I want to search for entities in sphere of 100.0 by looping.
On AMXX it can be done this way:
PHP Code:

while((iEnt engfunc(EngFunc_FindEntityInSphereiEntfOrigin100.0)) != 0

Code:

"Games"
{
        "#default"
        {
                "Signatures"
                {
                        "FindEntityInSphere"  // "    magnitude: %f"
                        {
                                "library"      "server"
                                "windows"      "\x55\x8B\xEC\x83\xEC\x0C\x53\x56\x8B\xF1\x8B\x4D\x08\x57"
                                "linux" "@_ZN17CGlobalEntityList18FindEntityInSphereEP11CBaseEntityRK6Vectorf"
                        }
                }
        }
}

Thanks !

Dragokas 02-10-2019 13:26

Re: [H3LP] FindEntityInSphere
 
FindEntityByClassname + GetVectorDistance

DarthMan 02-10-2019 16:27

Re: [H3LP] FindEntityInSphere
 
Quote:

Originally Posted by Dragokas (Post 2639046)
FindEntityByClassname + GetVectorDistance

Ye but that only finds by specific classname. And looping through entities is not a good practice anyways. For what I need now it could be enough, but I've other plugin where I wanna get all entities in given sphere.

Dragokas 02-11-2019 00:13

Re: [H3LP] FindEntityInSphere
 
I'm sure FindEntityInSphere() do the same looping. Devs will correct me if I'm wrong.

+ sm_count
https://forums.alliedmods.net/showthread.php?p=1729015

Code:

        for( int i = 0; i < 4096; i++ )
        {
                if( IsValidEntity(i) && IsValidEdict(i) )
                {
                        GetEdictClassname(i, sTemp, sizeof(sTemp));


Lux 02-11-2019 00:24

Re: [H3LP] FindEntityInSphere
 
Quote:

Originally Posted by Dragokas (Post 2639117)
I'm sure FindEntityInSphere() do the same looping. Devs will correct me if I'm wrong.

+ sm_count
https://forums.alliedmods.net/showthread.php?p=1729015

Code:

        for( int i = 0; i < 4096; i++ )
        {
                if( IsValidEntity(i) && IsValidEdict(i) )
                {
                        GetEdictClassname(i, sTemp, sizeof(sTemp));


https://github.com/ValveSoftware/sou....cpp#L685-L711

It looks that way.

Also why loop 4096 times you don't need to
you only can have 2048 entities +1 for world spawn.

eyal282 02-11-2019 01:10

Re: [H3LP] FindEntityInSphere
 
GetEntityCount is what I use for looping. I am unaware of any issues.

Powerlord 02-11-2019 02:23

Re: [H3LP] FindEntityInSphere
 
Quote:

Originally Posted by Lux (Post 2639118)
you only can have 2048 entities +1 for world spawn.

Worldspawn counts as one of the 2048 entities, specifically entity 0.

DarthMan 02-11-2019 03:27

Re: [H3LP] FindEntityInSphere
 
Quote:

Originally Posted by Powerlord (Post 2639127)
Worldspawn counts as one of the 2048 entities, specifically entity 0.

So for sphere it's a good idea to just start a loop from 1 to 2048 if I want to find all entities in a given distance, check if they are valid and get vector distance between player origin and entity origin? That's fine too, but using directly FindEntityInSphere from the server dll would be faster because it only makes 1 call, whereas using the mentioned method would make plenty of calls to the engine, each time it checks if the entity is valid and gets origin between the 2. Turns out that the signature is wrong, FF uses the 2006 sdk and I used IDA to search for that signature of bytes and it couldn't find any function. My plug-in also reported that the signature could not be found.

Lux 02-11-2019 04:20

Re: [H3LP] FindEntityInSphere
 
Quote:

Originally Posted by Powerlord (Post 2639127)
Worldspawn counts as one of the 2048 entities, specifically entity 0.

Yea dam thanks for pointing that out.

https://github.com/ValveSoftware/sou...ic/const.h#L65

Quote:

Originally Posted by DarthMan (Post 2639135)
So for sphere it's a good idea to just start a loop from 1 to 2048 if I want to find all entities in a given distance, check if they are valid and get vector distance between player origin and entity origin? That's fine too, but using directly FindEntityInSphere from the server dll would be faster because it only makes 1 call, whereas using the mentioned method would make plenty of calls to the engine, each time it checks if the entity is valid and gets origin between the 2. Turns out that the signature is wrong, FF uses the 2006 sdk and I used IDA to search for that signature of bytes and it couldn't find any function. My plug-in also reported that the signature could not be found.

Yes sourcemod is slower but it's not that slow.

If your game is CSGO
you can use backup's extension

https://forums.alliedmods.net/showthread.php?t=304710

PHP Code:

 //Find entities within a radius. Pass 'null' to start an iteration, or reference to a previously found entity to continue a search
    //hscript FindInSphere(hscript, vector, float);
    
public static native HScript FindInSphere(HScript afloat[] bfloat c); 


psychonic 02-11-2019 11:19

Re: [H3LP] FindEntityInSphere
 
If you end up looping, it's probably faster to use FindEntityByClassname with a classname of "*". (It supports wildcarding the end of the string). That will just loop over all entities in the global entity list, rather than checking every possibly index.


All times are GMT -4. The time now is 09:06.

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