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!
}


}

...