mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-20 06:52:03 +00:00
Check players
This commit is contained in:
@@ -51,6 +51,7 @@ DATABASE = {
|
|||||||
ClientsByID = {},
|
ClientsByID = {},
|
||||||
},
|
},
|
||||||
UNITS = {},
|
UNITS = {},
|
||||||
|
UNITS_Index = {},
|
||||||
STATICS = {},
|
STATICS = {},
|
||||||
GROUPS = {},
|
GROUPS = {},
|
||||||
PLAYERS = {},
|
PLAYERS = {},
|
||||||
@@ -99,7 +100,7 @@ function DATABASE:New()
|
|||||||
self:HandleEvent( EVENTS.DeleteCargo )
|
self:HandleEvent( EVENTS.DeleteCargo )
|
||||||
|
|
||||||
-- Follow alive players and clients
|
-- Follow alive players and clients
|
||||||
self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
-- self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
||||||
self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
|
self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
|
||||||
|
|
||||||
self:_RegisterTemplates()
|
self:_RegisterTemplates()
|
||||||
@@ -109,6 +110,33 @@ function DATABASE:New()
|
|||||||
self:_RegisterPlayers()
|
self:_RegisterPlayers()
|
||||||
self:_RegisterAirbases()
|
self:_RegisterAirbases()
|
||||||
|
|
||||||
|
self.UNITS_Position = 0
|
||||||
|
|
||||||
|
--- @param Wrapper.Unit#UNIT PlayerUnit
|
||||||
|
local function CheckPlayers( self )
|
||||||
|
|
||||||
|
local UNITS_Count = #self.UNITS_Index
|
||||||
|
if UNITS_Count > 0 then
|
||||||
|
self.UNITS_Position = ( ( self.UNITS_Position <= UNITS_Count ) and self.UNITS_Position + 1 ) or 1
|
||||||
|
local PlayerUnit = self.UNITS[self.UNITS_Index[self.UNITS_Position]]
|
||||||
|
if PlayerUnit then
|
||||||
|
local UnitName = PlayerUnit:GetName()
|
||||||
|
local PlayerName = PlayerUnit:GetPlayerName()
|
||||||
|
self:E( { UNITS_Count, self.UNITS_Position, UnitName, PlayerName } )
|
||||||
|
if PlayerName and PlayerName ~= "" then
|
||||||
|
if not self.PLAYERS[PlayerName] or self.PLAYERS[PlayerName] ~= PlayerUnit then
|
||||||
|
self:E( { "Add player for unit:", UnitName, PlayerName } )
|
||||||
|
self:AddPlayer( UnitName, PlayerName )
|
||||||
|
_EVENTDISPATCHER:CreateEventPlayerEnterUnit( PlayerUnit )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self:E( "Scheduling" )
|
||||||
|
local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.05 )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -130,6 +158,8 @@ function DATABASE:AddUnit( DCSUnitName )
|
|||||||
if not self.UNITS[DCSUnitName] then
|
if not self.UNITS[DCSUnitName] then
|
||||||
local UnitRegister = UNIT:Register( DCSUnitName )
|
local UnitRegister = UNIT:Register( DCSUnitName )
|
||||||
self.UNITS[DCSUnitName] = UNIT:Register( DCSUnitName )
|
self.UNITS[DCSUnitName] = UNIT:Register( DCSUnitName )
|
||||||
|
|
||||||
|
table.insert( self.UNITS_Index, DCSUnitName )
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.UNITS[DCSUnitName]
|
return self.UNITS[DCSUnitName]
|
||||||
@@ -140,7 +170,7 @@ end
|
|||||||
-- @param #DATABASE self
|
-- @param #DATABASE self
|
||||||
function DATABASE:DeleteUnit( DCSUnitName )
|
function DATABASE:DeleteUnit( DCSUnitName )
|
||||||
|
|
||||||
--self.UNITS[DCSUnitName] = nil
|
self.UNITS[DCSUnitName] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Adds a Static based on the Static Name in the DATABASE.
|
--- Adds a Static based on the Static Name in the DATABASE.
|
||||||
|
|||||||
@@ -730,6 +730,21 @@ do -- Event Creation
|
|||||||
world.onEvent( Event )
|
world.onEvent( Event )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Creation of a S_EVENT_PLAYER_ENTER_UNIT Event.
|
||||||
|
-- @param #EVENT self
|
||||||
|
-- @param Wrapper.Unit#UNIT PlayerUnit.
|
||||||
|
function EVENT:CreateEventPlayerEnterUnit( PlayerUnit )
|
||||||
|
self:F( { PlayerUnit } )
|
||||||
|
|
||||||
|
local Event = {
|
||||||
|
id = EVENTS.PlayerEnterUnit,
|
||||||
|
time = timer.getTime(),
|
||||||
|
initiator = PlayerUnit:GetDCSObject()
|
||||||
|
}
|
||||||
|
|
||||||
|
world.onEvent( Event )
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param #EVENT self
|
--- @param #EVENT self
|
||||||
@@ -749,8 +764,6 @@ function EVENT:onEvent( Event )
|
|||||||
|
|
||||||
local EventMeta = _EVENTMETA[Event.id]
|
local EventMeta = _EVENTMETA[Event.id]
|
||||||
|
|
||||||
self:E( { EventMeta.Text, Event } )
|
|
||||||
|
|
||||||
if self and self.Events and self.Events[Event.id] then
|
if self and self.Events and self.Events[Event.id] then
|
||||||
|
|
||||||
if Event.initiator then
|
if Event.initiator then
|
||||||
|
|||||||
Reference in New Issue
Block a user