Jump to content

LUA Question: addCommandForGroup and MP player groupID


stinkx

Recommended Posts

Hi there,

I have been trying to get together a very simple range script but it seems i have hit a brick wall. Would appreciate any help.

 

We have two planes with pilot names (unit name)

unitNames={'DEBUG_P','MULE_P'}

then we have other functions for starting a run, finishing a run, reporting and resetting scores etc.

 

for simplicity i wanted to add start/reset/report to f10 to avoid dealing with zones etc.

 

here is the code that assigns those functions to each player's f10 menu seperately

function addFuncs(unitNames)
 for _,v in ipairs(unitNames) do
           local LunitName = v
           local unit = Unit.getByName(LunitName)
           if unit then
               local group = unit:getGroup()
               if group then
                   if not funcAddState[LunitName] then
                   trigger.action.outText('added functions to ' .. LunitName, 10)
                   local gid = group:getID()
                   if gid then
                     local _sub = missionCommands.addSubMenuForGroup(gid, "RUN" , nil)                    
                     for _,v in ipairs(targetNames) do
                       local txt= "Run " .. v
                       
                       missionCommands.addCommandForGroup(gid,txt, _sub , startRun, {LunitName, v})
                     end
                     missionCommands.addCommandForGroup(gid,"Reset Stats", nil, resetStats, LunitName)
                     missionCommands.addCommandForGroup(gid,"Display Stats", nil, displayStats, LunitName)
                     funcAddState[LunitName]=true
                   end
                 end
               end
           end
 end
mist.scheduleFunction(addFuncs,{unitNames},timer.getTime() + 5)
end

while

funcAddState={} --the list of planes who has the f10 menu added
for k,v in ipairs(unitNames) do
 funcAddState[v]=false
end

has been initialized at the start

 

 

now the problem is, when we get into the multiplayer, i am unable to feed groupID to the addCommandForGroup because

 

local LunitName = 'DEBUG_P'
local Lunit= Unit.getByName(LunitName)
local Lgroup=Lunit:getGroup()
return Lgroup

and

 local LunitName = 'MULE_P'
local Lunit= Unit.getByName(LunitName)
local Lgroup=Lunit:getGroup()
return Lgroup

returns

{
   "id_": 0
}

for both

 

any ideas on groupID of players during multiplayer, or on workarounds to the addCommandForGroup ?

 

 

PS:btw in singleplayer the proper ids of 1 and 2 are correctly returned

  • Like 1
Link to comment
Share on other sites

Its a known bug that is quite annoying. Simply put none of the Group functions work on anything a client is in. It should work ok if the host is in the group.

 

http://forums.eagle.ru/showthread.php?t=147792

 

31682 - Client groups not accessible in multiplayer.

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

It should. It also works in 1.5 as long as its single player or MP as the host. I know its not ideal, but you can work under the assumption that something like that will get fixed.

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

  • Recently Browsing   0 members

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