AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Questions Find Entity in Sphere (https://forums.alliedmods.net/showthread.php?t=282770)

Whitez 05-16-2016 13:13

Questions Find Entity in Sphere
 
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
    
}



Zynda 05-16-2016 18:47

Re: Questions Find Entity in Sphere
 
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
    
}



Whitez 05-16-2016 23:04

Re: Questions Find Entity in Sphere
 
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

Zynda 05-17-2016 10:19

Re: Questions Find Entity in Sphere
 
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.

HamletEagle 05-17-2016 11:28

Re: Questions Find Entity in Sphere
 
If you want to detect walls, use traceline.

Whitez 05-17-2016 12:48

Re: Questions Find Entity in Sphere
 
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

Black Rose 05-18-2016 15:16

Re: Questions Find Entity in Sphere
 
In this case I would try to use multiple TraceHull with a size closest to the sprites different sizes.

Whitez 05-19-2016 10:52

Re: Questions Find Entity in Sphere
 
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
    



Black Rose 05-19-2016 11:31

Re: Questions Find Entity in Sphere
 
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.

Whitez 05-19-2016 11:45

Re: Questions Find Entity in Sphere
 
I don't care about the ground, only walls, or you mean walls assigned as func_detail, func_breakable entities?


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

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