Jump to content

Identifying user of F10 command


Ahmed

Recommended Posts

Hello,

 

I posted this on Discord but never got an answer so lets try here. I assume this has already been requested before, but just in case.

 

The scripting functions addCommand addCommandForCoalition and addCommandForGroup have no way of identifying what player used the command in MP.

 

The most elegant solution would be for the callback function to receive a second parameter with the player or unit that used the command and that's what I'd like to request.

 

At the moment there is no workaround to identify the player other than e xtremely messy half-solutions.

 

Thanks,

Link to comment
Share on other sites

@Ahmed

 

Make sure that you only have a single client in each group, this way you'll always know which unit triggered the menu command.

 

Then...

 

Option #1 - Link that F10 menu to an event, then pass the initiator unit as argument:

local function Command_Function(Initiator)
   [color="Blue"]-- Do stuff using initiator unit object[/color]
end


local Handler = {}

function Handler:onEvent(event)

   if  event.id == world.event.S_EVENT_BIRTH and event.initiator:getCategory() == Object.Category.UNIT then
      
      if  event.initiator:getPlayerName() then
         
          local Grp = event.initiator:getGroup()
          local Grp_ID = Grp:getID()
          local Initiator = event.initiator
         
          Main =  missionCommands.addSubMenuForGroup(Grp_ID, "Group Menu")
          Command = missionCommands.addCommandForGroup(Grp_ID, "Group Command", Main, Command_Function, Initiator)[color="blue"] -- Pass Initiator as argument[/color]
      end
   end
end

world.addEventHandler(Handler) 

 

 

Option #2 - Include all relevant clients in a set, then iterate the set, creating a group menu for each one of them, passing the client unit and/or player name as argument (MOOSE example):

local function Command_Function(Client , Player_Name)
   [color="Blue"]-- Do stuff using the client object (unit) and/or the player name[/color]
end


local Client_SET = SET_CLIENT:New():FilterActive(Active):FilterPrefixes("[color="Red"]common client prefix/suffix[/color]"):FilterStart()

  Client_SET:ForEachClient(
  function(Client)
     
     local Grp = Client:GetGroup()
     local Player_Name = Client:GetPlayerName()
     
      Main = MENU_GROUP:New(Grp , "Group Menu")
      Command = MENU_GROUP_COMMAND:New(Grp , "Group Command" , Main , Command_Function , Client , Player_Name) [color="Blue"]-- Pass client object (unit) and player name as arguments[/color]
      end
  end
  )


Edited by Hardcard
Link to comment
Share on other sites

@Ahmed

 

Make sure that you only have a single client in each group, this way you'll always know which unit triggered the menu command.

 

Thanks, I have been using a similar solution. But this is exactly what I meant with half-solutions. Having only one client per group has side-effects on things like not showing wingmen as such on the F18 SA page or callsign issues.

 

The issue should be fixed at its root by ED without having to take these kind of compromises of losing core system functionalities (or adding a submenu for each client on the group that is the other messy workaround)


Edited by Ahmed
Link to comment
Share on other sites

  • Recently Browsing   0 members

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