Jump to content

Recommended Posts

Posted

Ok,

 

Clearly I don't really understand lua, cuz I am pulling my hair out with this one.

 

I simply want to see if group "RED1" detects the group "player" via RWR. The script doesn't crash but it also doesn't seem to work as the flag never gets triggered

 

Thanks in advance,

 

local target = Group.getByName('player')

if Group.getByName('RED1'):getController():isTargetDetected(target, 'RWR') == true then

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

end

Posted

This may not fully address your issue, BUT I have had issues setting user flags to boolean values. True usually == 1, but not always, it seems. Much more reliable to set flags to numeric values.

Posted

That flag will keep the last given value, so yup, it'll stay true unless you reset it.

 

Here, you're looking for something like this:

 

local function Scheduler_Function()
     
     local target = Group.getByName('player')
     
     if Group.getByName('RED1'):getController():isTargetDetected(target, 'RWR') == true then
        
        trigger.action.setUserFlag("1", true)
     
     elseif Group.getByName('RED1'):getController():isTargetDetected(target, 'RWR') ~= true then
            
            trigger.action.setUserFlag("1", 0)
     end

  return timer.getTime() + 5

end 

timer.scheduleFunction(Scheduler_Function, nil, timer.getTime() + 5)

Posted

Thanks very much....it helps a lot to see the scheduler in context. So I could basically put any code in between the local function and the return and it would run on a schedule. Very Cool.

Posted

Also a note for other that might be interested.....function only works with UNITS is you want to check detection of aircraft. If you call GROUPS is will only work for ships and ground vehicles. Just FYI....

Posted

So kinda proud of myself....fleshed out the code a bit....boy has this been a learning experience. I think the final result is pretty cool.

 

Script test to see if any blue aircraft can be detected by a radar unit. Then increments a variable that can be used to simulate "burn thru".

 

Thanks to all the replies for your help. I'll post below for comments, suggestions, flames, etc. BTW it does require mist, as I had of use a couple of it's functions

 

 

 

trigger.action.outText("NHR Radar Detection Script Active",10)

 

local radarscore = 0

 

 

local function Scheduler_Function()

 

local tracked = false

local targettable = mist.makeUnitTable({'[blue][plane]'})

 

 

for i = 1 , #targettable do

 

local target = Unit.getByName(targettable)

 

if Unit.getByName('EW'):getController():isTargetDetected(target, 'RADAR') == true then

 

tracked = true

 

elseif Unit.getByName('EW'):getController():isTargetDetected(target, 'RADAR') ~= true then

 

trigger.action.setUserFlag("100", radarscore)

 

end

 

end

 

if tracked == true then

radarscore = radarscore + 1

trigger.action.setUserFlag("100", radarscore)

--trigger.action.outText(radarscore,10)

end

 

return timer.getTime() + 5

 

end

 

timer.scheduleFunction(Scheduler_Function, nil, timer.getTime() + 5)

  • Recently Browsing   0 members

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