3 registered members (AndrewAMD, exile, Ayumi),
836
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: EVENT_DETECT nearest target.
[Re: mEnTaL]
#405480
07/31/12 19:51
07/31/12 19:51
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
One simple way would be
var min_dist = 100;
result = c_scan
if(you)if(vec_dist(my.x, you.x) < min_dist) _found_a_near_ent;
//if(result < 100) _found_a_neaR_ent; //could work
Or u save all found ents in an array then checking all distances to get the "real" nearest ent. Edit: Manual says YOU is automatic set to nearest entity.
Last edited by rayp; 07/31/12 20:00.
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: EVENT_DETECT nearest target.
[Re: mEnTaL]
#405484
07/31/12 20:22
07/31/12 20:22
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
: var i; for (i=0; i<5; i++) // repeat 5 times x *= x; // calculate the 5th power of x
edit: Adding something to an array (if i remember right) looks like this:
var my_array[100];
var my_index;
var i;
//add
c_scan
if(you)
{
my_Array[my_Index] = handle (you);
my_index += 1;
}
But this is a long time ago i used a array with 3dgs Edit2: theres an simple way to go through all ents with an "for" then using vec_dist, but i cant remember. Edit3: This is what i meant. U could modify it with vec_dist etc. to check for all ents function hide_all_ents() { // repeat for all entities for(you = ent_next(NULL); you; you = ent_next(you)) set(you,INVISIBLE); // make entity invisible } }
Last edited by rayp; 07/31/12 21:20.
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: EVENT_DETECT nearest target.
[Re: mEnTaL]
#405495
07/31/12 22:13
07/31/12 22:13
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
I know what this code above does it should show you just the basic. Here is the mod which i meant above. It works without c_scan. I did not test it but i think it finds the nearest one. Use it fex. like this find_nearest(player); This should find the nearest you to player.
// -------------------------------------------------------------------------------------------------------------------------------------------------
function find_nearest(ENTITY* ent)
{
var you_handle;
var _dist=1000;
var _ndist;
var dist_to_nearest;
// repeat for all entities
for(you = ent_next(NULL); you; you = ent_next(you))
{
if(you.skill2 == 1)
{
_ndist = vec_dist(ent.x, you.x);
if (_ndist < _dist) { _dist = _ndist; you_handle = handle(you); }
}
}
dist_to_nearest = _dist; //nearest entity to "ent"
you = ptr_for_handle(you_handle); //you to nearest found
}
// -------------------------------------------------------------------------------------------------------------------------------------------------
Last edited by rayp; 07/31/12 22:59.
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: EVENT_DETECT nearest target.
[Re: mEnTaL]
#405498
08/01/12 00:02
08/01/12 00:02
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
Your welcome ! Btw: I blame the manual:
function hide_all_ents() { // repeat for all entities for(you = ent_next(NULL); you; you = ent_next(you)) set(you,INVISIBLE); // make entity invisible } }
Edit2: I now used my own function from above the first time. Worked well.
Last edited by rayp; 08/03/12 16:03.
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
|