This is a last resort, but use a periotic event to check for a buff, then add the buff in the ability Beserk. Then, pick every unit in the playable map area not in Invis_Group and add the ghost ability to the picked unit, and then add that unit to Invis_Group. Next, pick every unit in Invis_Group, check if the unit has your buff, and if it doesn't, remove the ghost ability from the unit and remove the unit from Invis_Group.