Jump to content

Recommended Posts

Posted

Hi I was wondering if there was a script that I could use in a trigger. If AWACS detects a unit then I could play a sound or message. Any ideas?

-----------------------------------------------

Intel® Core™i7 Quad Core Processor i7-6700 (3.4GHz) 8MB Cache | 32GB HyperX FURY DDR4 2133MHz | MSI GeForce RTX 2070 ARMOR 8G |SSD 1TB 970 EVO Plus M.2

Posted (edited)

yes :

Spoiler

local awacs = Unit.getByName('your awacs unit name')
local target = Unit.getByName('your target unit name')
if awacs and awacs:isExist() == true and awacs:getLife() > 0
and target and target:isExist() == true and target:getLife() > 0 then
if Controller.isTargetDetected(awacs, target, RADAR) == true then
trigger.action.outText('AWACS has detected ' .. target:getName() .. ' with Radar.', 15)
end
end

Use it in a continuously tested trigger. In "conditions" of this trigger, you can set : flag X is true, and in "action", next to this "do script", you can add : flag X set false. This way the checking will stop when target is detected. (prior to this trigger, set another one with : flag X set true in "actions", to start the checking of target detection)

Edited by toutenglisse
added units existence check in code
Posted
12 hours ago, toutenglisse said:

yes :

  Reveal hidden contents

local awacs = Unit.getByName('your awacs unit name')
local target = Unit.getByName('your target unit name')
if Controller.isTargetDetected(awacs, target, RADAR) == true then
trigger.action.outText('Your message.', 15)
end

Use it in a continuously tested trigger. In "conditions" of this trigger, you can set : flag X is true, and in "action", next to this "do script", you can add : flag X set false. This way the checking will stop when target is detected. (prior to this trigger, set another one with : flag X set true in "actions", to start the checking of target detection)

 

I have used this to great success, but is there a way to make it query four aircraft and still work without an error if only 2 or 3 aircraft show up? 
Thanks in advance. 

Posted
5 hours ago, ShadowFrost said:

I have used this to great success, but is there a way to make it query four aircraft and still work without an error if only 2 or 3 aircraft show up? 
Thanks in advance. 

 

Yes - you can use this code in a "do script", in a trigger "once", "conditions" Time > 1 : (to declare awacs and targets)

Spoiler

awacs = Unit.getByName('your awacs unit name')
target = {}
target[1] = Unit.getByName('your target1 unit name')
target[2] = Unit.getByName('your target2 unit name')
target[3] = Unit.getByName('your target3 unit name')
target[4] = Unit.getByName('your target4 unit name')
trigger.action.setUserFlag( "1", false )
trigger.action.setUserFlag( "2", false )
trigger.action.setUserFlag( "3", false )
trigger.action.setUserFlag( "4", false )

and then use this code in a "do script", in a "continuously tested" trigger, "conditions" Time > 2 : (to check radar detection for each target, and stop checking when detected)

Spoiler

if awacs and awacs:isExist() == true and awacs:getLife() > 0 then
for j = 1, #target do
if target[j] and target[j]:isExist() == true and target[j]:getLife() > 0
and trigger.misc.getUserFlag( "" .. j ) == 0 then
if Controller.isTargetDetected(awacs, target[j], RADAR) == true then
trigger.action.outText('AWACS has detected ' .. target[j]:getName() .. ' with Radar.', 15)
trigger.action.setUserFlag( "" .. j, true )
end
end
end
end

 

  • Recently Browsing   0 members

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