Wrecking Crew Posted August 27, 2016 Share Posted August 27, 2016 (edited) Hi, thanks for taking a look, trying to detect when clients take off. The Flag 50003 is supposed to go True on an S_EVENT_TAKEOFF. I cobbled this code from examples so there may well be something wrong, but it is not throwing errors, testing it in Single Player DCS v1.5.4. I did try different means for setting Flag 50003 to True and 1, and using just 'F-15C 01' for the player name but no joy. Appreciate any help. do local function detectClient(event) if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then local airborneUnit = event.initiator if(Unit.getPlayerName(airborneUnit) == {'F-15C 01', 'F-15C 02', 'F-15C 03', 'F-15C 04','M-2000C 21', 'M-2000C 22', 'M-2000C 23', 'M-2000C 24'}) then trigger.setUserFlag(50003, 1) end end end mist.addEventHandler(detectClient) end The Player names are in the 'Pilot' field for the Client a/c. Edited August 27, 2016 by Wrecking Crew Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Rakuzard Posted August 27, 2016 Share Posted August 27, 2016 (edited) if(Unit.getPlayerName(airborneUnit) == {'F-15C 01', 'F-15C 02', 'F-15C 03', 'F-15C 04','M-2000C 21', 'M-2000C 22', 'M-2000C 23', 'M-2000C 24'}) Unit.getPlayerName returns only a string, not a table. This condition won't ever be true. :) Something like this maybe: do local function detectClient(event) local function contains(tbl, val) for _,v in ipairs(tbl) do if v == val then return true end end return false end if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then local airborneUnit = event.initiator if(contains({'F-15C 01', 'F-15C 02', 'F-15C 03', 'F-15C 04','M-2000C 21', 'M-2000C 22', 'M-2000C 23', 'M-2000C 24'}, Unit.getPlayerName(airborneUnit))) then trigger.setUserFlag(50003, 1) end end end mist.addEventHandler(detectClient) end Edited August 27, 2016 by Rakuzard - Deutsche Tutorials und DCS Gameplay: youtube.com/Rakuzard | raku.yt/discord - Link to comment Share on other sites More sharing options...
Wrecking Crew Posted August 27, 2016 Author Share Posted August 27, 2016 Thanks, had high hopes this would do it. Once this works I will be able to do lots more. This did not work for player F-15C 01 in Single Player test: do local function detectClient(event) local function contains(tbl, val) for _,v in ipairs(tbl) do if v == val then return true end end return false end if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then local airborneUnit = event.initiator if(contains({'F-15C 01', 'F-15C 02', 'F-15C 03', 'F-15C 04','M-2000C 21', 'M-2000C 22', 'M-2000C 23', 'M-2000C 24'}, Unit.getPlayerName(airborneUnit))) then trigger.setUserFlag(50003, 1) end end end mist.addEventHandler(detectClient) end The mission is attached. The event is the 4th one down, 'mist.detectClient' The help is appreciated. :beer: Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Wrecking Crew Posted August 27, 2016 Author Share Posted August 27, 2016 Do the number of spaces/tab vs spaces make a difference between working code and not? There are two spaces in the function 'contains' instead of one. Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Wrecking Crew Posted August 28, 2016 Author Share Posted August 28, 2016 Making progress, this code detects the take off of the F-15C and sets the flag and outputs the text but when I quit the mission the following error appears. Why this error? do local function detectClient(event) local airborneUnitName = event.initiator:getName() if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then trigger.action.setUserFlag(50003, true) trigger.action.outText(airborneUnitName .. ' just tookoff!', 5) end end mist.addEventHandler(detectClient) end Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Yukari Posted August 28, 2016 Share Posted August 28, 2016 (edited) do local function detectClient(event) local airborneUnitName = event.initiator:getName() if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then trigger.action.setUserFlag(50003, true) trigger.action.outText(airborneUnitName .. ' just tookoff!', 5) end end mist.addEventHandler(detectClient) end When you quit the mission an event is triggered(S_EVENT_MISSION_END) as well Event = { id = 12, time = Time, } this event, however, does no have an "initiator". In your code you did local airborneUnitName = event.initiator:getName() before the if clause. Try to simply place this line into the "if" do local function detectClient(event) if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then local airborneUnitName = event.initiator:getName() trigger.action.setUserFlag(50003, true) trigger.action.outText(airborneUnitName .. ' just tookoff!', 5) end end mist.addEventHandler(detectClient) end so that when you quit a mission, an event is triggered and event handler does your function. It goes to the if, only to find that the event is not a takeoff event; then it stops there and leaves no scripting error Edited August 28, 2016 by Yukari typo Nooooooooo Link to comment Share on other sites More sharing options...
Wrecking Crew Posted August 28, 2016 Author Share Posted August 28, 2016 Makes perfect sense -- that solved the error, thank you! Now to extend the logic to detect the takeoff of specific a/c who are Clients... Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Wrecking Crew Posted August 28, 2016 Author Share Posted August 28, 2016 Got it! Thank you guys. Here is the tested code and simple mission. The outText line is only for testing. do local function detectClientTakeoff(event) local function contains(tbl, val) for _,v in ipairs(tbl) do if v == val then return true end end return false end if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then local airborneUnitName = event.initiator:getName() trigger.action.outText(airborneUnitName .. ' just tookoff!', 5) if(contains({'F-15C 01', 'F-15C 02', 'F-15C 03', 'F-15C 04', 'M-2000C 21', 'M-2000C 22', 'M-2000C 23', 'M-2000C 24'}, airborneUnitName)) then trigger.action.setUserFlag(50003, true) end end end mist.addEventHandler(detectClientTakeoff) end Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site. Link to comment Share on other sites More sharing options...
Recommended Posts