Jump to content

Help Creating Submenu Script


alfredo_laredo

Recommended Posts

Ok.. No experience on LUA scripts andafter several hours reading im having problems creating my first and very simple script.

The mission is a training ground for our squad. (Multiplayer)

 

There is and instructor that has different abilities, mark with smoke tarjets, activate IA units etc.

 

The mission is working now with Mission editor triggers.

 

I am ussing the "Addradioitem" trigger for the instructor to be able tu turn on/off various flags.

 

But the problem is that the F-10 radio menu is already filled and confusing.

 

what I want is to create a Script to Submenu for the instructor.

 

I would Like help in creating something like this.

 

F-10 Other

...........Option1

........................Submenu1

........................................Turn Flag 1 On

........................................Turn Flag 1 Off

.........................................Turn Flag 2 On

........................................Turn Flag 2 off

............Option 2

........................ Submenu2

........................................Turn FLag 3 On

........................................ Turn Flag 3 Off

With that script I should be able to understand the proccess and add my own sumbenus

A.K.A. Timon -117th- in game

Link to comment
Share on other sites

Yes, I already check that mission script.. but its a extremly complex mission. here is the script part about Radio menu. I guess MBot would have no problem if I add part of his script here..

 

 

----------------------------------------------------------------------------------------------------------------------------

--Radiomenu

----------------------------------------------------------------------------------------------------------------------------

 

function ClearDisplay(_id)

helo[_id.num].display = "none"

missionCommands.removeItemForGroup(_id.groupID, {"Clear Station Display"})

missionCommands.removeItemForGroup(_id.groupID, {"Sonobuoy Station", "Display Station", })

missionCommands.removeItemForGroup(_id.groupID, {"MAD Station", "Display Station"})

missionCommands.removeItemForGroup(_id.groupID, {"Weapon Station", "Display Station"})

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"Sonobuoy Station"}, SonobuoyStation, _id)

if helo[_id.num].enableDippingsonar == true then

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Display Station"})

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"Dipping Sonar Station"}, DippingSonarStation, _id)

end

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"MAD Station"}, MADStation, _id)

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"Weapon Station"}, WeaponStation, _id)

end

 

function SonobuoyStation(_id)

helo[_id.num].display = "sonobuoy"

timer.scheduleFunction(DisplaySonobuoySensorStation, _id, timer.getTime() + 1)

missionCommands.removeItemForGroup(_id.groupID, {"Sonobuoy Station", "Display Station", })

missionCommands.removeItemForGroup(_id.groupID, {"Clear Station Display"})

missionCommands.addCommandForGroup(_id.groupID, "Clear Station Display", nil, ClearDisplay, _id)

end

 

function DeployDippingSonar(_id)

helo[_id.num].dippingsonar_status = "down"

timer.scheduleFunction(DeployDippingSonarSound, _id, timer.getTime() + 1)

timer.scheduleFunction(DeployDippingSonarReport, _id, timer.getTime() + 1.5)

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Deploy Dipping Sonar"})

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Retrieve Dipping Sonar"})

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Stop Dipping Sonar"})

missionCommands.addCommandForGroup(_id.groupID, "Stop Dipping Sonar", {"Dipping Sonar Station"}, StopDippingSonar, _id)

missionCommands.addCommandForGroup(_id.groupID, "Retrieve Dipping Sonar", {"Dipping Sonar Station"}, RetrieveDippingSonar, _id)

if helo[_id.num].dippingsonar_cable == 0 then

timer.scheduleFunction(DippingSonarDamage, _id, timer.getTime() + 1)

end

end

 

function StopDippingSonar(_id)

helo[_id.num].dippingsonar_status = "stop"

timer.scheduleFunction(DippingSonarDetection, _id, timer.getTime() + 3)

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Deploy Dipping Sonar"})

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Retrieve Dipping Sonar"})

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Stop Dipping Sonar"})

missionCommands.addCommandForGroup(_id.groupID, "Deploy Dipping Sonar", {"Dipping Sonar Station"}, DeployDippingSonar, _id)

missionCommands.addCommandForGroup(_id.groupID, "Retrieve Dipping Sonar", {"Dipping Sonar Station"}, RetrieveDippingSonar, _id)

end

 

function RetrieveDippingSonar(_id)

helo[_id.num].dippingsonar_status = "up"

timer.scheduleFunction(RetrieveDippingSonarSound, _id, timer.getTime() + 1)

timer.scheduleFunction(RetrieveDippingSonarReport, _id, timer.getTime() + 1.5)

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Deploy Dipping Sonar"})

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Retrieve Dipping Sonar"})

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Stop Dipping Sonar"})

missionCommands.addCommandForGroup(_id.groupID, "Stop Dipping Sonar", {"Dipping Sonar Station"}, StopDippingSonar, _id)

missionCommands.addCommandForGroup(_id.groupID, "Deploy Dipping Sonar", {"Dipping Sonar Station"}, DeployDippingSonar, _id)

end

 

function DippingSonarStation(_id)

helo[_id.num].display = "dippingsonar"

timer.scheduleFunction(DisplayDippingSonarStation, _id, timer.getTime() + 1)

missionCommands.removeItemForGroup(_id.groupID, {"Dipping Sonar Station", "Display Station"})

missionCommands.removeItemForGroup(_id.groupID, {"Clear Station Display"})

missionCommands.addCommandForGroup(_id.groupID, "Clear Station Display", nil, ClearDisplay, _id)

end

 

function DeployMAD(_id)

helo[_id.num].MAD_deploy = true

timer.scheduleFunction(DeployMADSound, _id, timer.getTime() + 1)

timer.scheduleFunction(DeployMADReport, _id, timer.getTime() + 1.5)

missionCommands.removeItemForGroup(_id.groupID, {"MAD Station", "Deploy MAD"})

missionCommands.addCommandForGroup(_id.groupID, "Retrieve MAD", {"MAD Station"}, RetrieveMAD, _id)

if helo[_id.num].MAD_cable == 0 then

timer.scheduleFunction(MADDamage, _id, timer.getTime() + 1.5)

end

end

 

function RetrieveMAD(_id)

helo[_id.num].MAD_deploy = false

timer.scheduleFunction(RetrieveMADSound, _id, timer.getTime() + 1)

timer.scheduleFunction(RetrieveMADReport, _id, timer.getTime() + 1.5)

missionCommands.removeItemForGroup(_id.groupID, {"MAD Station", "Retrieve MAD"})

missionCommands.addCommandForGroup(_id.groupID, "Deploy MAD", {"MAD Station"}, DeployMAD, _id)

end

 

function MADStation(_id)

helo[_id.num].display = "MAD"

timer.scheduleFunction(DisplayMADStation, _id, timer.getTime() + 1)

missionCommands.removeItemForGroup(_id.groupID, {"MAD Station", "Display Station"})

missionCommands.removeItemForGroup(_id.groupID, {"Clear Station Display"})

missionCommands.addCommandForGroup(_id.groupID, "Clear Station Display", nil, ClearDisplay, _id)

end

 

function WeaponStation(_id)

helo[_id.num].display = "weapon"

timer.scheduleFunction(DisplayWeaponStation, _id, timer.getTime() + 1)

missionCommands.removeItemForGroup(_id.groupID, {"Weapon Station", "Display Station"})

missionCommands.removeItemForGroup(_id.groupID, {"Clear Station Display"})

missionCommands.addCommandForGroup(_id.groupID, "Clear Station Display", nil, ClearDisplay, _id)

end

 

function EnableShowTruth() --All subs and torpedos are indicated with signal flares

ShowTruth = true

missionCommands.removeItem({"Enable Show Truth"})

missionCommands.addCommand("Disable Show Truth", nil, DisableShowTruth)

end

 

function DisableShowTruth()

ShowTruth = false

missionCommands.removeItem({"Disable Show Truth"})

missionCommands.addCommand("Enable Show Truth", nil, EnableShowTruth)

end

 

function PopulateRadioMenu(_id)

missionCommands.removeItemForGroup(_id.groupID, nil)

missionCommands.addCommandForGroup(_id.groupID, "Drop Smoke Marker", nil, DropSmokeMarker, _id)

missionCommands.addSubMenuForGroup(_id.groupID, "Sonobuoy Station")

missionCommands.addCommandForGroup(_id.groupID, "Drop Sonobuoy Shallow", {"Sonobuoy Station"}, DropSonobuoy, { _id, -50 })

missionCommands.addCommandForGroup(_id.groupID, "Drop Sonobuoy Deep", {"Sonobuoy Station"}, DropSonobuoy, { _id, -400 })

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"Sonobuoy Station"}, SonobuoyStation, _id)

if helo[_id.num].enableDippingsonar == true then

missionCommands.addSubMenuForGroup(_id.groupID, "Dipping Sonar Station")

missionCommands.addCommandForGroup(_id.groupID, "Deploy Dipping Sonar", {"Dipping Sonar Station"}, DeployDippingSonar, _id)

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"Dipping Sonar Station"}, DippingSonarStation, _id)

end

missionCommands.addSubMenuForGroup(_id.groupID, "MAD Station")

missionCommands.addCommandForGroup(_id.groupID, "Deploy MAD", {"MAD Station"}, DeployMAD, _id)

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"MAD Station"}, MADStation, _id)

missionCommands.addSubMenuForGroup(_id.groupID, "Weapon Station")

missionCommands.addCommandForGroup(_id.groupID, "Drop Weapon", {"Weapon Station"}, DropTorpedo, _id)

missionCommands.addSubMenuForGroup(_id.groupID, "Weapon Depth Preset", {"Weapon Station"})

missionCommands.addCommandForGroup(_id.groupID, "Set 50 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -50 })

missionCommands.addCommandForGroup(_id.groupID, "Set 100 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -100 })

missionCommands.addCommandForGroup(_id.groupID, "Set 150 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -150 })

missionCommands.addCommandForGroup(_id.groupID, "Set 200 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -200 })

missionCommands.addCommandForGroup(_id.groupID, "Set 250 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -250 })

missionCommands.addCommandForGroup(_id.groupID, "Set 300 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -300 })

missionCommands.addCommandForGroup(_id.groupID, "Set 350 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -350 })

missionCommands.addCommandForGroup(_id.groupID, "Set 400 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -400 })

missionCommands.addCommandForGroup(_id.groupID, "Set 450 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -450 })

missionCommands.addCommandForGroup(_id.groupID, "Set 500 m", {"Weapon Station", "Weapon Depth Preset"}, WeaponDepth, { _id, -500 })

missionCommands.addCommandForGroup(_id.groupID, "Display Station", {"Weapon Station"}, WeaponStation, _id)

if SwitchShowTruth == true then

if ShowTruth == false then

--missionCommands.removeItem({"Enable Show Truth"}) --disabled (not needed anyway), causes bug

missionCommands.addCommand("Enable Show Truth", nil, EnableShowTruth)

elseif ShowTruth == true then

--missionCommands.removeItem({"Disable Show Truth"}) --disabled (not needed anyway), causes bug

missionCommands.addCommand("Disable Show Truth", nil, DisableShowTruth)

end

end

end

 

local function CheckHeloActive()

for n = 1, #helo do

if Unit.getByName(helo[n].name) ~= nil and helo[n].active == false then

local _id = {

name = helo[n].name,

groupID = Unit.getByName(helo[n].name):getGroup():getID(),

num = n

}

PopulateRadioMenu(_id)

helo[n].active = true

helo[n].smokemarker = helo[n].smokemarkerCapacity

helo[n].sonobuoy = helo[n].sonobuoyCapacity

helo[n].torpedo = helo[n].torpedoCapacity

HeloVariables(n)

elseif Unit.getByName(helo[n].name) == nil then

helo[n].active = false

end

end

return timer.getTime() + 1

end

timer.scheduleFunction(CheckHeloActive, nil, 2)

 

A.K.A. Timon -117th- in game

Link to comment
Share on other sites

Looking at the script I found out this functiones like this

 

F-10 Other

...........Option1 missionCommands.addSubMenuForGroup(_id.groupID, "submenu1")

........................Submenu1

........................................Turn Flag 1 On missionCommands.addCommandForGroup (???)

........................................Turn Flag 1 Off missionCommands.addCommandForGroup (???)

.........................................Turn Flag 2 On missionCommands.addCommandForGroup (???

A.K.A. Timon -117th- in game

Link to comment
Share on other sites

I am working on something very similar, alfredo.

 

One thing I can't figure out is how to selectively remove an item from a submenu. For instance, you wanted to replace "Turn Flag 2 Off" above with something else.

 

Seems like the scripting function: missionCommands.removeItemForCoalition(enum coalition.side coalition, Path or nil path) should have not just a "path" but also a "string name", yes?

 

So far everything I tried results in all the submenu's and items being deleted from F10 other menu. Has anyone successfully accomplished this??

Link to comment
Share on other sites

  • 11 months later...
  • 3 weeks later...

Hi guys,

 

Here's an example for a 2 level sub menu with commands at level 2.

 

Basically use the return of addSubMenu, which is a path, to build your menu structure

 




local _path1 = missionCommands.addSubMenu("Level 1", nil)

local _path2 = missionCommands.addSubMenu("Level 2", _path1)

missionCommands.addCommand("COMMAND 1", _path2,function() 
env.info("RADIO COMMAND")
end, nil)


 

Hope that helps!

  • Like 1

Scripts: Complete Transport And Logistics Deployment - CTLD / CTLD Examples - Lots of example of how to use CTLD

CSAR Script - Downed Pilot Rescue / Dedicated Server Script - Automatically launch DCS Multiplayer server at startup

Range Scoring Script - Get scores and counts hits on targets for gunnery or bombs / SimpleSlotBlock - Multiplayer dynamic Slot Blocking Script

 

Projects: DCS-SimpleRadio Standalone - DCS Radio Integration for All Aircraft - NO TeamSpeak Required! :)

DCS-SimpleRadio Troubleshooting Post / DCS-SimpleRadio Free Support Channel on Discord

Link to comment
Share on other sites

  • 1 year later...

I was looking to create Radio sub menu actions, and thanks to this old example, i've made it.

 

but now, i'm stuck at the point where i need to remove the called command without deactivating other sub menus.

 

my code looks like this

 

ON MISSION START :

local M1 = missionCommands.addSubMenu("Level 1", nil)

local M2 = missionCommands.addSubMenu("Level 2", M1)

missionCommands.addCommand("COMMAND SUB2", M2,function() trigger.action.setUserFlag(1, true) end, nil)
missionCommands.addCommand("COMMAND SUB1", M1,function() trigger.action.setUserFlag(2, true) end, nil)

then ONCE :

Flag (1) is True (in sub menu Level 2)

Do Script :

missionCommands.removeItem(M2)

unfortunately, the removeItem removes all Radio item (F10 is wiped) :(

Is there a way to do this correctly ?

This is basically my very first LUA programmation so don't whip me please.

TASK / ROLES acronyms guide

Black Shark A.I. datalink guide illustrated (v1.2.4 Available on Wiki)

DCS World Codex 1.1 : full units list (Speed/Weapons/Armor thickness/Threat zone/Weapon damage...) (Oct 2013)

BlackShark 2 1.2.x Bug and glitches thread (v1.2.7)

Link to comment
Share on other sites

Its probably a locality issue. The value M2 is local to "Do Script" that occurs on mission start. Any code anywhere else, like the other do script, cannot "see" the value of M2, therefore it is nil. When you pass nil or nothing to a missionCommands.removeItem() function it removes everything.

 

You can remove the local to make the value M2 "global" to test it out.

 

However you should try to avoid global values as much as possible.

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

Thank you Grimes. It works like a charm. I should have tested this before posting.

 

I tried to implement multiples functions via 1 radio command, but I think it can't be possible, as I should set a flag, which in turn activate others functions.

 

anyways, if you have a trick to immediately de-active the selected item menu in the same lua-box, i'll take it, and avoid global variables as much as possible.

 

I looked over ED wiki and hoggit, and I must admit I'm stuck with many dark zones, as there are many command, but no argument/optional argument description.

In fact, the ultimate tool is MIST, with a great description to each command. but sometimes, MIST is just overkill.

TASK / ROLES acronyms guide

Black Shark A.I. datalink guide illustrated (v1.2.4 Available on Wiki)

DCS World Codex 1.1 : full units list (Speed/Weapons/Armor thickness/Threat zone/Weapon damage...) (Oct 2013)

BlackShark 2 1.2.x Bug and glitches thread (v1.2.7)

Link to comment
Share on other sites

  • 1 year later...

Hi!

 

Thanks to some old threats like this one, the hoggit wiki, a bit of intuition and luck, I've been able to create a nested F10 radio command menu for a SP mission I'm making (DCS 2.5).

I've also managed to get those nested F10 radio commands to actually trigger flags correctly, which has been a massive breakthrough for me.

 

Now, however, I've hit another wall (sort of) and I don't think I can surmount it without help.

 

I basically have two problems:

 

1- I don't know how to apply a single command to a set of strings/GroupIDs

(I don't even know if it's possible with the method I'm currently using)

 

Example:

local subN4 = missionCommands.addSubMenuForGroup(5 ,'Su33 air refueling -Kuznetsov-', subR)

 

I would like this single command to also apply to strings/groupIDs 10 and 51, not just 5.

 

I've already tried listing them as follows:

5,10,51

5..10..51

{5,10,51}

5 10 51

 

No dice... probably because I'm a total noob and I'm trying silly stuff, so bear with me, :Flush:

 

Does the command "addSubMenuForGroup" even accept several groupID strings instead of just the one?

 

The workaround I'm using atm is to just run the command individually for each string/groupID, which significantly increases the number of lines in my script and...well, looks kind of ugly, :thumbdown:

 

 

2- I'm having trouble figuring out how to remove those scripted radio commands once they've finished running.

 

I've read several articles, posts and watched some YT videos, trying to come up with a way of doing this, but so far I haven't found anything I can use.

 

I can remove my nested radio commands using this:

missionCommands.removeItemForGroup(groupID, path)

 

Problem is that I don't know how to write up a condition/logic, so this command waits for the right moment to run (ie wait for the radio message to be played first).

 

 

Something like:

 

if
flag 1 = 1 (the radio command I want to remove triggers this flag in my script)
then 
run missionCommands.removeItemForGroup(groupID, path)

 

Would this kind of thing be doable in LUA?

 

Also, from what I've read, I understand that if I set my script to global instead of local, I'd have no problem running the removeItem command on a separate trigger... but since someone said this can be dangerous, I'd rather not do it unless it's absolutely necessary.

 

Here's part of my nested F10 radio menu script so far (seems to work without issues):

 

local subR = missionCommands.addSubMenu('Missions')

local subN1 = missionCommands.addSubMenuForGroup(5,'Su33 carrier take-off & landing', subR)

local subN2 = missionCommands.addCommandForGroup(5,'Briefing', subN1, function() trigger.action.setUserFlag('1', true) end)

 

local subN3 = missionCommands.addCommandForGroup(5,'Su33 take-off procedure -Replayable-', subR, function() trigger.action.setUserFlag('2', true) end)

 

local subN4 = missionCommands.addSubMenuForGroup(5,'Su33 air refueling -Kuznetsov-', subR)

local subN5 = missionCommands.addCommandForGroup(5,'Briefing', subN4, function() trigger.action.setUserFlag('3', true) end)

 

local subN6 = missionCommands.addSubMenuForGroup(10,'Su33 air refueling', subR)

local subN7 = missionCommands.addCommandForGroup(10,'Briefing', subN6, function() trigger.action.setUserFlag('4', true) end)

 

local subN8 = missionCommands.addSubMenuForGroup(51,'Su33 air refueling', subR)

local subN9 = missionCommands.addCommandForGroup(51,'Briefing', subN8, function() trigger.action.setUserFlag('4', true) end)

 

local subN10 = missionCommands.addSubMenuForCoalition(1,'CAS static targets', subR)

local subN11 = missionCommands.addCommandForCoalition(1,'Briefing', subN10, function() trigger.action.setUserFlag('5', true) end)

 

local subN12 = missionCommands.addSubMenuForCoalition(1,'CAS convoy', subR)

local subN13 = missionCommands.addCommandForCoalition(1,'Briefing', subN12, function() trigger.action.setUserFlag('6', true) end)

 

 

How should I go about removing commands with this?

 

Thanks in advance.


Edited by Hardcard
Link to comment
Share on other sites

  • 3 years later...

Hi guys, help, I created a training mission and I created the radio menu to activate the various training sessions.
the problem is that even if the flags that are activated are repetitive, they are activated only once! It's a script problem, I can't make it repetitive .... I have already done all the necessary tests in the editor so I will turn the script to you and please help me ....

 

 

local M1 = missionCommands.addSubMenu("A2G", nil)

local M2 = missionCommands.addSubMenu("CONVOGLIO", M1)
local M3 = missionCommands.addSubMenu("GROUND EST", M1)
local M4 = missionCommands.addSubMenu("JTAC POLIGONO", M1)
missionCommands.addCommand("ON", M2,function() trigger.action.setUserFlag(1, true) end, nil)
missionCommands.addCommand("0FF", M2,function() trigger.action.setUserFlag(2, true) end, nil)
missionCommands.addCommand("ON", M3,function() trigger.action.setUserFlag(3, true) end, nil)
missionCommands.addCommand("OFF", M3,function() trigger.action.setUserFlag(4, true) end, nil)
missionCommands.addCommand("ON", M4,function() trigger.action.setUserFlag(15, true) end, nil)
missionCommands.addCommand("0FF", M4,function() trigger.action.setUserFlag(16, true) end, nil)

Link to comment
Share on other sites

What do you mean by 'repetitive', i.e. what are you trying to do (what do you expect to see), what do you actually see happening, and why do you think that is wrong?

 

From the code snippet I see above, you are setting 6 different flags to true when a menu item is selected. Since I see no code that re-sets them (maybe you do that in your code someplace else), they will remain that way on the second invocation. Also, if you trigger on a flag being set, remember that by default, triggers themselves are ONCE, and you may need to alter that as well.

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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