Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, exile, Ayumi), 836 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Print Thread
Rate Thread
EVENT_DETECT nearest target. #405479
07/31/12 19:42
07/31/12 19:42
Joined: Jul 2009
Posts: 96
M
mEnTaL Offline OP
Junior Member
mEnTaL  Offline OP
Junior Member
M

Joined: Jul 2009
Posts: 96
Ok, I have an entity which performs c_scan every frame and detects (throught EVENT_DETECT) only entities with skill2=2;
My question is how to make it detect the nearest one and set the "YOU" poiner to it?

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 Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
One simple way would be

Code:
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: rayp] #405482
07/31/12 20:03
07/31/12 20:03
Joined: Jul 2009
Posts: 96
M
mEnTaL Offline OP
Junior Member
mEnTaL  Offline OP
Junior Member
M

Joined: Jul 2009
Posts: 96
The first way you suggested will just find a near entity within the scanning cone. I've already done that. The problem is that my scanning distance is much more than 100 quants and i rly need to find the NEAREST one. The second way you mentioned is exactly what I need, but unfortunately I don't know how to make it.
Some help will be appreciated. laugh

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 Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Quote:
:
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:
Code:
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
Quote:

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: rayp] #405494
07/31/12 21:48
07/31/12 21:48
Joined: Jul 2009
Posts: 96
M
mEnTaL Offline OP
Junior Member
mEnTaL  Offline OP
Junior Member
M

Joined: Jul 2009
Posts: 96
Thanks for the reply, but that function will just hide all entities within the scan cone. I need something like that:
1. Use vec_dist to get the distances to all entities with skill2=1 within the scan cone
2. Compare the distances to each one of them
3. Determine which is the smallest distance
4. Set the "you" pointer to the nearest scanned entity

This is the sequence, but i just don't know how to make it work.

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 Offline

X
rayp  Offline

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.

Code:
// -------------------------------------------------------------------------------------------------------------------------------------------------
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: rayp] #405497
07/31/12 23:34
07/31/12 23:34
Joined: Jul 2009
Posts: 96
M
mEnTaL Offline OP
Junior Member
mEnTaL  Offline OP
Junior Member
M

Joined: Jul 2009
Posts: 96
Looks like it works. Thanks, man! laugh

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 Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Your welcome !

Btw: I blame the manual:
Quote:


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;

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1