Raised This Month: $51 Target: $400
 12% 

Solved [H3LP] FindEntityInSphere


Post New Thread Reply   
 
Thread Tools Display Modes
DarthMan
Veteran Member
Join Date: Aug 2011
Old 02-11-2019 , 11:45   Re: [H3LP] FindEntityInSphere
Reply With Quote #11

Quote:
Originally Posted by psychonic View Post
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.
Ah, never knew about it. I mean, I knew that * was a possibility on the goldsrc engine. Good idea and thanks for sharing.
DarthMan is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 02-11-2019 , 12:45   Re: [H3LP] FindEntityInSphere
Reply With Quote #12

Untested. On paper should work ...

PHP Code:

public void Function()
{
    
int ent = -1;
    while ((
ent FindEntityInSphere(ent, {20.020.020.0}, 100.0)) != -1)
    {
        
// do something
    
}
}

int FindEntityInSphere(int entfloat[] originfloat distance)
{
    while ((
ent FindEntityByClassname(ent"*")) != -1)
    {
        
float buffer[3];
        
GetEntPropVector(entProp_Send"m_vecOrigin"buffer);
        
        if (
GetVectorDistance(originbuffer) < distance)
        {
            return 
ent;
        }
    }
    
    return -
1;

__________________
Ilusion9 is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 02-11-2019 , 13:31   Re: [H3LP] FindEntityInSphere
Reply With Quote #13

Quote:
Originally Posted by Ilusion9 View Post
Untested. On paper should work ...

PHP Code:

public void Function()
{
    
int ent = -1;
    while ((
ent FindEntityInSphere(ent, {20.020.020.0}, 100.0)) != -1)
    {
        
// do something
    
}
}

int FindEntityInSphere(int entfloat[] originfloat distance)
{
    while ((
ent FindEntityByClassname(ent"*")) != -1)
    {
        
float buffer[3];
        
GetEntPropVector(entProp_Send"m_vecOrigin"buffer);
        
        if (
GetVectorDistance(originbuffer) < distance)
        {
            return 
ent;
        }
    }
    
    return -
1;

Yeah, I've been thinking of dking it the same way. Thanks, I guess this will help others looking for the same thing.
DarthMan is offline
Reply



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 04:34.


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