mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Fixes for getPlayername() errors
This commit is contained in:
parent
9869dbd95a
commit
07c3be9d6a
@ -26,9 +26,9 @@
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **[funkyfranky](https://forums.eagle.ru/member.php?u=115026)**
|
||||
-- ### Author: **funkyfranky**
|
||||
--
|
||||
-- ### Contributions: [FlightControl](https://forums.eagle.ru/member.php?u=89536)
|
||||
-- ### Contributions: FlightControl, Applevangelist
|
||||
--
|
||||
-- ====
|
||||
-- @module Functional.PseudoATC
|
||||
@ -44,7 +44,7 @@
|
||||
-- @field #number mrefresh Interval in seconds after which the F10 menu is refreshed. E.g. by the closest airports. Default is 120 sec.
|
||||
-- @field #number talt Interval in seconds between reporting altitude until touchdown. Default 3 sec.
|
||||
-- @field #boolean chatty Display some messages on events like take-off and touchdown.
|
||||
-- @field #boolean eventsmoose If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler.
|
||||
-- @field #boolean eventsmoose [Deprecated] If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler.
|
||||
-- @field #boolean reportplayername If true, use playername not callsign on callouts
|
||||
-- @extends Core.Base#BASE
|
||||
|
||||
@ -100,13 +100,14 @@ PSEUDOATC.id="PseudoATC | "
|
||||
|
||||
--- PSEUDOATC version.
|
||||
-- @field #number version
|
||||
PSEUDOATC.version="0.9.5"
|
||||
PSEUDOATC.version="0.10.5"
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO list
|
||||
-- DONE: Add takeoff event.
|
||||
-- DONE: Add user functions.
|
||||
-- DONE: Refactor to use Moose event handling only
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -131,23 +132,14 @@ function PSEUDOATC:Start()
|
||||
self:F()
|
||||
|
||||
-- Debug info
|
||||
self:E(PSEUDOATC.id.."Starting PseudoATC")
|
||||
self:I(PSEUDOATC.id.."Starting PseudoATC")
|
||||
|
||||
-- Handle events.
|
||||
if self.eventsmoose then
|
||||
self:T(PSEUDOATC.id.."Events are handled by MOOSE.")
|
||||
self:HandleEvent(EVENTS.Birth, self._OnBirth)
|
||||
self:HandleEvent(EVENTS.Land, self._PlayerLanded)
|
||||
self:HandleEvent(EVENTS.Takeoff, self._PlayerTakeOff)
|
||||
self:HandleEvent(EVENTS.PlayerLeaveUnit, self._PlayerLeft)
|
||||
self:HandleEvent(EVENTS.Crash, self._PlayerLeft)
|
||||
--self:HandleEvent(EVENTS.Ejection, self._PlayerLeft)
|
||||
--self:HandleEvent(EVENTS.PilotDead, self._PlayerLeft)
|
||||
else
|
||||
self:T(PSEUDOATC.id.."Events are handled by DCS.")
|
||||
-- Events are handled directly by DCS.
|
||||
world.addEventHandler(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -199,7 +191,7 @@ function PSEUDOATC:SetMenuRefresh(interval)
|
||||
self.mrefresh=interval or 120
|
||||
end
|
||||
|
||||
--- Enable/disable event handling by MOOSE or DCS.
|
||||
--- [Deprecated] Enable/disable event handling by MOOSE or DCS.
|
||||
-- @param #PSEUDOATC self
|
||||
-- @param #boolean switch If true, events are handled by MOOSE (default). If false, events are handled directly by DCS.
|
||||
function PSEUDOATC:SetEventsMoose(switch)
|
||||
@ -216,84 +208,6 @@ end
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Event Handling
|
||||
|
||||
--- Event handler for suppressed groups.
|
||||
--@param #PSEUDOATC self
|
||||
--@param #table Event Event data table. Holds event.id, event.initiator and event.target etc.
|
||||
function PSEUDOATC:onEvent(Event)
|
||||
if Event == nil or Event.initiator == nil or Unit.getByName(Event.initiator:getName()) == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
local DCSiniunit = Event.initiator
|
||||
local DCSplace = Event.place
|
||||
local DCSsubplace = Event.subplace
|
||||
|
||||
local EventData={}
|
||||
local _playerunit=nil
|
||||
local _playername=nil
|
||||
|
||||
if Event.initiator then
|
||||
EventData.IniUnitName = Event.initiator:getName()
|
||||
EventData.IniDCSGroup = Event.initiator:getGroup()
|
||||
EventData.IniGroupName = Event.initiator:getGroup():getName()
|
||||
-- Get player unit and name. This returns nil,nil if the event was not fired by a player unit. And these are the only events we are interested in.
|
||||
_playerunit, _playername = self:_GetPlayerUnitAndName(EventData.IniUnitName)
|
||||
end
|
||||
|
||||
if Event.place then
|
||||
EventData.Place=Event.place
|
||||
EventData.PlaceName=Event.place:getName()
|
||||
end
|
||||
if Event.subplace then
|
||||
EventData.SubPlace=Event.subplace
|
||||
EventData.SubPlaceName=Event.subplace:getName()
|
||||
end
|
||||
|
||||
-- Event info.
|
||||
self:T3(PSEUDOATC.id..string.format("EVENT: Event in onEvent with ID = %s", tostring(Event.id)))
|
||||
self:T3(PSEUDOATC.id..string.format("EVENT: Ini unit = %s" , tostring(EventData.IniUnitName)))
|
||||
self:T3(PSEUDOATC.id..string.format("EVENT: Ini group = %s" , tostring(EventData.IniGroupName)))
|
||||
self:T3(PSEUDOATC.id..string.format("EVENT: Ini player = %s" , tostring(_playername)))
|
||||
self:T3(PSEUDOATC.id..string.format("EVENT: Place = %s" , tostring(EventData.PlaceName)))
|
||||
self:T3(PSEUDOATC.id..string.format("EVENT: SubPlace = %s" , tostring(EventData.SubPlaceName)))
|
||||
|
||||
-- Event birth.
|
||||
if Event.id == world.event.S_EVENT_BIRTH and _playername then
|
||||
self:_OnBirth(EventData)
|
||||
end
|
||||
|
||||
-- Event takeoff.
|
||||
if Event.id == world.event.S_EVENT_TAKEOFF and _playername and EventData.Place then
|
||||
self:_PlayerTakeOff(EventData)
|
||||
end
|
||||
|
||||
-- Event land.
|
||||
if Event.id == world.event.S_EVENT_LAND and _playername and EventData.Place then
|
||||
self:_PlayerLanded(EventData)
|
||||
end
|
||||
|
||||
-- Event player left unit
|
||||
if Event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and _playername then
|
||||
self:_PlayerLeft(EventData)
|
||||
end
|
||||
|
||||
-- Event crash ==> player left unit
|
||||
if Event.id == world.event.S_EVENT_CRASH and _playername then
|
||||
self:_PlayerLeft(EventData)
|
||||
end
|
||||
|
||||
--[[
|
||||
-- Event eject ==> player left unit
|
||||
if Event.id == world.event.S_EVENT_EJECTION and _playername then
|
||||
self:_PlayerLeft(EventData)
|
||||
end
|
||||
|
||||
-- Event pilot dead ==> player left unit
|
||||
if Event.id == world.event.S_EVENT_PILOT_DEAD and _playername then
|
||||
self:_PlayerLeft(EventData)
|
||||
end
|
||||
]]
|
||||
end
|
||||
|
||||
--- Function called my MOOSE event handler when a player enters a unit.
|
||||
-- @param #PSEUDOATC self
|
||||
@ -303,7 +217,9 @@ function PSEUDOATC:_OnBirth(EventData)
|
||||
|
||||
-- Get unit and player.
|
||||
local _unitName=EventData.IniUnitName
|
||||
local _unit, _playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
--local _unit, _playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
local _unit = EventData.IniUnit
|
||||
local _playername = EventData.IniPlayerName
|
||||
|
||||
-- Check if a player entered.
|
||||
if _unit and _playername then
|
||||
@ -320,7 +236,10 @@ function PSEUDOATC:_PlayerLeft(EventData)
|
||||
|
||||
-- Get unit and player.
|
||||
local _unitName=EventData.IniUnitName
|
||||
local _unit, _playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
--local _unit, _playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
|
||||
local _unit = EventData.IniUnit
|
||||
local _playername = EventData.IniPlayerName
|
||||
|
||||
-- Check if a player left.
|
||||
if _unit and _playername then
|
||||
@ -336,17 +255,15 @@ function PSEUDOATC:_PlayerLanded(EventData)
|
||||
|
||||
-- Get unit, player and place.
|
||||
local _unitName=EventData.IniUnitName
|
||||
local _unit, _playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
local _unit = EventData.IniUnit
|
||||
local _playername = EventData.IniPlayerName
|
||||
--local _unit, _playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
local _base=nil
|
||||
local _baseName=nil
|
||||
if EventData.place then
|
||||
_base=EventData.place
|
||||
_baseName=EventData.place:getName()
|
||||
end
|
||||
-- if EventData.subplace then
|
||||
-- local _subPlace=EventData.subplace
|
||||
-- local _subPlaceName=EventData.subplace:getName()
|
||||
-- end
|
||||
|
||||
-- Call landed function.
|
||||
if _unit and _playername and _base then
|
||||
@ -362,7 +279,9 @@ function PSEUDOATC:_PlayerTakeOff(EventData)
|
||||
|
||||
-- Get unit, player and place.
|
||||
local _unitName=EventData.IniUnitName
|
||||
local _unit,_playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
local _unit = EventData.IniUnit
|
||||
local _playername = EventData.IniPlayerName
|
||||
--local _unit,_playername=self:_GetPlayerUnitAndName(_unitName)
|
||||
local _base=nil
|
||||
local _baseName=nil
|
||||
if EventData.place then
|
||||
@ -450,9 +369,6 @@ function PSEUDOATC:PlayerLanded(unit, place)
|
||||
local group=unit:GetGroup()
|
||||
local GID=group:GetID()
|
||||
local UID=unit:GetDCSObject():getID()
|
||||
--local PlayerName=self.group[GID].player[UID].playername
|
||||
--local UnitName=self.group[GID].player[UID].unitname
|
||||
--local GroupName=self.group[GID].player[UID].groupname
|
||||
local PlayerName = unit:GetPlayerName() or "Ghost"
|
||||
local UnitName = unit:GetName() or "Ghostplane"
|
||||
local GroupName = group:GetName() or "Ghostgroup"
|
||||
@ -483,12 +399,6 @@ function PSEUDOATC:PlayerTakeOff(unit, place)
|
||||
|
||||
-- Gather some information.
|
||||
local group=unit:GetGroup()
|
||||
--local GID=group:GetID()
|
||||
--local UID=unit:GetDCSObject():getID()
|
||||
--local PlayerName=self.group[GID].player[UID].playername
|
||||
--local CallSign=self.group[GID].player[UID].callsign
|
||||
--local UnitName=self.group[GID].player[UID].unitname
|
||||
--local GroupName=self.group[GID].player[UID].groupname
|
||||
local PlayerName = unit:GetPlayerName() or "Ghost"
|
||||
local UnitName = unit:GetName() or "Ghostplane"
|
||||
local GroupName = group:GetName() or "Ghostgroup"
|
||||
@ -926,7 +836,7 @@ function PSEUDOATC:AltitudeTimeStart(GID, UID)
|
||||
self:T(PSEUDOATC.id..string.format("Starting altitude report timer for player ID %d.", UID))
|
||||
|
||||
-- Start timer. Altitude is reported every ~3 seconds.
|
||||
self.group[GID].player[UID].altimer, self.group[GID].player[UID].altimerid=SCHEDULER:New(nil, self.ReportHeight, {self, GID, UID, 0.1, true}, 1, 3)
|
||||
self.group[GID].player[UID].altimer, self.group[GID].player[UID].altimerid=SCHEDULER:New(nil, self.ReportHeight, {self, GID, UID, 1, true}, 1, 3)
|
||||
end
|
||||
|
||||
--- Stop/destroy DCS scheduler function for reporting altitude.
|
||||
|
||||
@ -8115,6 +8115,8 @@ function AIRBOSS:OnEventBirth( EventData )
|
||||
return
|
||||
end
|
||||
|
||||
if EventData.IniObjectCategory ~= Object.Category.UNIT then return end
|
||||
|
||||
local _unitName = EventData.IniUnitName
|
||||
local _unit, _playername = self:_GetPlayerUnitAndName( _unitName )
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user