This commit is contained in:
Frank 2020-12-31 17:17:15 +01:00
parent f725039da5
commit 787151597c
2 changed files with 76 additions and 21 deletions

View File

@ -468,6 +468,8 @@ end
--- Adds a CLIENT based on the ClientName in the DATABASE.
-- @param #DATABASE self
-- @param #string ClientName Name of the Client unit.
-- @return Wrapper.Client#CLIENT The client object.
function DATABASE:AddClient( ClientName )
if not self.CLIENTS[ClientName] then
@ -863,7 +865,7 @@ end
function DATABASE:_RegisterClients()
for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do
self:I(string.format("Register Client %s", tostring(ClientName)))
self:I(string.format("Register Client: %s", tostring(ClientName)))
self:AddClient( ClientName )
end
@ -968,16 +970,28 @@ function DATABASE:_EventOnBirth( Event )
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
-- TODO: create event ClientAlive
local client=self.CLIENTS[Event.IniDCSUnitName] --Wrapper.Client#CLIENT
if client then
end
-- Get player name.
local PlayerName = Event.IniUnit:GetPlayerName()
if PlayerName then
-- Debug info.
self:I(string.format("Player %s joint unit %s of group %s", tostring(PlayerName), tostring(Event.IniDCSUnitName), tostring(Event.IniDCSGroupName)))
self:I(string.format("Player '%s' joint unit '%s' of group '%s'", tostring(PlayerName), tostring(Event.IniDCSUnitName), tostring(Event.IniDCSGroupName)))
-- Add client.
self:AddClient( Event.IniDCSUnitName )
-- Add client in case it does not exist already.
if not client then
client=self:AddClient(Event.IniDCSUnitName)
end
-- Add player.
client:AddPlayer(PlayerName)
-- Add player.
if not self.PLAYERS[PlayerName] then
@ -988,10 +1002,9 @@ function DATABASE:_EventOnBirth( Event )
local Settings = SETTINGS:Set( PlayerName )
Settings:SetPlayerMenu(Event.IniUnit)
end
if PlayerName or self.CLIENTS[Event.IniDCSUnitName] then
-- Create an event.
self:CreateEventPlayerEnterAircraft(Event.IniUnit)
end
end

View File

@ -67,6 +67,7 @@ CLIENT = {
_Menus = {},
_Tasks = {},
Messages = {},
Players = {},
}
@ -146,11 +147,6 @@ function CLIENT:Register( ClientName )
self.MessageSwitch = true
self.ClientAlive2 = false
--self.AliveCheckScheduler = routines.scheduleFunction( self._AliveCheckScheduler, { self }, timer.getTime() + 1, 5 )
self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. ClientName }, 1, 5, 0.5 )
self.AliveCheckScheduler:NoTrace()
self:F( self )
return self
end
@ -159,29 +155,68 @@ end
-- @param #CLIENT self
-- @return #CLIENT self
function CLIENT:Transport()
self:F()
self.ClientTransport = true
return self
end
--- AddBriefing adds a briefing to a CLIENT when a player joins a mission.
--- Adds a briefing to a CLIENT when a player joins a mission.
-- @param #CLIENT self
-- @param #string ClientBriefing is the text defining the Mission briefing.
-- @return #CLIENT self
function CLIENT:AddBriefing( ClientBriefing )
self:F( ClientBriefing )
self.ClientBriefing = ClientBriefing
self.ClientBriefingShown = false
return self
end
--- Add player name.
-- @param #CLIENT self
-- @param #string PlayerName Name of the player.
-- @return #CLIENT self
function CLIENT:AddPlayer(PlayerName)
table.insert(self.Players, PlayerName)
return self
end
--- Get player name(s).
-- @param #CLIENT self
-- @return #table List of player names.
function CLIENT:GetPlayers()
return self.Players
end
--- Get name of player.
-- @param #CLIENT self
-- @return #
function CLIENT:GetPlayer()
return self.Players[1]
end
--- Remove player.
-- @param #CLIENT self
-- @param #string PlayerName Name of the player.
-- @return #CLIENT self
function CLIENT:RemovePlayer(PlayerName)
for i,playername in pairs(self.Players) do
if PlayerName==playername then
table.remove(self.Players, i)
break
end
end
return self
end
--- Show the briefing of a CLIENT.
-- @param #CLIENT self
-- @return #CLIENT self
function CLIENT:ShowBriefing()
self:F( { self.ClientName, self.ClientBriefingShown } )
if not self.ClientBriefingShown then
self.ClientBriefingShown = true
@ -252,6 +287,9 @@ function CLIENT:Alive( CallBackFunction, ... )
self.ClientCallBack = CallBackFunction
self.ClientParameters = arg
self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. self.ClientName }, 0.1, 5, 0.5 )
self.AliveCheckScheduler:NoTrace()
return self
end
@ -259,6 +297,8 @@ end
function CLIENT:_AliveCheckScheduler( SchedulerName )
self:F3( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
env.info("FF client alive scheduler")
if self:IsAlive() then
if self.ClientAlive2 == false then
self:ShowBriefing()
@ -388,11 +428,13 @@ function CLIENT:GetClientGroupUnit()
local ClientDCSUnit = Unit.getByName( self.ClientName )
self:T( self.ClientDCSUnit )
if ClientDCSUnit and ClientDCSUnit:isExist() then
if ClientDCSUnit then -- and ClientDCSUnit:isExist() then
local ClientUnit=_DATABASE:FindUnit( self.ClientName )
self:T2( ClientUnit )
return ClientUnit
end
return nil
end
--- Returns the DCSUnit of the CLIENT.