AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   find ent by origin. (https://forums.alliedmods.net/showthread.php?t=49970)

[ --<-@ ] Black Rose 01-16-2007 16:52

find ent by origin.
 
This fuction is supposed to find an entity, but it finds the wrong one.
Maby there's a way to continue from 'ent' but i dunno how to stop the loop if nothing was found with classname 'my_classname' in specifyed sphere.
Funny thing is it worked before, and I can't remember me changing any of it.
Code:
stock FindEntAtOrigin(Float:fOrigin[3]) {         new classname[10], Float:fRadius, ent         while ( fRadius < 50.0 ) {                 fRadius += 5.0         ent = engfunc(EngFunc_FindEntityInSphere, g_MaxPlayers, fOrigin, fRadius)                 if ( ent ) {             pev(ent, pev_classname, classname, 9)             if ( equal(classname, "my_classname") )                 return ent;         }     }     return 0; }

XxAvalanchexX 01-16-2007 16:57

Re: find ent by origin.
 
The first argument for the FindEntity functions is the entity index (minus one) to start searching from. So, if you use 134, it will begin looking at entities 135 and onward. This is how you would process all entities in a sphere:

Code:
ent = g_MaxPlayers; while((ent = engfunc(EngFunc_FindEntityInSphere, ent, fOrigin, fRadius)) != 0) {      // whatever }

It keeps checking from ent and onwards. Since ent keeps getting updated as the last entity that it found, it never catches the same entity twice. It keeps going until the next entity found is returned 0, meaning there are no more.

[ --<-@ ] Black Rose 01-16-2007 16:58

Re: find ent by origin.
 
Thank you Avalanche.
I thought about something like that but i wasn't sure how to stop it.

EDIT2: It works now.
current function:
Code:
stock FindEntAtOrigin(Float:fOrigin[3]) {         new classname[10], Float:fRadius, ent         while ( fRadius < 50.0 && ! ent ) {                 fRadius += 10.0         ent = g_MaxPlayers                 while ( ent != 0 ) {                         ent = engfunc(EngFunc_FindEntityInSphere, ent, fOrigin, fRadius)                         pev(ent, pev_classname, classname, 9)                         if ( equal(classname, "wpn_spawn") )                 return ent;         }     }     return 0; }


All times are GMT -4. The time now is 22:25.

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