Compare commits

...

2 Commits

Author SHA1 Message Date
David Pierron c9270a0fd2 changed the code that looks for nearby units (#163) 2025-09-10 14:39:58 +02:00
David Pierron def40f440c added coff.ee information to the readme 2025-07-31 08:47:54 +02:00
2 changed files with 212 additions and 213 deletions
+9 -12
View File
@@ -40,7 +40,7 @@ end
ctld.Id = "CTLD - " ctld.Id = "CTLD - "
--- Version. --- Version.
ctld.Version = "1.5.1" ctld.Version = "1.5.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
@@ -1998,11 +1998,13 @@ function ctld.getNearbyUnits(_point, _radius, _coalition)
local unitsByDistance = {} local unitsByDistance = {}
local cpt = 1 local cpt = 1
local _units = {} local _units = {}
local _unitList = mist.DBs.unitsByName for _unitName, _ in pairs(mist.DBs.unitsByName) do
for _unitName, _unit in pairs(mist.DBs.unitsByName) do
local u = Unit.getByName(_unitName) local u = Unit.getByName(_unitName)
if u and u:isExist() and (_coalition == 4 or u:getCoalition() == _coalition) then local e = (u and u:isExist()) or false
--local _dist = ctld.getDistance(u:getPoint(), _point) -- pcall is needed because getCoalition() fails if the unit is an object without coalition (like a smoke effect)
local c = nil
pcall(function() c = (u and e and u:getCoalition()) or nil end)
if u and e and (_coalition == 4 or c == _coalition) then
local _dist = mist.utils.get2DDist(u:getPoint(), _point) local _dist = mist.utils.get2DDist(u:getPoint(), _point)
if _dist <= _radius then if _dist <= _radius then
unitsByDistance[cpt] = {id =cpt, dist = _dist, unit = _unitName, typeName = u:getTypeName()} unitsByDistance[cpt] = {id =cpt, dist = _dist, unit = _unitName, typeName = u:getTypeName()}
@@ -5864,7 +5866,6 @@ end
-- Adds menuitem to a human unit -- Adds menuitem to a human unit
function ctld.addTransportF10MenuOptions(_unitName) function ctld.addTransportF10MenuOptions(_unitName)
ctld.logDebug("ctld.addTransportF10MenuOptions(_unitName=[%s])", ctld.p(_unitName)) ctld.logDebug("ctld.addTransportF10MenuOptions(_unitName=[%s])", ctld.p(_unitName))
local status, error = pcall(function()
local _unit = ctld.getTransportUnit(_unitName) local _unit = ctld.getTransportUnit(_unitName)
ctld.logTrace("_unit = %s", ctld.p(_unit)) ctld.logTrace("_unit = %s", ctld.p(_unit))
@@ -6063,10 +6064,6 @@ function ctld.addTransportF10MenuOptions(_unitName)
end end
end end
end end
end)
if (not status) then
ctld.logError(string.format("Error adding f10 to transport: %s", error))
end
end end
--****************************************************************************************************** --******************************************************************************************************
@@ -8495,7 +8492,7 @@ 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()") --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
@@ -8508,7 +8505,7 @@ function ctld.eventHandler:onEvent(event)
elseif event.id == world.event.S_EVENT_BIRTH then elseif event.id == world.event.S_EVENT_BIRTH then
eventName = "S_EVENT_BIRTH" eventName = "S_EVENT_BIRTH"
else else
ctld.logTrace("Ignoring event %s", ctld.p(event)) --ctld.logTrace("Ignoring event %s", ctld.p(event))
return return
end end
ctld.logDebug("caught event %s: %s", ctld.p(eventName), ctld.p(event)) ctld.logDebug("caught event %s: %s", ctld.p(eventName), ctld.p(event))
+2
View File
@@ -11,6 +11,8 @@ It's open-source and free as in free beer (you don't have to pay to use it), and
We're always looking for help, please reach out to [Zip on Discord](https://discordapp.com/users/421317390807203850) if you want to participate in maintenance or development. We're always looking for help, please reach out to [Zip on Discord](https://discordapp.com/users/421317390807203850) if you want to participate in maintenance or development.
And if you'd like to support our work, you can [buy me a coffee](https://coff.ee/veaf_zip)!
## Contents ## Contents
This script is a rewrite of some of the functionality of the original Complete Combat Troop Transport Script (CTTS) by Geloxo (http://forums.eagle.ru/showthread.php?t=108523), as well as adding new features. This script is a rewrite of some of the functionality of the original Complete Combat Troop Transport Script (CTTS) by Geloxo (http://forums.eagle.ru/showthread.php?t=108523), as well as adding new features.