* Add player UCID to event data structure (for multi-player)
This commit is contained in:
Applevangelist 2023-11-07 11:07:28 +01:00
parent c765070401
commit 7f650913d9
3 changed files with 26 additions and 7 deletions

View File

@ -283,6 +283,7 @@ EVENTS = {
-- @field Wrapper.Group#GROUP IniGroup (UNIT) The initiating MOOSE wrapper @{Wrapper.Group#GROUP} of the initiator Group object.
-- @field #string IniGroupName UNIT) The initiating GROUP name (same as IniDCSGroupName).
-- @field #string IniPlayerName (UNIT) The name of the initiating player in case the Unit is a client or player slot.
-- @field #string IniPlayerUCID (UNIT) The UCID of the initiating player in case the Unit is a client or player slot and on a multi-player server.
-- @field DCS#coalition.side IniCoalition (UNIT) The coalition of the initiator.
-- @field DCS#Unit.Category IniCategory (UNIT) The category of the initiator.
-- @field #string IniTypeName (UNIT) The type name of the initiator.
@ -298,6 +299,7 @@ EVENTS = {
-- @field Wrapper.Group#GROUP TgtGroup (UNIT) The target MOOSE wrapper @{Wrapper.Group#GROUP} of the target Group object.
-- @field #string TgtGroupName (UNIT) The target GROUP name (same as TgtDCSGroupName).
-- @field #string TgtPlayerName (UNIT) The name of the target player in case the Unit is a client or player slot.
-- @field #string TgtPlayerUCID (UNIT) The UCID of the target player in case the Unit is a client or player slot and on a multi-player server.
-- @field DCS#coalition.side TgtCoalition (UNIT) The coalition of the target.
-- @field DCS#Unit.Category TgtCategory (UNIT) The category of the target.
-- @field #string TgtTypeName (UNIT) The type name of the target.
@ -1145,6 +1147,14 @@ function EVENT:onEvent( Event )
end
Event.IniPlayerName = Event.IniDCSUnit:getPlayerName()
if Event.IniPlayerName then
-- get UUCID
local PID = NET.GetPlayerIDByName(nil,Event.IniPlayerName)
if PID then
Event.IniPlayerUCID = net.get_player_info(tonumber(PID), 'ucid')
--env.info("Event.IniPlayerUCID="..tostring(Event.IniPlayerUCID),false)
end
end
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
Event.IniCategory = Event.IniDCSUnit:getDesc().category
@ -1217,6 +1227,14 @@ function EVENT:onEvent( Event )
Event.TgtGroupName = Event.TgtDCSGroupName
end
Event.TgtPlayerName = Event.TgtDCSUnit:getPlayerName()
if Event.TgtPlayerName then
-- get UUCID
local PID = NET.GetPlayerIDByName(nil,Event.TgtPlayerName)
if PID then
Event.TgtPlayerUCID = net.get_player_info(tonumber(PID), 'ucid')
--env.info("Event.TgtPlayerUCID="..tostring(Event.TgtPlayerUCID),false)
end
end
Event.TgtCoalition = Event.TgtDCSUnit:getCoalition()
Event.TgtCategory = Event.TgtDCSUnit:getDesc().category
Event.TgtTypeName = Event.TgtDCSUnit:getTypeName()

View File

@ -441,19 +441,22 @@ UTILS.BasicSerialize = function(s)
end
end
--- Print a table to log in a nice format
-- @param #table table The table to print
-- @param #number ident Number of idents
function UTILS.PrintTableToLog(table, indent)
if not table then
BASE:E("No table passed!")
env.warning("No table passed!")
return
end
if not indent then indent = 0 end
for k, v in pairs(table) do
if type(v) == "table" then
BASE:I(string.rep(" ", indent) .. tostring(k) .. " = {")
env.info(string.rep(" ", indent) .. tostring(k) .. " = {")
UTILS.PrintTableToLog(v, indent + 1)
BASE:I(string.rep(" ", indent) .. "}")
env.info(string.rep(" ", indent) .. "}")
else
BASE:I(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(v))
env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(v))
end
end
end

View File

@ -470,11 +470,9 @@ end
-- @return #number PlayerID or nil
function NET:GetPlayerIDByName(Name)
if not Name then return nil end
local playerList = self:GetPlayerList()
self:T({playerList})
local playerList = net.get_player_list()
for i=1,#playerList do
local playerName = net.get_name(i)
self:T({playerName})
if playerName == Name then
return playerList[i]
end