Jump to content

Recommended Posts

Posted

Hi,

 

I'm very new at LUA scripting and I've been struggling with this one, which should be really basic but I'm not really sure how to start:

I'd like to have a trigger zone trigger this script when another unit or part of coalition enters the area: then I'd like the script to display the range/bearing/altitude(or altitude difference) of the unit just entered the circle.

Could perhaps anyone give me any clues how to start?

 

I'm kind of stuck at how to get my own position, the other group's position and altitude - I know it must be trivial, but I couldn't figure it out yet.

Thanks a lot!

Posted (edited)

Hi, here is an exemple of functions I use in a script (dcs + mist functions) so you can adapt to your need :

 

here a function to get bearing range, here for ground units but it's same for aircraft :

(usage : my aircraft reach a 25km radius zone around outpost to defend - triggers enemy group to move to attack outpost, check destruction of both groups, and display a message with bearing range of enemy group, with outpost as reference, but reference can be bullseye or your aircraft position)

 

function DOStart(zoneName)

 

mist.flagFunc.units_in_moving_zones({

units = {'Blue F18c 3-1'},

zone_units = {'Red Target Group Unit 1'},

flag = "4",

radius = 25000,

})

 

if trigger.misc.getUserFlag("4") > 0 then

groupAliveCheckTask9ID = mist.scheduleFunction(MA_groundGroupAliveCheck9,{},timer.getTime()+30)

BlueAmbushRouteID = mist.scheduleFunction(BlueAmbushRoute,{'GameZone'}, timer.getTime() + 1, 60, timer.getTime() + 1800)

local avgPos = mist.getLeadPos('Blue Target Group')

local ref = mist.getLeadPos('Red Target Group')

local vec = {x = avgPos.x - ref.x, y =avgPos.y - ref.y, z = avgPos.z - ref.z}

local dir = mist.utils.round(mist.utils.toDegree(mist.utils.getDir(vec, ref)), 0)

local dist = mist.utils.get2DDist(avgPos, ref)

local distMetric = mist.utils.round(dist/1000, 0)

local distImperial = mist.utils.round(mist.utils.metersToNM(dist), 0)

dir = string.format('%03d', dir)

trigger.action.outText('Beware : Enemy vehicles are attacking from bearing : ' .. dir .. ' and distance : ' .. distMetric .. 'km/' .. distImperial .. 'nm from our Outpost.', 15)

trigger.action.setUserFlag( "7", true )

else

DOStartID = mist.scheduleFunction(DOStart,{aoName},timer.getTime()+30)

end

 

end

 

To get altitude here an exemple :

 

local latitude, longitude, altitude = coord.LOtoLL(mist.getLeadPos('Blue F18c 3'))

 

To display altitude of 'Blue F18c 3', just insert altitude in a message (like : trigger.action.outText('altitude of Blue F18c 3 is :' .. altitude .. ' meters high.', 15) or in the same message already giving bearing/range.

Edited by toutenglisse
typo
Posted

If you wish to use scripting for creating DCS missions, I highly recommend using the Moose scripting environment, due to its powerful methods and ongoing development. Following is a Moose script to accomplish most of what you want:

 

 

From_Grp = UNIT:FindByName( "B17" )   -- Instantiate units of interest
To_Grp = UNIT:FindByName( "P51" )  -- GROUP instead of UNIT works also

SCHEDULER:New( nil, 
 function()

     To_GrpCoord = To_Grp:GetCoordinate()  -- Get To_Grp group coordinate
     From_GrpCoord = From_Grp:GetCoordinate()  
     To_GrpDist = From_GrpCoord:Get2DDistance( To_GrpCoord )  -- Returns distance in meters   

   if To_GrpDist <= 14000 then  -- Optional message conditions. 14000 m ~ 7.2 NM 

     To_GrpBR = To_GrpCoord:ToStringBR( From_GrpCoord, _SETTINGS:SetImperial() )
     WelcomeMsg = "Colt 1, Springfield 3. Visual, bearing ".. To_GrpBR

     MessageTo_Grp = MESSAGE:New( WelcomeMsg, 15, nil ):ToAll()
     Scheduler:Stop()
   end
               
 end, {}, 1, 1  -- Freq must be high to get accurate BR message
 )

 

 

You can easily add the altitude function and replace

To_GrpDist <= 14000

with GroupInZone. This script stops the scheduler after the first message, but you may wish to make modifications to send subsequent messages when other groups enter the zone.

Posted

Thanks a lot guys, I've got the bearing/distance bit sorted out nicely.

 

Now I'm trying to find a way to get the name of ANY unit entering a moving zone - ie. I'd run the script every 15 seconds or so checking if there's any unit inside the moving zone.

Does MOOSE or MIST have a function/way to do this?

 

So far I've managed without, but I'm willing to use it if it makes it easier :)

Posted (edited)

Thanks, I'm trying with MIST now, but can't really get the names of units out of the table inZone, I keep getting errors and it seems like it is populated with the right amount of entries(2).

 

local units = mist.makeUnitTable({'[blue][plane]', '[blue][helicopter]'})

local zone_unit_names = mist.makeUnitTable({'[g]group_1'}); -- get the unit name which has the trigger zone attached ie. PLAYER

local inZone = mist.getUnitsInMovingZones(units, zone_unit_names, 9260, 'sphere') -- table of units INSIDE the zone, RANGE METERS!!!

for i = 1, #inZone do -- iterate units

trigger.action.outText('Checking ' ..i, 10)

local name = inZone.units

trigger.action.outText('Checking unit ' ..name, 10)

end

 

I've also tried with

local u = Unit.getByName(inZone)

local name=u:getName() -- get unit's NAME

instead of the

local name = inZone.units
bit, but no joy... Edited by Jagohu
Posted

It seems like MIST only gives you the number of aircraft inside the zone, or at least I couldn't get anything else out of the table.

Anyhow, problem is solved now, I have programmed it perhaps a less elegant, but at least a working way :)

Thanks for all the advices!

  • Recently Browsing   0 members

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