mirror of
https://github.com/ciribob/DCS-CTLD.git
synced 2025-08-15 06:17:22 +00:00
bug: corrected the way we handle dynamic slots; it used to cause random CTDs
This commit is contained in:
39
CTLD.lua
39
CTLD.lua
@@ -35,7 +35,7 @@ ctld = {} -- DONT REMOVE!
|
|||||||
ctld.Id = "CTLD - "
|
ctld.Id = "CTLD - "
|
||||||
|
|
||||||
--- Version.
|
--- Version.
|
||||||
ctld.Version = "1.2.1"
|
ctld.Version = "1.2.2"
|
||||||
|
|
||||||
-- To add debugging messages to dcs.log, change the following log levels to `true`; `Debug` is less detailed than `Trace`
|
-- To add debugging messages to dcs.log, change the following log levels to `true`; `Debug` is less detailed than `Trace`
|
||||||
ctld.Debug = false
|
ctld.Debug = false
|
||||||
@@ -8143,40 +8143,47 @@ end
|
|||||||
--- Handle world events.
|
--- Handle world events.
|
||||||
ctld.eventHandler = {}
|
ctld.eventHandler = {}
|
||||||
function ctld.eventHandler:onEvent(event)
|
function ctld.eventHandler:onEvent(event)
|
||||||
ctld.logTrace("ctld.eventHandler:onEvent(), event = %s", ctld.p(event))
|
ctld.logTrace("ctld.eventHandler:onEvent()")
|
||||||
if event == nil then
|
if event == nil then
|
||||||
ctld.logError("Event handler was called with a nil event!")
|
ctld.logError("Event handler was called with a nil event!")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local eventName = "unknown"
|
||||||
-- check that we know the event
|
-- check that we know the event
|
||||||
if event.id ~= 20 then -- S_EVENT_PLAYER_ENTER_UNIT
|
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
|
||||||
|
eventName = "S_EVENT_PLAYER_ENTER_UNIT"
|
||||||
|
elseif event.id == world.event.S_EVENT_BIRTH then
|
||||||
|
eventName = "S_EVENT_BIRTH"
|
||||||
|
else
|
||||||
|
ctld.logTrace("Ignoring event %s", ctld.p(event))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
ctld.logDebug("caught event %s: %s", ctld.p(eventName), ctld.p(event))
|
||||||
|
|
||||||
-- find the originator unit
|
-- find the originator unit
|
||||||
local unitName = nil
|
local unitName = nil
|
||||||
if event.initiator ~= nil and event.initiator.getName then
|
if event.initiator ~= nil and event.initiator.getName then
|
||||||
unitName = event.initiator:getName()
|
unitName = event.initiator:getName()
|
||||||
ctld.logDebug("caught event S_EVENT_PLAYER_ENTER_UNIT for unit [%s]", ctld.p(unitName))
|
ctld.logDebug("unitName = [%s]", ctld.p(unitName))
|
||||||
end
|
end
|
||||||
if not unitName then
|
if not unitName then
|
||||||
ctld.logWarning("no unitname found in event %s", ctld.p(event))
|
ctld.logInfo("no unitname found in event %s", ctld.p(event))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local nextSteps = coroutine.create(function()
|
local function processHumanPlayer()
|
||||||
ctld.logTrace("in the 'nextSteps' coroutine")
|
ctld.logTrace("in the 'processHumanPlayer' function")
|
||||||
if mist.DBs.humansByName[unitName] then -- it's a human unit
|
if mist.DBs.humansByName[unitName] then -- it's a human unit
|
||||||
ctld.logDebug("caught event S_EVENT_PLAYER_ENTER_UNIT for human unit [%s]", ctld.p(unitName))
|
ctld.logDebug("caught event %s for human unit [%s]", ctld.p(eventName), ctld.p(unitName))
|
||||||
local _unit = Unit.getByName(unitName)
|
local _unit = Unit.getByName(unitName)
|
||||||
if _unit ~= nil then
|
if _unit ~= nil then
|
||||||
-- assign transport pilot
|
-- assign transport pilot
|
||||||
ctld.logTrace("_unit = %s", ctld.p(_unit))
|
ctld.logTrace("_unit = %s", ctld.p(_unit))
|
||||||
|
|
||||||
local playerTypeName = _unit:getTypeName()
|
local playerTypeName = _unit:getTypeName()
|
||||||
ctld.logTrace("playerTypeName = %s", ctld.p(playerTypeName))
|
ctld.logTrace("playerTypeName = %s", ctld.p(playerTypeName))
|
||||||
|
|
||||||
-- Allow units to CTLD by aircraft type and not by pilot name
|
-- Allow units to CTLD by aircraft type and not by pilot name
|
||||||
if ctld.addPlayerAircraftByType then
|
if ctld.addPlayerAircraftByType then
|
||||||
for _,aircraftType in pairs(ctld.aircraftTypeTable) do
|
for _,aircraftType in pairs(ctld.aircraftTypeTable) do
|
||||||
@@ -8201,18 +8208,18 @@ function ctld.eventHandler:onEvent(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
if not mist.DBs.humansByName[unitName] then
|
if not mist.DBs.humansByName[unitName] then
|
||||||
-- give a few milliseconds for MiST to handle the BIRTH event too
|
-- give a few milliseconds for MiST to handle the BIRTH event too
|
||||||
ctld.logTrace("give MiST some time to handle the BIRTH event too")
|
ctld.logTrace("give MiST some time to handle the BIRTH event too")
|
||||||
timer.scheduleFunction(function()
|
timer.scheduleFunction(function()
|
||||||
ctld.logTrace("resuming the 'nextSteps' coroutine in a timer")
|
ctld.logTrace("calling the 'processHumanPlayer' function in a timer")
|
||||||
coroutine.resume(nextSteps)
|
processHumanPlayer()
|
||||||
end, nil, timer.getTime() + 0.5)
|
end, nil, timer.getTime()+0.5)
|
||||||
else
|
else
|
||||||
ctld.logTrace("resuming the 'nextSteps' coroutine immediately")
|
ctld.logTrace("calling the 'processHumanPlayer' function immediately")
|
||||||
coroutine.resume(nextSteps)
|
processHumanPlayer()
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user