Raised This Month: $ Target: $400
 0% 

Questions Find Entity in Sphere


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-16-2016 , 13:13   Questions Find Entity in Sphere
Reply With Quote #1

I have few questions about this function
PHP Code:
engfunc(EngFunc_FindEntityInSphere, -1originradius
How can i use it efficiently to detect if a wall is at an x or y distance from an origin ?
Will this following be efficient since:

1. it doesn't have a defined radius from the beginning, and it will check a very large area
2. it doesn't have a certain entity to search for so it will detect and others before checking for func_wall

PHP Code:
engfunc(EngFunc_FindEntityInSphere, -1originradius

if( 
entity class name func_wall
{
    
    if(
radius x)
    {
        do 
this
    
}
    else if(
radius y)
    {
        do 
this
    
}
    else
    {
        do 
that
    
}

Whitez is offline
Zynda
Member
Join Date: Jul 2011
Old 05-16-2016 , 18:47   Re: Questions Find Entity in Sphere
Reply With Quote #2

I found it unclear as to what you wish to accomplish from your post.
So i've gone ahead and created an example on how you could use EngFunc_FindEntityInSphere to search and then filter entities.
PHP Code:
new Float:origin[3] = { 0.00.00.0 // Origin to search from, could be a player origin or something
new Float:radius 1000.0 // Size of the sphere to search in

new entity = -// Starting entity

while( ( entity engfuncEngFunc_FindEntityInSphereentityoriginradius ) ) > )
{
    
// Get some entity properties
    
    
new classname[64]
    
peventitypev_classnameclassnamecharsmaxclassname  ) )
    
    new 
Float:health
    pev
entitypev_healthhealth )
    
    new 
Float:entityOrigin[3]
    
peventitypev_originentityOrigin )

    new 
Float:distance vector_distanceoriginentityOrigin )
    
    
// Print information about the entity
    
console_printid"[Ent id: %i] [Classname: %s] [Distance: %f]"entityclassnamedistance )
    
    
// Comparison examples:
    
    // The entity is a func_wall
    
if( equalclassname"func_wall" ) )
    {
        
// Do stuff
    
}
    
    
// The entity has a health above 70
    
if( health 70.0 )
    {
        
// Do stuff
    
}
    
    
// The distance from the search origin to the entity's origin is less than 250 units
    
if( distance 250.0 )
    {
        
// Do stuff
    
}

Zynda is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-16-2016 , 23:04   Re: Questions Find Entity in Sphere
Reply With Quote #3

I am trying to check if there is a wall around the origin of a player on a radius of both 100 measures and 300
Then create three cases, case radius <=100 , case 100 < radius <= 300, case default

About vector distance from player's origin to wall's origin, the origin of the wall isn't actually at the middle of the wall? meaning that if it is a large block the player might be even touching it and still be at a distance of a over 100
Whitez is offline
Zynda
Member
Join Date: Jul 2011
Old 05-17-2016 , 10:19   Re: Questions Find Entity in Sphere
Reply With Quote #4

The origin pev of a func_wall will usually always be 0 0 0, unless it has an origin brush tied to it.
This is purely a map creators choice and there is not much you can do about it.
I've found that you can calculate an effective origin like this:
PHP Code:
new Float:virtualOrigin]

new 
Float:entityAbsmin]
new 
Float:entityAbsmax]

peventitypev_absminentityAbsmin )
peventitypev_absmaxentityAbsmax )

for( new 
03i++ )
{
    
virtualOrigin] = ( ( entityAbsmax] + entityAbsmin] ) / )

Where virtualOrigin is the entity's 'true' origin.

Last edited by Zynda; 05-17-2016 at 10:33.
Zynda is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-17-2016 , 11:28   Re: Questions Find Entity in Sphere
Reply With Quote #5

If you want to detect walls, use traceline.
__________________
HamletEagle is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-17-2016 , 12:48   Re: Questions Find Entity in Sphere
Reply With Quote #6

Well i need to detect any wall around the player ( back, front, sides ) not only in front

Let me explain exactly what i want to do, so you guys can understand better what i am looking for

Everytime a player is killed i want to spawn at his origin a sprite, but sometimes the sprite is too large and it is going through the wall

To make sure that the sprite won't collide with the wall i need to reduce it's scale, but i want to reduce the scale only when the player is close to walls, and not when he is in an open area far from walls

So in case the player is close to a wall, i want to reduce the scale of the sprite to 2, in case the player is very close to a wall ( for example in a tunnel like on cs_assault ) i want to reduce the scale of the sprite to 1

Last edited by Whitez; 05-17-2016 at 12:50.
Whitez is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-18-2016 , 15:16   Re: Questions Find Entity in Sphere
Reply With Quote #7

In this case I would try to use multiple TraceHull with a size closest to the sprites different sizes.
__________________
Black Rose is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-19-2016 , 10:52   Re: Questions Find Entity in Sphere
Reply With Quote #8

Then for just one radius? any method without the need of a loop?

I don't see the need of a loop in this situation, can't it be done like this?

PHP Code:
if(engfunc(EngFunc_FindEntityInSphere"func_wall"origin100.0))
{
    
    
code here
    

Whitez is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-19-2016 , 11:31   Re: Questions Find Entity in Sphere
Reply With Quote #9

Not all walls are "func_wall". For example, the map. That's why you should use TraceHull and see if it hits anything at all.
__________________
Black Rose is offline
Whitez
Member
Join Date: Apr 2016
Location: London, UK
Old 05-19-2016 , 11:45   Re: Questions Find Entity in Sphere
Reply With Quote #10

I don't care about the ground, only walls, or you mean walls assigned as func_detail, func_breakable entities?

Last edited by Whitez; 05-19-2016 at 11:45.
Whitez 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 18:44.


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