c_scan and "you" pointer to closest entity?

Posted By: Loopix

c_scan and "you" pointer to closest entity? - 03/15/08 10:21

I know...this is simple stuff and has been asked before (even recently on this forum). Unfortunately all answers diden't really help me
I manage to get a handle on the closest entity but the handle won't switch when a second entity comes closer than the first.
I use "my.enemy" as skill to determine the current enemy.

Please...can someone post a piece of code that accomplishes that in a simple way (in good old c-script) ?

Thank you!
Posted By: Dark_samurai

Re: c_scan and "you" pointer to closest entity? - 03/15/08 12:27

You have to do the scanning in a loop, so that you always have the right entity.
If you want more help, please post your code.

Dark_Samurai
Posted By: tindust

Re: c_scan and "you" pointer to closest entity? - 03/15/08 15:40

Dark_Samurai is right, you need to put the scan in a refresh loop. Something like this:

Code:
while(scanner_is_on)
{
c_scan(blah);
wait(5);
}


No need to have the scan done every cycle, saves processing power. This will update the you pointer accordingly.

cheers,
Posted By: Loopix

Re: c_scan and "you" pointer to closest entity? - 03/15/08 19:02

Thanks guys...I got it working (at least I think so...). I had to change my scan event like this:
Code:

var min_dist;
////scans for enemies
function scan_enemies()
{
min_dist = 999999;
////we are scanning
my.is_scanning = on;

////set scan mode
my.scan_mode = scan_search;

////set scan cone
temp.x = 360;
temp.y = 0;
temp.z = my.attack_range;

////do the search/scan
c_scan(my.x,my.pan,temp,ignore_me + scan_ents);

////wait a little before next scan (performance reasons)
wait(-scan_search_sleep);

////we have finished scanning
my.is_scanning = off;
}

function entity_search_scan_event_fight()
{
if(event_type == event_scan){

if(you){
////some conditions to set the handle
if(you.scan_mode == scan_search && vec_dist(you.x,my.x) < you.attack_range && you.entity_type_id >= 0 && you.allied_id != my.allied_id){


if(vec_dist(my.x, you.x) < min_dist)
{
min_dist = vec_dist(my.x,you.x);
you.enemy = handle(my);
}
}
}
}
}



Then I simple do like this in the entity action:
Code:


...

if(my.is_scanning == off)
{
////scan for enemies
scan_enemies();
}

if(my.enemy){

//get a pointer to the enemy!
you = ptr_for_handle(my.enemy);

//if the pointer is valid
if(you){
blablabla...do things!
}


}

...


© 2024 lite-C Forums