Jump to content

addsubmenu's Coalition works, Group doesnt..what?


Recommended Posts

Ok, so I have 2 menu scripts....one that is for a coalition and one that is for individual groups. Coalition menu's work perfectly all the way through. Change it to the Group menu and nothing comes up at all. What am I missing?

Both scripts are posted below. Thanks for any feedback!

 

Coaltion: (this works)

 

local function setFlags(v)

trigger.action.setUserFlag(v.flag, v.val)

end

 

local spawn1 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"Spawn PVE")

local spawn2 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"Mig-29s",spawn1)

local spawn3 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"SU-33s",spawn1)

local spawn4 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"F-14s",spawn1)

local spawn5 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"F-18s",spawn1)

local spawn6 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"F-15s",spawn1)

local spawn7 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"J-11As",spawn1)

local spawn8 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"F-5Es",spawn1)

local spawn9 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"FW-190s",spawn1)

local spawn10 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"F-16Cs",spawn1)

local spawn11 = missionCommands.addSubMenuForCoalition(coalition.side.BLUE,"F-4Es",spawn1)

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "Mig 29 1 Ship", spawn2, setFlags, {flag=123, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "Mig 29 2 Ship", spawn2, setFlags, {flag=184, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "Su-33 1 Ship", spawn3, setFlags, {flag=124, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "Su-33 2 Ship", spawn3, setFlags, {flag=185, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-14 1 Ship", spawn4, setFlags, {flag=125, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-14 2 Ship", spawn4, setFlags, {flag=182, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-18 1 Ship", spawn5, setFlags, {flag=126, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-18 2 Ship", spawn5, setFlags, {flag=183, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-15 1 Ship", spawn6, setFlags, {flag=127, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-15 2 Ship", spawn6, setFlags, {flag=186, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "J=11A 1 Ship", spawn7, setFlags, {flag=130, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "J=11A 2 Ship", spawn7, setFlags, {flag=190, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-5E 1 Ship", spawn8, setFlags, {flag=131, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-5E 2 Ship", spawn8, setFlags, {flag=189, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "FW-190 1 Ship", spawn9, setFlags, {flag=132, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "FW-190 2 Ship", spawn9, setFlags, {flag=191, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-16C 1 Ship", spawn10, setFlags, {flag=133, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-16C 2 Ship", spawn10, setFlags, {flag=187, val=true})

 

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-4E 1 Ship", spawn11, setFlags, {flag=146, val=true})

missionCommands.addCommandForCoalition(coalition.side.BLUE, "F-4E 2 Ship", spawn11, setFlags, {flag=188, val=true})

 

 

Group: (this doesnt)

 

local function setFlags(v)

trigger.action.setUserFlag(v.flag, v.val)

end

 

local spawn1 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"Spawn PVE")

local spawn2 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"Mig-29s",spawn1)

local spawn3 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"SU-33s",spawn1)

local spawn4 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"F-14s",spawn1)

local spawn5 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"F-18s",spawn1)

local spawn6 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"F-15s",spawn1)

local spawn7 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"J-11As",spawn1)

local spawn8 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"F-5Es",spawn1)

local spawn9 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"FW-190s",spawn1)

local spawn10 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"F-16Cs",spawn1)

local spawn11 = missionCommands.addSubMenuForGroup(BVR_Blue_F18_1,"F-4Es",spawn1)

 

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "Mig 29 1 Ship", spawn2, setFlags, {flag=123, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "Mig 29 2 Ship", spawn2, setFlags, {flag=184, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "Su-33 1 Ship", spawn3, setFlags, {flag=124, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "Su-33 2 Ship", spawn3, setFlags, {flag=185, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-14 1 Ship", spawn4, setFlags, {flag=125, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-14 2 Ship", spawn4, setFlags, {flag=182, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-18 1 Ship", spawn5, setFlags, {flag=126, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-18 2 Ship", spawn5, setFlags, {flag=183, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-15 1 Ship", spawn6, setFlags, {flag=127, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-15 2 Ship", spawn6, setFlags, {flag=186, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "J=11A 1 Ship", spawn7, setFlags, {flag=130, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "J=11A 2 Ship", spawn7, setFlags, {flag=190, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-5E 1 Ship", spawn8, setFlags, {flag=131, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-5E 2 Ship", spawn8, setFlags, {flag=189, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "FW-190 1 Ship", spawn9, setFlags, {flag=132, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "FW-190 2 Ship", spawn9, setFlags, {flag=191, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-16C 1 Ship", spawn10, setFlags, {flag=133, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-16C 2 Ship", spawn10, setFlags, {flag=187, val=true})

 

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-4E 1 Ship", spawn11, setFlags, {flag=146, val=true})

missionCommands.addCommandForGroup(BVR_Blue_F18_1, "F-4E 2 Ship", spawn11, setFlags, {flag=188, val=true})

Link to comment
Share on other sites

You're missing the groupID (the first parameter must be the groupID, not the group object or name)

 

I don't know how BVR_Blue_F18_1 is declared in your script, but if that's the name of the group in ME, you need to do something like this:

 

local Group_ID = Group.getByName("BVR_Blue_F18_1"):getID()

local spawn1 = missionCommands.addSubMenuForGroup(Group_ID ,"Spawn PVE")  [color="Blue"]-- Maybe make this variable global? In case you want to remove this root submenu later on[/color]
local spawn2 = missionCommands.addSubMenuForGroup(Group_ID ,"Mig-29s",spawn1) [color="Blue"]-- Maybe make this variable global? In case you want to remove this root submenu later on[/color]

missionCommands.addCommandForGroup(Group_ID , "Mig 29 1 Ship", spawn2, setFlags, {flag=123, val=true})
missionCommands.addCommandForGroup(Group_ID , "Mig 29 2 Ship", spawn2, setFlags, {flag=184, val=true})


Edited by Hardcard
Link to comment
Share on other sites

So if I want to use it for multiple groups can I just put local Group_ID = Group.getByName("BVR_Blue_F18_1"):getID() in for each group then use Group I'd for the rest of the script?

 

local Group_ID = Group.getByName("BVR_Blue_F18_1"):getID()

local Group_ID = Group.getByName("BVR_Blue_F18_2"):getID()

local Group_ID = Group.getByName("BVR_Blue_F18_3"):getID()

 

Like that?

Link to comment
Share on other sites

Don't use the same variable name for all three groups, otherwise DCS won't know the difference.

In this case, this won't work for what you want to accomplish, even if you give the variables different names... it's just a general scripting tip.

 

Now, if you want the group menus to be automatically created for the three groups, you'll need to use a table and a for loop.

 

local function setFlags(v)
      trigger.action.setUserFlag(v.flag, v.val)
end

local Group_Name_Table = {"BVR_Blue_F18_1", "BVR_Blue_F18_2", "BVR_Blue_F18_3"} [color="Blue"]-- Include all the relevant group names in this table (string format, separated by commas)[/color]

for i , GroupName in pairs( Group_Name_Table ) do  [color="Blue"]-- This is the for loop. i stands for the table index value, which in this case would be either 1, 2 or 3 (since there are 3 elements in the table above). GroupName stands for the values inside the table (in this case, the string names of the 3 groups)[/color]
   
   if Group.getByName(GroupName) ~= nil then
   
      local Group_ID = Group.getByName(GroupName):getID()
   
      local spawn1 = missionCommands.addSubMenuForGroup(Group_ID,"Spawn PVE")
      local spawn2 = missionCommands.addSubMenuForGroup(Group_ID,"Mig-29s",spawn1)
      local spawn3 = missionCommands.addSubMenuForGroup(Group_ID,"SU-33s",spawn1)
      local spawn4 = missionCommands.addSubMenuForGroup(Group_ID,"F-14s",spawn1)
      local spawn5 = missionCommands.addSubMenuForGroup(Group_ID,"F-18s",spawn1)
      local spawn6 = missionCommands.addSubMenuForGroup(Group_ID,"F-15s",spawn1)
      local spawn7 = missionCommands.addSubMenuForGroup(Group_ID,"J-11As",spawn1)
      local spawn8 = missionCommands.addSubMenuForGroup(Group_ID,"F-5Es",spawn1)
      local spawn9 = missionCommands.addSubMenuForGroup(Group_ID,"FW-190s",spawn1)
      local spawn10 = missionCommands.addSubMenuForGroup(Group_ID,"F-16Cs",spawn1)
      local spawn11 = missionCommands.addSubMenuForGroup(Group_ID,"F-4Es",spawn1)
      
      
      missionCommands.addCommandForGroup(Group_ID, "Mig 29 1 Ship", spawn2, setFlags, {flag=123, val=true})
      missionCommands.addCommandForGroup(Group_ID, "Mig 29 2 Ship", spawn2, setFlags, {flag=184, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "Su-33 1 Ship", spawn3, setFlags, {flag=124, val=true})
      missionCommands.addCommandForGroup(Group_ID, "Su-33 2 Ship", spawn3, setFlags, {flag=185, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "F-14 1 Ship", spawn4, setFlags, {flag=125, val=true})
      missionCommands.addCommandForGroup(Group_ID, "F-14 2 Ship", spawn4, setFlags, {flag=182, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "F-18 1 Ship", spawn5, setFlags, {flag=126, val=true})
      missionCommands.addCommandForGroup(Group_ID, "F-18 2 Ship", spawn5, setFlags, {flag=183, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "F-15 1 Ship", spawn6, setFlags, {flag=127, val=true})
      missionCommands.addCommandForGroup(Group_ID, "F-15 2 Ship", spawn6, setFlags, {flag=186, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "J=11A 1 Ship", spawn7, setFlags, {flag=130, val=true})
      missionCommands.addCommandForGroup(Group_ID, "J=11A 2 Ship", spawn7, setFlags, {flag=190, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "F-5E 1 Ship", spawn8, setFlags, {flag=131, val=true})
      missionCommands.addCommandForGroup(Group_ID, "F-5E 2 Ship", spawn8, setFlags, {flag=189, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "FW-190 1 Ship", spawn9, setFlags, {flag=132, val=true})
      missionCommands.addCommandForGroup(Group_ID, "FW-190 2 Ship", spawn9, setFlags, {flag=191, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "F-16C 1 Ship", spawn10, setFlags, {flag=133, val=true})
      missionCommands.addCommandForGroup(Group_ID, "F-16C 2 Ship", spawn10, setFlags, {flag=187, val=true})
      
      missionCommands.addCommandForGroup(Group_ID, "F-4E 1 Ship", spawn11, setFlags, {flag=146, val=true})
      missionCommands.addCommandForGroup(Group_ID, "F-4E 2 Ship", spawn11, setFlags, {flag=188, val=true})
  
  end

end


Edited by Hardcard
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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