normre14232 Posted August 28, 2019 Posted August 28, 2019 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
Habu_69 Posted August 28, 2019 Posted August 28, 2019 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.
normre14232 Posted August 28, 2019 Author Posted August 28, 2019 Thanks for the heads up. Made the change as suggested. Still must be missing something....
funkyfranky Posted August 28, 2019 Posted August 28, 2019 You have that script in a scheduler function and call it every X seconds? If not, it is only executed once and if at that time, the target is not detected, the flag will never be raised. A warrior's mission is to foster the success of others. i9-12900K | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3 RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
normre14232 Posted August 28, 2019 Author Posted August 28, 2019 Ha....thanks that was it. Don't really know how to write a scheduler, so I put a DO SCRIPT FILE on a continuous action trigger and it worked. Thank you!!
normre14232 Posted August 28, 2019 Author Posted August 28, 2019 Oops....maybe not. Seems like the flag is always true now....
Hardcard Posted August 28, 2019 Posted August 28, 2019 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) [sIGPIC][/sIGPIC]
normre14232 Posted August 28, 2019 Author Posted August 28, 2019 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.
normre14232 Posted August 28, 2019 Author Posted August 28, 2019 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....
normre14232 Posted August 30, 2019 Author Posted August 30, 2019 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)
Grimes Posted August 31, 2019 Posted August 31, 2019 Glad non Grimes people were able to help. :thumbup: The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Recommended Posts