you can test this (no errors ... but work ???):

action ally()
{
if (my.status==attacking)
{................}
........
my.event=detect_target;
}

function detect_target ()
{
ENTITY*target1;
if (event_type == EVENT_DETECT)
{
if (you.skill2==1) // enemy detected
{
my.status=attacking; target1=you; }
}
}