mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#DATABASE
* Register players joining CA slots as CLIENTs
This commit is contained in:
commit
166a7ab7db
@ -126,6 +126,8 @@ function DATABASE:New()
|
|||||||
self:SetEventPriority( 1 )
|
self:SetEventPriority( 1 )
|
||||||
|
|
||||||
self:HandleEvent( EVENTS.Birth, self._EventOnBirth )
|
self:HandleEvent( EVENTS.Birth, self._EventOnBirth )
|
||||||
|
-- DCS 2.9 fixed CA event for players -- TODO: reset unit when leaving
|
||||||
|
self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
||||||
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
|
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
|
||||||
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
||||||
self:HandleEvent( EVENTS.RemoveUnit, self._EventOnDeadOrCrash )
|
self:HandleEvent( EVENTS.RemoveUnit, self._EventOnDeadOrCrash )
|
||||||
@ -810,6 +812,7 @@ function DATABASE:AddPlayer( UnitName, PlayerName )
|
|||||||
self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName )
|
self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName )
|
||||||
self.PLAYERSJOINED[PlayerName] = PlayerName
|
self.PLAYERSJOINED[PlayerName] = PlayerName
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Deletes a player from the DATABASE based on the Player Name.
|
--- Deletes a player from the DATABASE based on the Player Name.
|
||||||
@ -1470,39 +1473,43 @@ function DATABASE:_EventOnDeadOrCrash( Event )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Handles the OnPlayerEnterUnit event to fill the active players table (with the unit filter applied).
|
--- Handles the OnPlayerEnterUnit event to fill the active players table for CA units (with the unit filter applied).
|
||||||
-- @param #DATABASE self
|
-- @param #DATABASE self
|
||||||
-- @param Core.Event#EVENTDATA Event
|
-- @param Core.Event#EVENTDATA Event
|
||||||
function DATABASE:_EventOnPlayerEnterUnit( Event )
|
function DATABASE:_EventOnPlayerEnterUnit( Event )
|
||||||
self:F2( { Event } )
|
self:F2( { Event } )
|
||||||
|
|
||||||
if Event.IniDCSUnit then
|
if Event.IniDCSUnit then
|
||||||
if Event.IniObjectCategory == 1 then
|
-- Player entering a CA slot
|
||||||
|
if Event.IniObjectCategory == 1 and Event.IniGroup and Event.IniGroup:IsGround() then
|
||||||
|
|
||||||
-- Add unit.
|
local IsPlayer = Event.IniDCSUnit:getPlayerName()
|
||||||
self:AddUnit( Event.IniDCSUnitName )
|
if IsPlayer then
|
||||||
|
|
||||||
-- Ini unit.
|
-- Debug info.
|
||||||
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
|
self:I(string.format("Player '%s' joined GROUND unit '%s' of group '%s'", tostring(Event.IniPlayerName), tostring(Event.IniDCSUnitName), tostring(Event.IniDCSGroupName)))
|
||||||
|
|
||||||
-- Add group.
|
local client= self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
|
||||||
self:AddGroup( Event.IniDCSGroupName )
|
|
||||||
|
|
||||||
-- Get player unit.
|
-- Add client in case it does not exist already.
|
||||||
local PlayerName = Event.IniDCSUnit:getPlayerName()
|
if not client then
|
||||||
|
client=self:AddClient(Event.IniDCSUnitName)
|
||||||
if PlayerName then
|
|
||||||
|
|
||||||
if not self.PLAYERS[PlayerName] then
|
|
||||||
self:AddPlayer( Event.IniDCSUnitName, PlayerName )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local Settings = SETTINGS:Set( PlayerName )
|
-- Add player.
|
||||||
|
client:AddPlayer(Event.IniPlayerName)
|
||||||
|
|
||||||
|
-- Add player.
|
||||||
|
if not self.PLAYERS[Event.IniPlayerName] then
|
||||||
|
self:AddPlayer( Event.IniUnitName, Event.IniPlayerName )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Player settings.
|
||||||
|
local Settings = SETTINGS:Set( Event.IniPlayerName )
|
||||||
Settings:SetPlayerMenu(Event.IniUnit)
|
Settings:SetPlayerMenu(Event.IniUnit)
|
||||||
|
|
||||||
else
|
|
||||||
self:E("ERROR: getPlayerName() returned nil for event PlayerEnterUnit")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1514,14 +1521,25 @@ end
|
|||||||
function DATABASE:_EventOnPlayerLeaveUnit( Event )
|
function DATABASE:_EventOnPlayerLeaveUnit( Event )
|
||||||
self:F2( { Event } )
|
self:F2( { Event } )
|
||||||
|
|
||||||
|
local function FindPlayerName(UnitName)
|
||||||
|
local playername = nil
|
||||||
|
for _name,_unitname in pairs(self.PLAYERS) do
|
||||||
|
if _unitname == UnitName then
|
||||||
|
playername = _name
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return playername
|
||||||
|
end
|
||||||
|
|
||||||
if Event.IniUnit then
|
if Event.IniUnit then
|
||||||
|
|
||||||
if Event.IniObjectCategory == 1 then
|
if Event.IniObjectCategory == 1 then
|
||||||
|
|
||||||
-- Try to get the player name. This can be buggy for multicrew aircraft!
|
-- Try to get the player name. This can be buggy for multicrew aircraft!
|
||||||
local PlayerName = Event.IniUnit:GetPlayerName()
|
local PlayerName = Event.IniUnit:GetPlayerName() or FindPlayerName(Event.IniUnitName)
|
||||||
|
|
||||||
if PlayerName then --and self.PLAYERS[PlayerName] then
|
if PlayerName then
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:I(string.format("Player '%s' left unit %s", tostring(PlayerName), tostring(Event.IniUnitName)))
|
self:I(string.format("Player '%s' left unit %s", tostring(PlayerName), tostring(Event.IniUnitName)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user