This is how I approached it before- static units based on GUID and the distance tool
Code: Select all
function isincomms(unit)
local comm_units ={
{name='Bunker (Comm Center)', guid='CNJF8E-0HN1FT8ITCIGT'},
{name='Bunker (Comm Center)', guid='CNJF8E-0HN1FT8ITCIBJ'},
{name='Bunker (Comm Center)', guid='CNJF8E-0HN1FT8ITCIHC'},
{name='Bunker (Comm Center)', guid='CNJF8E-0HN1FT8ITCIK9'},
{name='Bunker (Comm Center)', guid='CNJF8E-0HN1FT8ITCHTL'}
}
for _,comm in ipairs(comm_units) do
if Tool_Range(unit.guid,comm.guid) <= 300 then
return true
end
end
return false
end
local units = VP_GetSide({side='USSR'}).units
for _,v in ipairs(units) do
local unit = SE_GetUnit({guid = v.guid})
if isincomms(unit) then
ScenEdit_SetUnit({guid=unit.guid,outofcomms=false})
else
ScenEdit_SetUnit({guid=unit.guid,outofcomms=true})
end
end
Code: Select all
units = VP_GetSide({side='USSR'}).units
print(units)
if(string.find(units.name, "Comm"))
or units.subtype = 4001
or units.subtype = 4003
or units.subtype = 4003
or units.subtype = 2002
or units.subtype = 2001
or units.subtype = 2008
or units.subtype = 3111
then
local commcenter = VP_GetUnit ({guid=unit.guid})
local units = VP_GetSide({side="USSR"}).units
for k,v in ipairs(units) do
local los = Tool_LOS(observer = v.guid, target = commcenter.guid, mode = 1, horizon = 0)
if los = "False" then
ScenEdit_SetUnit({guid.v.guid,OutOfComms="True"})
else
ScenEdut_SetUnit({guid.v.guid,OutOfComms="False"})
end
end
end