Jump to content

MP radio menu in LUA


L39Tom

Recommended Posts

Ok, I'm going crazy with this radio menu.

I'm trying to make a (different)radio menu for two clients.

I set 2 client F18 hot at Batumi airfield.

Script starts over ONCE....MORE TIME(2)...DO SCRIPT

 

 

here ist the script (parts copied from other scripts)

 

 

-----Clients----

jet = {

[1] = {

name = "MERLIN1"

},

[2] = {

name = "MERLIN2"

}

}

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

function sub11(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 11", 10 , false)

missionCommands.removeItemForGroup(val.groupID,{"SubMenu 1.1.","MainMenu 1"})

end

function sub12(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 12", 10 , false)

end

function sub21(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 21", 10 , false)

end

function sub22(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 22", 10 , false)

end

 

------Radio Menue

function RadioMenu(_id)

missionCommands.removeItemForGroup(_id.groupID, nil)

 

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 1")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.1.", {"MainMenu 1"}, sub11, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.2.", {"MainMenu 1"}, sub12, _id)

 

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 2")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.1.", {"MainMenu 2"}, sub21, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.2.", {"MainMenu 2"}, sub22, _id)

 

end

 

-------testing loop---------------

local function CheckActiveClients()

for n = 1, #jet do

if Unit.getByName(jet[n].name) ~= nil then

local _id = {

name = jet[n].name,

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

num = n

}

trigger.action.outText(_id,2)

RadioMenu(_id)

end

end

return timer.getTime() + 1

end

--trigger.action.outText("Line "..string.format(debug.getinfo(1).currentline).." passed", 4000)

timer.scheduleFunction(CheckActiveClients, nil, 2)

At the end there should be a radio menu (F10) for both clients.

 

The clients should get different messages after triggering a sub menu.

 

 

PS: Is it possible to remove a submenu just for one client with

missionCommands.removeItemForGroup?

 

 

thanks for some help

Link to comment
Share on other sites

And what's the problem exactly?

 

Are the clients getting both nested menus instead of just the one?

 

If it's not running, could the problem be related to the following bit?:

 

 

local _id = { name = jet[n].name, groupID = Unit.getByName(jet[n].name):getGroup():getID(), num = n }

 

trigger.action.outText(_id,2) -- _id is a table, not a string. Perhaps the DCS scripting engine is freaking out because trigger.action.outText() is getting a table as first parameter instead of a string?

 


Edited by Hardcard
Link to comment
Share on other sites

Hallo Hardcard.

You are right. The shown trigger.action comand is wrong. But even if you

delete it: none of the clients get a f10 menu.

I tried every combination and take some codes together. Nothing.

Link to comment
Share on other sites

Tbh, I've never used such an iterator (the for loop).

 

Have you verified that _id.groupID actually returns a valid group ID?

 

If you add the following line at the very start of RadioMenu() function, do you get the client name and the group ID?

 

trigger.action.outText(_id.name.." group ID = ".._id.groupID,10)

 

If you don't, then there's your problem, I guess.

 

 

If you do get them, then try commenting out the removeItemForGroup() line, see if the menus appear then:

missionCommands.removeItemForGroup(_id.groupID, nil)

 

 

EDIT: I've tested the script in a single player environment (switching between 2 clients) and I can confirm that both clients get the menus consistently.

_id.name and _id.groupID seem to return the correct values.

 

It's a matter of giving the clients the unit names MERLIN1 and MERLIN2 respectively... at least in a single player environment.

 

This is the script version that I tested (I run it using a MISSION START trigger):

 

-----Clients----

jet = { [1] = {name = "MERLIN1"}, [2] = {name = "MERLIN2"} }

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

function sub11(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 11", 10 , false)

missionCommands.removeItemForGroup(IDval.groupID,{"SubMenu 1.1.","MainMenu 1"})

end

function sub12(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 12", 10 , false)

end

function sub21(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 21", 10 , false)

end

function sub22(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 22", 10 , false)

end

 

------Radio Menue

function RadioMenu(_id)

 

trigger.action.outText(_id.name.." group ID = ".._id.groupID,10)

 

missionCommands.removeItemForGroup(_id.groupID, nil)

 

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 1")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.1.", {"MainMenu 1"}, sub11, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.2.", {"MainMenu 1"}, sub12, _id)

 

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 2")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.1.", {"MainMenu 2"}, sub21, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.2.", {"MainMenu 2"}, sub22, _id)

 

end

 

-------testing loop---------------

 

local function CheckActiveClients()

 

for n = 1, #jet do

 

if Unit.getByName(jet[n].name) ~= nil then

 

local _id = {name = jet[n].name, groupID = Unit.getByName(jet[n].name):getGroup():getID(), num = n}

 

RadioMenu(_id)

end

end

return timer.getTime() + 10

end

 

--trigger.action.outText("Line "..string.format(debug.getinfo(1).currentline).." passed", 4000)

timer.scheduleFunction(CheckActiveClients, nil, 10)

 

 

Perhaps things get trickier in multiplayer environments, which might explain why your clients don't get the menus.

 

 

Btw, I've noticed another mistake in the following line:

function sub11(IDval) 
trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 11", 10 , false)
missionCommands.removeItemForGroup([color="red"][i]val[/i][/color].groupID,{"SubMenu 1.1.","MainMenu 1"}) [color="Blue"]-- I guess it should be [i][b]IDval[/b][/i] instead of [i][b]val[/b][/i][/color]
end

 

 

In case you want to make the menus client-specific, I guess you could use groupID checks (you'll need to know the group ID of each client beforehand) :

 

function RadioMenu(_id)

 

trigger.action.outText(_id.name.." group ID = ".._id.groupID,10)

 

missionCommands.removeItemForGroup(_id.groupID, nil)

 

if _id.groupID == 1 then -- Only MERLIN1 will get this

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 1")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.1.", {"MainMenu 1"}, sub11, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.2.", {"MainMenu 1"}, sub12, _id)

end

 

if _id.groupID == 2 then -- Only MERLIN2 will get this

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 2")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.1.", {"MainMenu 2"}, sub21, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.2.", {"MainMenu 2"}, sub22, _id)

end

end

 


Edited by Hardcard
Link to comment
Share on other sites

Thanks again, Hardcard. You made it work.

 

 

 

But if I use your script I do not get the right submenu all the time.

Try to trigger sub 1.1. menu 10 times, most of the tries I get "sub 2.2."

I shortened the check to 1sec but no difference.

 

 

Do have a clue what to change?

 

 

Btw, when entering sub 1.1. the submenu doesn't get removed for the client. Did that worked for you?

 

 

I solve the first problem (thanks to MBOTs heli-mission). Now I get the right submenu all the time.

 

 

 

-----Clients----

jet = { [1] = {name = "MERLIN1"}, [2] = {name = "MERLIN2"} }

 

 

for n = 1, #jet do

jet[n].active = false

end

 

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

function sub11(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 11", 10 , false)

missionCommands.removeItemForGroup(IDval.groupID,{"SubMenu 1.1.","MainMenu 1"})

end

function sub12(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 12", 10 , false)

end

function sub21(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 21", 10 , false)

end

function sub22(IDval)

trigger.action.outTextForGroup(IDval.groupID, " You have entered submenu 22", 10 , false)

end

 

------Radio Menue

function RadioMenu(_id)

 

trigger.action.outText(_id.name.." group ID = ".._id.groupID,10)

 

--missionCommands.removeItemForGroup(_id.groupID, nil)

 

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 1")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.1.", {"MainMenu 1"}, sub11, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 1.2.", {"MainMenu 1"}, sub12, _id)

 

missionCommands.addSubMenuForGroup(_id.groupID, "MainMenu 2")

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.1.", {"MainMenu 2"}, sub21, _id)

missionCommands.addCommandForGroup(_id.groupID, "SubMenu 2.2.", {"MainMenu 2"}, sub22, _id)

 

end

 

-------testing loop---------------

 

local function CheckActiveClients()

for n = 1, #jet do

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

local _id = {name = jet[n].name, groupID = Unit.getByName(jet[n].name):getGroup():getID(), num = n}

RadioMenu(_id)

jet[n].active = true

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

jet[n].active = false

end

end

return timer.getTime() + 1

end

 

--trigger.action.outText("Line "..string.format(debug.getinfo(1).currentline).." passed", 4000)

timer.scheduleFunction(CheckActiveClients, nil, 1)

 

 

hopefully we get that "remove"problem solved, too


Edited by L39Tom
get further
Link to comment
Share on other sites

Yes, I noticed the submenu message problem as well.

 

I think it was caused by the scheduler calling RadioMenu() again (thus creating a new menu structure), while the client was still using the previous menu structure (which no longer existed).

 

With a sufficient scheduler delay (30 seconds or so), I was able to access all menus and get all the correct messages, since it was all done before RadioMenu() could be called again by the scheduler.

 

As for removeItemForGroup(), I can confirm that it worked for me. When I commented the line out, radio menus started stacking every time RadioMenu() was called.

So definitely keep it on, don't comment it out.


Edited by Hardcard
Link to comment
Share on other sites

Hi Hardcard, I made it worked. Just another stupid fault.

 

 

missionCommands.removeItemForGroup(IDval.groupID,{"SubMenu 1.1.","MainMenu 1"}) has to be

missionCommands.removeItemForGroup(IDval.groupID,{"MainMenu 1","SubMenu 1.1."}) :doh:

 

 

with the jet[n].active part everything works as it should!

 

 

So, another problem solved. Thanks for your kind suport as everytime.

Link to comment
Share on other sites

  • 2 years later...

THANK YOU BOTH !!
I've been trying to generate a list for a group for several days, this script is totally useful to me even if I have to indicate the name of the pilot and not the group.
Cheers

[sIGPIC][/sIGPIC]

Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz   3.70 GHz ROG STRIX Z490-E GAMING
RAM 128 M.2*2 2T total SSD*3 2.5T total
GeForce RTX 3090   Orion2 HOTAS F-16EX  Saitek Pro Rudder

Link to comment
Share on other sites

  • Recently Browsing   0 members

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