Managing Comms based on LOS

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
kahta
Posts: 562
Joined: Sat Sep 21, 2019 6:42 pm
Location: Arkansas

Managing Comms based on LOS

Post by kahta »

I am trying to create a lua script that will put a unit out of comms if it is not within LOS of a comm/comms facility.

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
This is what I wrote up and is (obviously) not working. If anyone has suggestions on how to make something like this work, I would appreciate it!

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



Post Reply

Return to “Lua Legion”