Jump to content

DCS get table of all units in lua (using MIST)


Nilusink

Recommended Posts

I don't know if this is the right place to ask, but I've tried to create a small script that explodes all planes that are not inside a specific zone. The only problem that I have is that I can't get a table of DCS units.

 

do
    trigger.action.outText("loop ", .5, false)
    net.log("loop")
    local ZONE_NAME = "Zone"

    local allUnits = mist.makeUnitTable({'[plane]'})
    local unitsInsideZone = mist.getUnitsInZones(allUnits, ZONE_NAME)

    -- check all units are inside zone
    for _, unit in pairs(allUnits) do
        trigger.action.outText("checking "..unit:getName(), 2, false)
    end
end

I tried this, but DCS gives me the error

Quote

attempted to call field 'getName' (a nil value)

at line `trigger.action.outText("checking "..unit:getName(), 2, false)`.

After further investigation I found out that `unit` seems to be a string value. I tried searching on different forums, but they all say that this should work. The mist documentation even gives me this exact line:

do
	local units = mist.makeUnitTable({'[all]'}, 'static')
end

I don't know what I'm doing wrong.

 

 

Edit

I got it working by 'borrowing' some code from Outofmyzone:

enemyPlanes = mist.makeUnitTable({'[all][planes]'})
InZone = mist.getUnitsInZones(enemyPlanes, {zone})
for i = 1, #enemyPlanes do
  uName = enemyPlanes[i]
  unit = Unit.getByName(uName)
end

 


Edited by Nilusink
Link to comment
Share on other sites

Hi

Right place to ask is here : https://forum.dcs.world/forum/1160-scripting-tips-tricks-issues/

😀

Use this example :

local u = mist.getUnitsInZones(mist.makeUnitTable({'[all]'}), {'KutaisiBattle'})

   for i = 1, #u do

	   local _uName = Unit.getName(u[i])
	   trigger.action.outText("checking ".. _uName, 2, false)

   end

Se here : https://wiki.hoggitworld.com/view/MIST_getUnitsInZones

 

 


Edited by Kanelbolle
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...