AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ H3LP ] Check entity in origin distance (https://forums.alliedmods.net/showthread.php?t=302142)

DarthMan 10-18-2017 05:45

[ H3LP ] Check entity in origin distance
 
Hello. How can I check the closest entity in an origin distance? Like if I use vector_distance from point1 to point2, I wanna get the closest entity from that vector distance.

KiLLeR. 10-18-2017 06:06

Re: [ H3LP ] Check entity in origin distance
 
Loop through all entities in this distance and keep only the closest one in variable.

Natsheh 10-18-2017 06:37

Re: [ H3LP ] Check entity in origin distance
 
Use Find entity in sphere and check who got the closest distance

DarthMan 10-18-2017 06:50

Re: [ H3LP ] Check entity in origin distance
 
Quote:

Originally Posted by Natsheh (Post 2555166)
Use Find entity in sphere and check who got the closest distance

I used find entity in sphere, but I don't know how to get them in a line from fOrigin to fRet. So this acts like a TraceLine, and I only want to look at entities from that line. If I user vector_distance the normal way it won't work as I want to. I can try getting all entities origin, and check if there is a close distance between the entity origin and fRet, but, wouldn't that check it in a sphere? Like it can return a wrong entity.

Natsheh 10-18-2017 08:15

Re: [ H3LP ] Check entity in origin distance
 
Quote:

Originally Posted by DarthMan (Post 2555168)
I used find entity in sphere, but I don't know how to get them in a line from fOrigin to fRet. So this acts like a TraceLine, and I only want to look at entities from that line. If I user vector_distance the normal way it won't work as I want to. I can try getting all entities origin, and check if there is a close distance between the entity origin and fRet, but, wouldn't that check it in a sphere? Like it can return a wrong entity.

PHP Code:


new Float:MaxDistance 500.0Float:fDistance;
new 
entFloat:origin_1[3], Float:origin_2[3], iTarget;
while( (
ent engfunc(EngFunc_FindEntityInSphereentorigin_1MaxDistance) > 0)
{
      
pev(entpev_originorigin_2)
      if((
fDistance get_distance_f(origin_1origin_2)) < MaxDistance)
      {
                 
iTarget ent;
                 
MaxDistance fDistance;
      }



Origin_1 is where your point 1 is located


All times are GMT -4. The time now is 23:10.

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