Yepp, I also was thinking about a different starting variant. So, yes, a starting of the rule from inside scar would be better, otherwise it could be that the SGroup would be cleared if the blackhawk moves over the removing target, like the map_entry_point in the example.
So you should start a scar script with your spawner rgd (a delay of one second would be enough) with the "start_blackhawk" and the modified script from above:
Code:
function Custom_CheckBlackhawk()
bh_found = false
for i = 1,World_GetPlayerCount() do
local player_id = World_GetPlayerAt(i)
-- you can also use "Player_HasBuilding" to choose the hq for example)
if (Player_HasMapEntryPosition(player_id)) then
local add_MapEntryPoint = function(egroupid, itemindex, entityID)
if (Entity_GetBlueprint(entityID) == EBP.STRAT_POINT.ENTRY) then
map_entry_pos = Util_GetPosition(entityID)
end
end
Player_GetAll(player_id)
EGroup_ForEach(eg_allentities, add_MapEntryPoint)
local sg_blackhawk = function(SGroupID, itemindex, squadID)
if (Squad_GetBlueprint(squadID) == SBP.CW.BLACKHAWK) then
if map_entry_pos == SGroup_GetPosition(SGroupID) then
SGroup_DestroyAllSquads(SGroupID)
else
bh_found = true
--------------------------------------
-- this part you only need if the Blackhawk do not return to a return location
-- and your checking function will get the blackhawk sometime
-- now you are sure your Blackhawk is doing it.
--------------------------------------
if Squad_IsMoving(squadID) == false then
if Timer_Exists(wait_delay) then
if Timer_GetRemaining(wait_delay) <= 0.01 then
-- this will move your Blackhawk back to the map_entry_point
Squad_SetPosition(squadID, map_entry_pos, map_entry_pos)
Timer_End(wait_delay)
end
else
-- set this delay to a time the Blackhawk needs for reinforcement)
Wait_Delay(5)
end
end
--------------------------------------
end
end
end
Player_GetAll(player_id)
SGroup_ForEach(sg_allsquads, sg_blackhawk)
end
end
if bh_found == false then
Rule_RemoveMe()
end
end
function start_blackhawk()
bh_found = false
for i = 1,World_GetPlayerCount() do
local player_id = World_GetPlayerAt(i)
local sg_bh = function(SGroupID, itemindex, squadID)
if (Squad_GetBlueprint(squadID) == SBP.CW.BLACKHAWK) then
bh_found = true
end
end
Player_GetAll(player_id)
SGroup_ForEach(sg_allsquads, sg_bh)
end
if bh_found == false or Rule_Exists(Custom_CheckBlackhawk) == false then
Rule_AddInterval(Custom_CheckBlackhawk, 1)
end
end
--------------------------------------
-- this part you only need if the Blackhawk do not return to a return location
--------------------------------------
function Wait_Delay(iDelay)
wait_delay = World_GetGameTime()
Timer_Start(wait_delay, iDelay)
end
--------------------------------------
But the check is depending on where your blackhawk returns after reinforcing something. What's his last position?
and at the end_self_target
This would be great and the best I think, you are right here.
Edit: Script modified
If needed we can customizing the timer, so there is no overlapping, if two Blackhawks are on the map at the same time.