Jump to content

LUA F10 Menu Script Questions


Raptor6872

Recommended Posts

Greetings All,

I was making a script that will allow specific groups access to given options for the F10 Menu in multiplayer.

In this example there are 4 groups, (e.g. XX-DRAGON-1-1-XX, ...) as seen in the code below.

 

When the mission starts, I 'DO SCRIPT FILE' and run the following code to no avail.

 

------------------------------------------------------------------
--             CustomLUA F10 Menu for Specific Groups           --
------------------------------------------------------------------

------------------------------------------------------------------
-- https://wiki.hoggitworld.com/view/DCS_func_addCommandForGroup
-- https://wiki.hoggitworld.com/view/DCS_func_addSubMenu
-- https://wiki.hoggitworld.com/view/DCS_func_addSubMenuForGroup
------------------------------------------------------------------

local function successSound() -- Run when called
	trigger.action.outSound("1-success.wav") -- Play sound
end

local function failureSound()
	trigger.action.outSound("2-failure.wav")
end

 
local tbl = {"XX-DRAGON-1-1-XX", "XX-DRAGON-1-2-XX", "XX-DRAGON-1-3-XX", "XX-DRAGON-1-4-XX"} -- List of group names to get menu access
	for i = 1, #tbl do
		if Group.getByName(tbl[i]) then
			local groupId = Group.getByName(tbl[i]):getID
			local adminM = missionCommands.addSubMenuForGroup(groupId, 'ADMIN MENU')
			local soundM = missionCommands.addSubMenuForGroup(groupId, 'Play Sounds', adminM)
			missionCommands.addCommandForGroup(groupId, 'Success', soundM , successSound, tbl[i])
			missionCommands.addCommandForGroup(groupId, 'Failure', soundM , failureSound, tbl[i])
	end
end

 

This code is based off of several links and I'm not quite sure why it does not work. When run in game, after joining the unit of said group, the menu never even shows up...

Any ideas?

DRAGON 1-3 | Raptor [i7-7700K OC 5 GHz CPU | 32 GB DDR4 RAM | RTX 2070S GPU w/ 4GB]

Link to comment
Share on other sites

If you're running the script with a MISSION START trigger, trying changing that to a ONCE trigger with say a TIME MORE(5) condition.

 

Also, in this statement:

 

local groupId = Group.getByName(tbl[i]):getID

 

you may need a set of parentheses at the end, like so:

 

local groupId = Group.getByName(tbl[i]):getID()

Link to comment
Share on other sites

Aside from the missing parenthesis, the script might not be fully protected against nil errors caused by missing groups.

 

I doubt that this line alone will cut it, since it might return true even if the groups aren't actually present (just having them listed in the mission database is enough, I think):

if Group.getByName(tbl[i]) then

 

To make sure, I'd use :isExist() instead (or in addition to it)

if Group.getByName(tbl[i]) and Group.getByName(tbl[i]):isExist() then

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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