Jump to content

Nested submenu that activates triggers


TonyG

Recommended Posts

I’ve looked through these forums, hoggit and the Menu commands in Moose, and I can’t seem to get anything working for a nested menu to activate triggers.

 

I’m looking for something that can activates SAMs on a training range for our squadron to practice HARMs. These would be in as late activated units.

 

For example:

 

SAM Range (main menu)

—> Activate SA-2 (flag 1 on)

—> Activate SA-6 (flag 2 on)

—> Activate SA-15 (flag 3 on)

 

If it’s better to direct spawn units from the menu as opposed to do it via flags that makes sense, but I’m having a hard time just getting the sub menu to work properly.

 

Thanks in advance for any suggestions you make or pointing me in the right direction.


Edited by TonyG
Link to comment
Share on other sites

You can only create sub menus with the scripting engine.

https://wiki.hoggitworld.com/view/DCS_func_addSubMenu

 

local function setFlag(val)
trigger.action.setUserFlag(val.flag, true)

end

local main= missionCommands.addSubMenu(SAM Range')
local sa2Menu= missionCommands.addCommand('SA-2', main, setFlag, {flag= 1})
local sa6Menu= missionCommands.addCommand('SA-6', main, setFlag, {flag= 2})
local sa15Menu= missionCommands.addCommand('SA-15', main, setFlag, {flag= 3})

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

@TonyG

 

Here you'll find one of my "old" MOOSE test missions.

 

Several things in the mission are handled via nested F10 menus (smoke units, open fire, hold fire, call in a helicopter/bomber/naval strike, etc.), all AI groups in the mission are late activated.

 

The beauty of this demo mission is that you can switch between client groups as much as you like, you'll always get the nested F10 menus for each group (sometimes they'll take a few seconds to appear, though).

Automatic menu removal is also implemented in the mission, iirc.

 

The mission uses a couple of rather long scripts (two versions of the same script, one for each coalition), which I wrote several months ago (my scripting skills weren't great back then, so you might find silly stuff in there :D)

You'll find the nested F10 group menus/commands towards the end of the scripts.

 

Anyway, I think this demo mission is a decent example of how to orchestrate stuff using nested F10 menus for different clients.

 

Now, in order to get everything started, you'll need to run "Zone Detection Test Menu" via F10 menu after entering any of the clients.

Next, keep flying straight until you enter the mission zone, then you'll get all the juicy F10 menu structure (I recommend helicopter and naval strikes, they're fun ;) ).


Edited by Hardcard
Link to comment
Share on other sites

Thanks Hardcard, I'll take a look at that. I'm not a genius by any stretch with lua, but the more I see, the more it makes sense. I appreciate you guys taking the time to help out a newbie on some of this basic stuff.

 

 

 

This is what I wound up with, and it works perfect. First bunch is the nested menus, and the spawning is the rest. I'm sure there's a more elegant way to code it, but it works and that's awesome!

 

local function setFlag(val)
trigger.action.setUserFlag(val.flag, true)

end

local main= missionCommands.addSubMenu('AA Range 1v')
local f4Menu= missionCommands.addCommand('F-4', main, setFlag, {flag= 101})
local f5Menu= missionCommands.addCommand('F-5', main, setFlag, {flag= 102})
local f15Menu= missionCommands.addCommand('F-15', main, setFlag, {flag= 103})
local f16enu= missionCommands.addCommand('F-16', main, setFlag, {flag= 104})
local m23Menu= missionCommands.addCommand('Mig21', main, setFlag, {flag= 105})
local m29Menu= missionCommands.addCommand('Mig29', main, setFlag, {flag= 106})

local function setFlag(val)
trigger.action.setUserFlag(val.flag, true)

end

local main= missionCommands.addSubMenu('AA Range 2v')
local f4Menu= missionCommands.addCommand('2 F-4', main, setFlag, {flag= 201})
local f5Menu= missionCommands.addCommand('2 F-5', main, setFlag, {flag= 202})
local f15Menu= missionCommands.addCommand('2 F-15', main, setFlag, {flag= 203})
local f16enu= missionCommands.addCommand('2 F-16', main, setFlag, {flag= 204})
local m23Menu= missionCommands.addCommand('2 Mig21', main, setFlag, {flag= 205})
local m29Menu= missionCommands.addCommand('2 Mig29', main, setFlag, {flag= 206})


local function setFlag(val)
trigger.action.setUserFlag(val.flag, true)

end

local main= missionCommands.addSubMenu('SAM Range On')
local sa2Menu= missionCommands.addCommand('SA-2', main, setFlag, {flag= 301})
local sa6Menu= missionCommands.addCommand('SA-6', main, setFlag, {flag= 302})
local sa8Menu= missionCommands.addCommand('SA-8', main, setFlag, {flag= 303})
local sa10Menu= missionCommands.addCommand('SA-10', main, setFlag, {flag= 304})
local sa11Menu= missionCommands.addCommand('SA-11', main, setFlag, {flag= 305})
 local sa15Menu= missionCommands.addCommand('SA-15', main, setFlag, {flag= 306})

and

 

if trigger.misc.getUserFlag( '101' ) == 1 then  -- ME trigger action flag 101
 SpawnREDF4 = SPAWN:New( "REDF-4" )
 SpawnREDF4_Group = SpawnREDF4:Spawn()
 trigger.action.setUserFlag('101',false)
 end
 
if trigger.misc.getUserFlag( '102' ) == 1 then  -- ME trigger action flag 102
 SpawnREDF5 = SPAWN:New( "REDF-5" )
 SpawnREDF5_Group = SpawnREDF5:Spawn()
 trigger.action.setUserFlag('102',false)
end

if trigger.misc.getUserFlag( '103' ) == 1 then  -- ME trigger action flag 103
 SpawnREDF15 = SPAWN:New( "REDF-15" )
 SpawnREDF15_Group = SpawnREDF15:Spawn()
 trigger.action.setUserFlag('103',false)
end

if trigger.misc.getUserFlag( '104' ) == 1 then  -- ME trigger action flag 104
 SpawnREDF16 = SPAWN:New( "REDF-16" )
 SpawnREDF16_Group = SpawnREDF16:Spawn()
 trigger.action.setUserFlag('104', false)
end

if trigger.misc.getUserFlag( '105' ) == 1 then  -- ME trigger action flag 105
 SpawnREDMig21 = SPAWN:New( "REDMig21" )
 SpawnREDMig21_Group = SpawnREDMig21:Spawn()
 trigger.action.setUserFlag('105', false)
end

if trigger.misc.getUserFlag( '106' ) == 1 then  -- ME trigger action flag 106
 SpawnREDMig29 = SPAWN:New( "REDMig29" )
 SpawnREDMig29_Group = SpawnREDMig29:Spawn()
 trigger.action.setUserFlag('106',false)
end

if trigger.misc.getUserFlag( '201' ) == 1 then  -- ME trigger action flag 201
 Spawn2VF4 = SPAWN:New( "2vF-4" )
 Spawn2VF4_Group = Spawn2VF4:Spawn()
 trigger.action.setUserFlag('201',false)
end
 
if trigger.misc.getUserFlag( '202' ) == 1 then  -- ME trigger action flag 202
 Spawn2VF5 = SPAWN:New( "2vF-5" )
 Spawn2VF5_Group = Spawn2VF5:Spawn()
 trigger.action.setUserFlag('202',false)
end

if trigger.misc.getUserFlag( '203' ) == 1 then  -- ME trigger action flag 203
 Spawn2VF15 = SPAWN:New( "2vF-15" )
 Spawn2VF15_Group = Spawn2VF15:Spawn()
 trigger.action.setUserFlag('203',false)
end

if trigger.misc.getUserFlag( '204' ) == 1 then  -- ME trigger action flag 204
 Spawn2VF16 = SPAWN:New( "2vF-16" )
 Spawn2VF16_Group = Spawn2VF16:Spawn()
 trigger.action.setUserFlag('204', false)
end

if trigger.misc.getUserFlag( '205' ) == 1 then  -- ME trigger action flag 205
 Spawn2VMig21 = SPAWN:New( "2vMig21" )
 Spawn2VMig21_Group = Spawn2VMig21:Spawn()
 trigger.action.setUserFlag('205', false)
end

if trigger.misc.getUserFlag( '206' ) == 1 then  -- ME trigger action flag 206
 Spawn2VMig29 = SPAWN:New( "2vMig29" )
 Spawn2VMig29_Group = Spawn2VMig29:Spawn()
 trigger.action.setUserFlag('206',false)
end

if trigger.misc.getUserFlag( '301' ) == 1 then  -- ME trigger action flag 301
 SpawnSA2 = SPAWN:New( "SA-2" )
 SpawnSA2_Group = SpawnSA2:Spawn()
 trigger.action.setUserFlag('301',false)
end

if trigger.misc.getUserFlag( '302' ) == 1 then  -- ME trigger action flag 302
 SpawnSA6 = SPAWN:New( "SA-6" )
 SpawnSA6_Group = SpawnSA6:Spawn()
 trigger.action.setUserFlag('302',false)
end

if trigger.misc.getUserFlag( '303' ) == 1 then  -- ME trigger action flag 303
 SpawnSA8 = SPAWN:New( "SA-8" )
 SpawnSA8_Group = SpawnSA8:Spawn()
 trigger.action.setUserFlag('303',false)
end

if trigger.misc.getUserFlag( '304' ) == 1 then  -- ME trigger action flag 304
 SpawnSA10 = SPAWN:New( "SA-10" )
 SpawnSA10_Group = SpawnSA10:Spawn()
 trigger.action.setUserFlag('304',false)
end

if trigger.misc.getUserFlag( '305' ) == 1 then  -- ME trigger action flag 305
 SpawnSA11 = SPAWN:New( "SA-11" )
 SpawnSA11_Group = SpawnSA11:Spawn()
 trigger.action.setUserFlag('205',false)
end

if trigger.misc.getUserFlag( '306' ) == 1 then  -- ME trigger action flag 306
 SpawnSA15 = SPAWN:New( "SA-15" )
 SpawnSA15_Group = SpawnSA15:Spawn()
 trigger.action.setUserFlag('306',false)
end

Link to comment
Share on other sites

I added the Wrench Carrier Script to the mission that had this, and the F10 menu doesn’t seem to function in multiplayer, though I see it on my host computer. My client computer doesn’t see the menu.

 

I’ve read through the forums and seen some issues in the past with F10 radio menus and multiplayer, and I’ve seen some issues while integrating the CTLD script with the Alerax LSO script, where one or both would stop responding to commands, but nothing like the menus just not showing up.

 

Any thoughts from the brain trust here why that would affect things like that?

Link to comment
Share on other sites

What I do is map the menu entries to functions, that contain all the assets required to make that menu entry work.

 

This way it's very clean code, it's all self-contained and modular, and performant, because everything can be local inside the function, and nothing's alive on the map unless it's requested.

 

Banner EDForum2020.jpg

Have fun. Don't suck. Kill bad guys. 👍

https://discord.gg/blacksharkden/

Link to comment
Share on other sites

What I do is map the menu entries to functions, that contain all the assets required to make that menu entry work.

 

This way it's very clean code, it's all self-contained and modular, and performant, because everything can be local inside the function, and nothing's alive on the map unless it's requested.

 

 

I redid the menu script, it looks like this now, i think that's what you meant?

 

AAv1= missionCommands.addSubMenu('AA Range 1v')
AAv2= missionCommands.addSubMenu('AA Range 2v')
SAM = missionCommands.addSubMenu('SAM Range On')
 
  missionCommands.addCommand('F-4', AAv1, function() trigger.action.setUserFlag('101',true)end)
  missionCommands.addCommand('F-5', AAv1, function() trigger.action.setUserFlag('102',true)end)
  missionCommands.addCommand('F-15', AAv1, function() trigger.action.setUserFlag('103',true)end)
  missionCommands.addCommand('F-16', AAv1, function() trigger.action.setUserFlag('104',true)end)
  missionCommands.addCommand('Mig21', AAv1, function() trigger.action.setUserFlag('105',true)end)
  missionCommands.addCommand('Mig29', AAv1, function() trigger.action.setUserFlag('106',true)end)
 
  missionCommands.addCommand('2 F-4', AAv2, function() trigger.action.setUserFlag('201',true)end)
  missionCommands.addCommand('2 F-5', AAv2, function() trigger.action.setUserFlag('202',true)end)
  missionCommands.addCommand('2 F-15', AAv2, function() trigger.action.setUserFlag('203',true)end)
  missionCommands.addCommand('2 F-16', AAv2, function() trigger.action.setUserFlag('204',true)end)
  missionCommands.addCommand('2 Mig21', AAv2, function() trigger.action.setUserFlag('205',true)end)
  missionCommands.addCommand('2 Mig29', AAv2, function() trigger.action.setUserFlag('206',true)end)
  
  missionCommands.addCommand('SA-2', SAM, function() trigger.action.setUserFlag('301',true)end)
  missionCommands.addCommand('SA-6', SAM, function() trigger.action.setUserFlag('302',true)end)
  missionCommands.addCommand('SA-8', SAM, function() trigger.action.setUserFlag('303',true)end)
  missionCommands.addCommand('SA-10', SAM, function() trigger.action.setUserFlag('304',true)end)
  missionCommands.addCommand('SA-11', SAM, function() trigger.action.setUserFlag('305',true)end)
   missionCommands.addCommand('SA-15', SAM, function() trigger.action.setUserFlag('306',true)end)

It didn't fix the F10 menu, but it seems to be the Wrench script, as I've read issues in MP and clients not seeing the script.

Link to comment
Share on other sites

I condensed the script into a single file, but I'm having issues with the F10 menu not showing anything other than my menu I've created. The settings menu, the range script and the JTAC menus all seem to have vanished and I can't get them to come on.

 

Is there something in my menu code that would be causing this? On the plus side, it's pretty great to have been able to figure out how to get at least this single aspect to work as desired....

 

 

AAv1= missionCommands.addSubMenu('AA Range 1v')
AAv2= missionCommands.addSubMenu('AA Range 2v')
SAM = missionCommands.addSubMenu('SAM Range On')
     
missionCommands.addCommand('F-4', AAv1, function()
   SpawnREDF4 = SPAWN:New( "REDF-4" )
   SpawnREDF4_Group = SpawnREDF4:Spawn()
   trigger.action.outText("F-4 Spawned",15)
  end)
 missionCommands.addCommand('F-5', AAv1, function()
   SpawnREDF5 = SPAWN:New( "REDF-5" )
   SpawnREDF5_Group = SpawnREDF5:Spawn()
   trigger.action.outText("F-5 Spawned",15)
  end)
missionCommands.addCommand('F-15', AAv1, function()
   SpawnREDF15 = SPAWN:New( "REDF-15" )
   SpawnREDF15_Group = SpawnREDF15:Spawn()
   trigger.action.outText("F-15 Spawned",15)
  end)
missionCommands.addCommand('F-16', AAv1, function()
   SpawnREDF16 = SPAWN:New( "REDF-16" )
   SpawnREDF16_Group = SpawnREDF16:Spawn()
   trigger.action.outText("F-16 Spawned",15)
  end)
missionCommands.addCommand('Mig21', AAv1, function()
   SpawnREDMig21 = SPAWN:New( "REDMig21" )
   SpawnREDMig21_Group = SpawnREDMig21:Spawn()
   trigger.action.outText("Mig-21 Spawned",15)
  end)
missionCommands.addCommand('Mig29', AAv1, function()
   SpawnREDMig29 = SPAWN:New( "REDMig29" )
   SpawnREDMig29_Group = SpawnREDMig29:Spawn()
   trigger.action.outText("Mig-29 Spawned",15)
  end)
missionCommands.addCommand('2 F-4', AAv2, function()
   Spawn2vF4 = SPAWN:New( "2vF-4" )
   Spawn2vF4_Group = Spawn2vF4:Spawn()
   trigger.action.outText("Section of F-4s Spawned",15)
  end)
missionCommands.addCommand('2 F-5', AAv2, function()
   Spawn2vF5 = SPAWN:New( "2vF-5" )
   Spawn2vF5_Group = Spawn2vF5:Spawn()
   trigger.action.outText("Section of F-5s Spawned",15)
  end)
missionCommands.addCommand('2 F-15', AAv2, function()
   Spawn2vF15 = SPAWN:New( "2vF-15" )
   Spawn2vF15_Group = Spawn2vF15:Spawn()
   trigger.action.outText("Section of F-15s Spawned",15)
  end)
missionCommands.addCommand('2 F-16', AAv2, function()
   Spawn2vF16 = SPAWN:New( "2vF-16" )
   Spawn2vF16_Group = Spawn2vF16:Spawn()
   trigger.action.outText("Section of F-16s Spawned",15)
  end)
missionCommands.addCommand('2 Mig21', AAv2, function()
   Spawn2vMig21 = SPAWN:New( "2vMig21" )
   Spawn2vMig21_Group = Spawn2vMig21:Spawn()
   trigger.action.outText("Section of Mig-21s Spawned",15)
  end)
missionCommands.addCommand('2 Mig29', AAv2, function()
   Spawn2vMig29 = SPAWN:New( "2vMig29" )
   Spawn2vMig29_Group = Spawn2vMig29:Spawn()
   trigger.action.outText("Section of Mig-29s Spawned",15)
  end)
missionCommands.addCommand('SA-2', SAM, function()
   SpawnSA2 = SPAWN:New( "SA-2" )
   SpawnSA2_Group = SpawnSA2:Spawn()
   trigger.action.outText("SA-2 Group Spawned",15)
  end)
missionCommands.addCommand('SA-6', SAM, function()
   SpawnSA6 = SPAWN:New( "SA-6" )
   SpawnSA6_Group = SpawnSA6:Spawn()
   trigger.action.outText("SA-6 Group Spawned",15)
  end)
 missionCommands.addCommand('SA-8', SAM, function()
   SpawnSA8 = SPAWN:New( "SA-8" )
   SpawnSA8_Group = SpawnSA8:Spawn()
   trigger.action.outText("SA-8 Spawned",15)
  end)
 missionCommands.addCommand('SA-10', SAM, function()
   SpawnSA10 = SPAWN:New( "SA-10" )
   SpawnSA10_Group = SpawnSA10:Spawn()
   trigger.action.outText("SA-10 Group Spawned",15)
  end)
 missionCommands.addCommand('SA-11', SAM, function()
   SpawnSA11 = SPAWN:New( "SA-11" )
   SpawnSA11_Group = SpawnSA11:Spawn()
   trigger.action.outText("SA-11 Group Spawned",15)
  end)
 missionCommands.addCommand('SA-15', SAM, function()
   SpawnSA15 = SPAWN:New( "SA-15" )
   SpawnSA15_Group = SpawnSA15:Spawn()
   trigger.action.outText("SA-15 Spawned",15)
  end)

Link to comment
Share on other sites

  • 2 years later...

If anyone wants to create radio menus I have created an excel spreadsheet which does it all for you...the action is only ever a flag & value but that's what you almost certainlly want anyway. Link is here - embedded in you tube description

 


Edited by gmangnall
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 7 months later...
On 1/29/2022 at 4:24 PM, gmangnall said:

If anyone wants to create radio menus I have created an excel spreadsheet which does it all for you...the action is only ever a flag & value but that's what you almost certainlly want anyway. Link is here - embedded in you tube description

 

 

First of all thank you for creating your tool/spreadsheet for menus. I'm currently using it and it has provided me with the bones for my menus. Now I am trying to remove commands and menus. Have succeeded in getting commands removed but at the expense of removing the whole menu!

The menu I'm creating gives out GPS positions/coordinates by contacting ground units and then inputting them into the NS430.  At mission start there are no positions given and the menu reads with the command "no positions". The ground unit then enters the trigger zone and then gives a coordinate of a sighted enemy.  The "no positions" command is removed and replaced with a coordinate. 

The script is this:

local M1 = missionCommands.addSubMenu('Mark Positions(GPS)',nil)           root menu

local M5 = missionCommands.addSubMenu('CombatCommand1',M1)         ground unit

   

missionCommands.addCommand('No positions', M5,function() trigger.action.setUserFlag(0,0) end, nil)   ground unit-CombatCommand1-status at mission start

After ground unit enters trigger zone

missionCommands.removeItem('No positions', M5,end, nil) succeeds in removing command but removes whole menu but replaced with one menu:

missionCommands.addCommand('coordinate', M5,function() trigger.action.setUserFlag(0,0) end, nil)

I realize your spreadsheet tool wasn't designed for this so if you can't give me an answer it's completely understandable. 

 

 

 

Link to comment
Share on other sites

6 hours ago, gmangnall said:

Hey Night Train.....thanks for your comments and I am glad you like the tool! Im afraid that Im unable to help though - I am not actually much of a scripter. Maybe try one of the face book groups....DCS Missino Editors maybe????

Again thanks for your tool. It's been a big help. Looks like I have to learn more about scripting. 

  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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