Jump to content

Does anyone have a script that writes out flag values?


Recommended Posts

Posted (edited)

When testing missions it would be a very big help to be able to just add a script at mission start that would write the flag values as messenges when they occur. To test that triggers are working as planned. To do this now I have to manually add a trigger for this for each flag and each value of the flag, this is a MASSIVE task just to test the mission.

 

Does anyone have a script that writes out flag values? I would be very thankfull.

 

Skickat från min D5503 via Tapatalk

Edited by NineLine
Posted (edited)

I do that with this sentence, for example to display Flag 101:

 

trigger.action.outText( 'Flag 101: ' .. trigger.misc.getUserFlag ( '101' ), 10 )

 

The 10 is the seconds that the message will be displayed.

Edited by Rudel_chw
  • Thanks 1

 

For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra

For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar

Mobile: iPad Pro 12.9" of 256 GB

Posted

Yes, but you can put it into any action, not just mission start.

 

For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra

For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar

Mobile: iPad Pro 12.9" of 256 GB

Posted (edited)

Ok i misunderstood then (read to fast). I guess this had to be set up for every individual flag then. I guess with a switched condition or continus action and condition time since flag 101 1 second I could get it to display the value for flag 101 every time it changes. It would be a step forward.

 

Wonder if it can be tweaked so that it writes any flags value then the value changes unregarded of what event that changed it.

 

Skickat från min D5503 via Tapatalk

Edited by Fisherman82
Posted (edited)

@Fisherman82

 

I created a demo mission + script which includes a real time flag monitoring routine.

 

A Mirage2000C will climb up to 5000+ meters and then RTB. I've set up 6 flags in the mission, which will be enabled/disabled depending on the plane's altitude.

You'll get a "permanent" text message, showing the state of all flags as the plane climbs/dives.

When the plane lands, the routine will be automatically stopped.

 

Here's the script:

 

 

 

local Mirage = Unit.getByName("Mirage")

 

local function FlagTest(Mirage,time)

 

local FlagTable = {

Flag_100 = trigger.misc.getUserFlag ( '100' ), --'100' is the name of the flag in ME

Flag_1000 = trigger.misc.getUserFlag ( '1000' ), --'1000' is the name of the flag in ME

Flag_2000 = trigger.misc.getUserFlag ( '2000' ), --'2000' is the name of the flag in ME

Flag_3000 = trigger.misc.getUserFlag ( '3000' ), --'3000' is the name of the flag in ME

Flag_4000 = trigger.misc.getUserFlag ( '4000' ), --'4000' is the name of the flag in ME

Flag_5000 = trigger.misc.getUserFlag ( '5000' ) --'5000' is the name of the flag in ME

 

-- If you want to include extra flags, just copy/paste one of these lines and change both its variable name and string value at the end, just like I did with each one of these flags

}

 

for k, v in pairs(FlagTable) -- Remove this line, it's a remnant from a previous test mission

do -- Remove this line, it's a remnant from a previous test mission

trigger.action.outText("Flag_100 value = "..FlagTable.Flag_100.."\nFlag_1000 value = "..FlagTable.Flag_1000.."\nFlag_2000 value = "..FlagTable.Flag_2000.."\nFlag_3000 value = "..

FlagTable.Flag_3000.."\nFlag_4000 value = "..FlagTable.Flag_4000.."\nFlag_5000 value = "..FlagTable.Flag_5000, 1,true) --If you want this text message to include extra flags, you'll need to add them following the same method I've used for each flag

end -- Remove this line, it's a remnant from a previous test mission

 

if Mirage:inAir() ~= false then -- This is a check that I included in order to manage the loop. When "Mirage" lands (actually, if it stops flying for whatever reason), the loop will be stopped and no further messages will be sent.

return time + 1

else

trigger.action.outText("Mirage landed!\nFlag scheduler stopped!", 10)

return nil

end

end

 

timer.scheduleFunction(FlagTest, Mirage, timer.getTime() + 1) -- Mirage is given as parameter for FlagTest function. You'll need to change this in your mission.

 

 

 

 

Now, you'll probably need to get rid of the "Mirage check" in order for this script to work in your mission. You can loop it indefinitely by doing something like this:

 

 

 

--Replace the line:

local Mirage = Unit.getByName("Mirage")

 

--With this one:

local Loop = 1

 

--Then replace the line:

local function FlagTest(Mirage,time)

 

--With this one:

local function FlagTest(Loop,time)

 

--Next, replace these lines:

if Mirage:inAir() ~= false then

return time + 1

else

trigger.action.outText("Mirage landed!\nFlag scheduler stopped!", 10)

return nil

end

end

 

--With these:

if Loop == 1 then

return time + 1

end

end

 

--Finally, replace this line:

timer.scheduleFunction(FlagTest, Mirage, timer.getTime() + 1)

 

--With this one:

timer.scheduleFunction(FlagTest, Loop, timer.getTime() + 1)

 

 

--That should do it!

 

 

 

Btw, in order to load the script in your mission, you can create a MISSION START trigger, with a DO SCRIPT FILE action

 

Attached mission + script below

Flag status message test.miz

Flag checker loop.lua

Edited by Hardcard
  • Like 1
Posted

Thank you Hardcard!

 

I tried it out, its a step closer to my vision of the script and I will most certainly use it in this shape for now.

 

I would like it to check for all flags between say 1-200, I guess that would be possible if I would get rid of the Mirage check and roll up my sleeves and enter all those flags instead of the six you had. Would be worth it because I would only have to do it in the script once and not every time I would like to test a mission with triggers in the ME. However for that number of flags I would have to get the rows of text do "roll" so that only the 6 latest changed flags are shown.

Posted (edited)

@Fisherman82

 

Sorry, I don't know of any convenient way to target flags based on value change. It can be done, I guess, but I imagine it would be pretty inconvenient.

 

I usually create flag status messages as I program each flag (this is a pretty straightforward process when scripting missions, but more of a hassle when using ME triggers).

 

The thing is that you'll never get the status of 200 flags on display at the same time, so perhaps it would be a good idea to divide them in groups of 10-20 or something like that.

Then you could create custom F10 menu commands, which would allow you to access each group of flags (something like "Show flags 1-10","Show flags 11-20", etc.)

 

I've modified the demo mission + script to incorporate these changes.

Now there's an F10 menu available for all Red coalition clients, which allows for flag status message management (it uses MOOSE, btw).

 

Here's the new script:

 

 

 

local LoopFlag = USERFLAG:New("LoopFlag") -- We'll use this flag to handle function looping

 

local function Flags_1_10(LoopFlag, time)

 

local FlagTable_1_10 = { -- This table contains flags 1 to 10

Flag_1 = trigger.misc.getUserFlag ( '1' ),

Flag_2 = trigger.misc.getUserFlag ( '2' ),

Flag_3 = trigger.misc.getUserFlag ( '3' ),

Flag_4 = trigger.misc.getUserFlag ( '4' ),

Flag_5 = trigger.misc.getUserFlag ( '5' ),

Flag_6 = trigger.misc.getUserFlag ( '6' ),

Flag_7 = trigger.misc.getUserFlag ( '7' ),

Flag_8 = trigger.misc.getUserFlag ( '8' ),

Flag_9 = trigger.misc.getUserFlag ( '9' ),

Flag_10 = trigger.misc.getUserFlag ( '10' )

}

 

trigger.action.outText("Flag_1 value = "..FlagTable_1_10.Flag_1.."\nFlag_2 value = "..FlagTable_1_10.Flag_2.."\nFlag_3 value = "..FlagTable_1_10.Flag_3..

"\nFlag_4 value = "..FlagTable_1_10.Flag_4.."\nFlag_5 value = "..FlagTable_1_10.Flag_5.."\nFlag_6 value = "..FlagTable_1_10.Flag_6.."\nFlag_7 value = "..FlagTable_1_10.Flag_7..

"\nFlag_8 value = "..FlagTable_1_10.Flag_8.."\nFlag_9 value = "..FlagTable_1_10.Flag_9.."\nFlag_10 value = "..FlagTable_1_10.Flag_10, 1,true) --This message will show the status of flags 1-10

 

if LoopFlag:Is(1) then -- As long as LoopFlag is 1, Flags_1_10 function will keep looping

return time + 1

else

return nil

end

end

 

local function Flags_1_10_Call() --This function is called by the coalition menu command Flag_1_10_Command, located towards the bottom of the script

LoopFlag:Set(1) -- We set LoopFlag to 1, to enable the looping of Flags_1_10 function, which we'll call in the line below

timer.scheduleFunction(Flags_1_10, LoopFlag, timer.getTime() + 1) --This will keep calling Flags_1_10 function for as long as LoopFlag is set to 1

end

 

 

local function Flags_11_20(LoopFlag, time)

 

local FlagTable_11_20 = { -- This table contains flags 11 to 20

Flag_11 = trigger.misc.getUserFlag ( '11' ),

Flag_12 = trigger.misc.getUserFlag ( '12' ),

Flag_13 = trigger.misc.getUserFlag ( '13' ),

Flag_14 = trigger.misc.getUserFlag ( '14' ),

Flag_15 = trigger.misc.getUserFlag ( '15' ),

Flag_16 = trigger.misc.getUserFlag ( '16' ),

Flag_17 = trigger.misc.getUserFlag ( '17' ),

Flag_18 = trigger.misc.getUserFlag ( '18' ),

Flag_19 = trigger.misc.getUserFlag ( '19' ),

Flag_20 = trigger.misc.getUserFlag ( '20' )

}

 

trigger.action.outText("Flag_11 value = "..FlagTable_11_20.Flag_11.."\nFlag_12 value = "..FlagTable_11_20.Flag_12.."\nFlag_13 value = "..FlagTable_11_20.Flag_13..

"\nFlag_14 value = "..FlagTable_11_20.Flag_14.."\nFlag_15 value = "..FlagTable_11_20.Flag_15.."\nFlag_16 value = "..FlagTable_11_20.Flag_16.."\nFlag_17 value = "..FlagTable_11_20.Flag_17..

"\nFlag_18 value = "..FlagTable_11_20.Flag_18.."\nFlag_19 value = "..FlagTable_11_20.Flag_19.."\nFlag_20 value = "..FlagTable_11_20.Flag_20, 1,true) --This message will show the status of flags 11-20

 

 

if LoopFlag:Is(2) then -- As long as LoopFlag is 2, Flags_11_20 function will keep looping

return time + 1

else

return nil

end

end

 

local function Flags_11_20_Call() --This function is called by the coalition menu command Flag_11_20_Command, located towards the bottom of the script

LoopFlag:Set(2) -- We set LoopFlag to 2, to enable the looping of Flags_11_20 function, which we'll call in the line below

timer.scheduleFunction(Flags_11_20, LoopFlag, timer.getTime() + 1) --This will keep calling Flags_11_20 function for as long as LoopFlag is set to 2

end

 

local function Flag_Stop() --This function is called by the coalition menu command Flag_Stop_Command, located at the end of the script

LoopFlag:Set(666) -- We set LoopFlag to 666, so the :devil_2: stops all loops (no further messages will be sent)

end

 

local Flag_Menu_Root_I = MENU_COALITION:New(coalition.side.RED,"Flag groups I and II") --Red coalition F10 root menu for flag groups I and II (flags 1-10 and 11-20)

local Flag_1_10_Command = MENU_COALITION_COMMAND:New( coalition.side.RED, "Flag group I (1 - 10)", Flag_Menu_Root_I, Flags_1_10_Call) --Red coalition F10 submenu command, responsible for calling Flags_1_10_Call function

local Flag_11_20_Command = MENU_COALITION_COMMAND:New( coalition.side.RED, "Flag group II (11 - 20)", Flag_Menu_Root_I, Flags_11_20_Call) --Red coalition F10 submenu command, responsible for calling Flags_11_20_Call function

local Flag_Stop_Command = MENU_COALITION_COMMAND:New( coalition.side.RED, "Stop flag messages!", Flag_Menu_Root_I, Flag_Stop) --Red coalition F10 submenu command, responsible for calling Flag_Stop function

 

 

 

Now, there are a few things to consider:

 

- In order for this script to work with your mission, you'll need to run Moose.lua with a MISSION START trigger

 

- Flags 7-10 will be enabled when the Mirage reaches an altitude of 5000+ meters. Flags 11-20 will be enabled when the Mirage lands.

 

- Since I didn't feel like setting up my HOTAS, I used a red igla manpad as "client" in the attached test mission (Combined Arms module is required for players to take control of this unit).

This igla manpad "hermit" is located on top of Mount Elbrus, it'll allow you to access the custom F10 menu once you take control of it.

If you don't own Combined Arms, simply add any flyable red aircraft that you want, that way you'll be able to access the custom F10 menu (I guess I should've done that, but I wanted a hermit flagmaster on Mount Elbrus :D).

 

- In order to avoid this sort of problems/nuances, I recommend that you learn basic scripting. :book:

 

 

EDIT: I noticed that the script was still using iterators from a previous test version, I've removed them since they aren't needed. I've uploaded the corrected test mission + script

Flag status message test (F10 menu + MOOSE, no iterator).miz

Flag checker loop (no pairs test).lua

Edited by Hardcard
  • Recently Browsing   0 members

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