adapted and corrected code

This commit is contained in:
David Pierron 2024-11-09 18:43:46 +01:00
parent d041a5cd19
commit b2448048b9

128
CTLD.lua
View File

@ -2535,7 +2535,7 @@ function ctld.checkTransportStatus()
--env.info("CTLD Transport Unit Dead event") --env.info("CTLD Transport Unit Dead event")
ctld.inTransitTroops[_name] = nil ctld.inTransitTroops[_name] = nil
ctld.inTransitFOBCrates[_name] = nil ctld.inTransitFOBCrates[_name] = nil
ctld.inTransitSlingLoadCrates[_name] = {} -- Tupper Multiple crates ctld.inTransitSlingLoadCrates[_name] = {}
end end
end end
end end
@ -2543,7 +2543,6 @@ end
function ctld.adaptWeightToCargo(unitName) function ctld.adaptWeightToCargo(unitName)
local _weight = ctld.getWeightOfCargo(unitName) local _weight = ctld.getWeightOfCargo(unitName)
trigger.action.setUnitInternalCargo(unitName, _weight) trigger.action.setUnitInternalCargo(unitName, _weight)
end end
function ctld.getWeightOfCargo(unitName) function ctld.getWeightOfCargo(unitName)
@ -2576,42 +2575,32 @@ function ctld.getWeightOfCargo(unitName)
_weight = _weight + FOB_CRATE_WEIGHT _weight = _weight + FOB_CRATE_WEIGHT
_description = _description .. string.format("1 FOB Crate oboard (%s kg)\n", FOB_CRATE_WEIGHT) _description = _description .. string.format("1 FOB Crate oboard (%s kg)\n", FOB_CRATE_WEIGHT)
end end
-- TUPPER mutiple internal crates
local _heli = ctld.getTransportUnit(unitName) local _heli = ctld.getTransportUnit(unitName)
local _heliType = _heli:getTypeName()
local _cargoCapacity = 1 local _cargoCapacity = 1
if ctld.inTransitSlingLoadCrates[_heli:getName()] == nil then if ctld.inTransitSlingLoadCrates[unitName] == nil then
ctld.inTransitSlingLoadCrates[_heli:getName()] = {} ctld.inTransitSlingLoadCrates[unitName] = {}
end end
if ctld.internalCargoLimits[_heli:getTypeName()] then if ctld.internalCargoLimits[_heliType] then
_cargoCapacity = ctld.internalCargoLimits[_heli:getTypeName()] _cargoCapacity = ctld.internalCargoLimits[_heliType]
end end
-- add simulated slingload crates weight -- add simulated slingload crates weight
-- replaced by tupper for i = 1, _cargoCapacity, 1 do
-- local _crate = ctld.inTransitSlingLoadCrates[unitName] local _crate = ctld.inTransitSlingLoadCrates[unitName][i]
-- if _crate then if _crate ~= nil and _crate.simulatedSlingload then
-- if _crate.simulatedSlingload then _weight = _weight + _crate.weight
-- _weight = _weight + _crate.weight if i > 1 then
-- _description = _description .. string.format("1 %s crate onboard (%s kg)\n", _crate.desc, _crate.weight) _description = _description .. "\n"
-- end
-- end
for i = 1, _cargoCapacity, 1 do
if ctld.inTransitSlingLoadCrates[_heli:getName()][i] ~= nil then
_weight = _weight + ctld.inTransitSlingLoadCrates[_heli:getName()][i].weight
if i == 1 then
_description = _description .. string.format("%s crates onboard (%s kg)", ctld.inTransitSlingLoadCrates[_heli:getName()][i].desc, ctld.inTransitSlingLoadCrates[_heli:getName()][i].weight)
else
_description = _description .. "\n" .. string.format("%s crate onboard (%s kg)", ctld.inTransitSlingLoadCrates[_heli:getName()][i].desc, ctld.inTransitSlingLoadCrates[_heli:getName()][i].weight)
end end
_description = _description .. string.format("%s crate onboard (%s kg)", _crate.desc, _crate.weight)
end end
end end
if _description ~= "" then if _description ~= "" then
_description = _description .. string.format("Total weight of cargo : %s kg\n", _weight) _description = _description .. string.format("\nTotal weight of cargo : %s kg\n", _weight)
else else
_description = "No cargo." _description = "No cargo."
end end
@ -2628,65 +2617,60 @@ function ctld.checkHoverStatus()
local _reset = true local _reset = true
local _transUnit = ctld.getTransportUnit(_name) local _transUnit = ctld.getTransportUnit(_name)
-- TUPPER mutiple internal crates local _transUnitName = _transUnit:getName()
local _cargoCapacity = 1 local _transUnitTypename = _transUnit:getTypeName()
if ctld.inTransitSlingLoadCrates[_transUnit:getName()] == nil then
ctld.inTransitSlingLoadCrates[_transUnit:getName()] = {} if ctld.inTransitSlingLoadCrates[_transUnitName] == nil then
ctld.inTransitSlingLoadCrates[_transUnitName] = {}
end end
if ctld.internalCargoLimits[_transUnit:getTypeName()] then local _cargoCapacity = 1
_cargoCapacity = ctld.internalCargoLimits[_transUnit:getTypeName()] if ctld.internalCargoLimits[_transUnitTypename] then
_cargoCapacity = ctld.internalCargoLimits[_transUnitTypename]
end end
--only check transports that are hovering and not planes --only check transports that are hovering and not planes
-- tupper multiple crate
-- if _transUnit ~= nil and ctld.inTransitSlingLoadCrates[_name] == nil and ctld.inAir(_transUnit) and ctld.unitCanCarryVehicles(_transUnit) == false then
if _transUnit ~= nil and #ctld.inTransitSlingLoadCrates[_name] < _cargoCapacity == nil and ctld.inAir(_transUnit) and ctld.unitCanCarryVehicles(_transUnit) == false then if _transUnit ~= nil and #ctld.inTransitSlingLoadCrates[_name] < _cargoCapacity == nil and ctld.inAir(_transUnit) and ctld.unitCanCarryVehicles(_transUnit) == false then
local _crates = ctld.getCratesAndDistance(_transUnit) local _crates = ctld.getCratesAndDistance(_transUnit)
for _, _crate in pairs(_crates) do for _, _crate in pairs(_crates) do
local _crateUnitName = _crate.crateUnit:getName()
if _crate.dist < ctld.maxDistanceFromCrate and _crate.details.unit ~= "FOB" then if _crate.dist < ctld.maxDistanceFromCrate and _crate.details.unit ~= "FOB" then
--check height! --check height!
local _height = _transUnit:getPoint().y - _crate.crateUnit:getPoint().y local _height = _transUnit:getPoint().y - _crate.crateUnit:getPoint().y
--env.info("HEIGHT " .. _name .. " " .. _height .. " " .. _transUnit:getPoint().y .. " " .. _crate.crateUnit:getPoint().y)
-- ctld.heightDiff(_transUnit)
--env.info("HEIGHT ABOVE GROUD ".._name.." ".._height.." ".._transUnit:getPoint().y.." ".._crate.crateUnit:getPoint().y)
if _height > ctld.minimumHoverHeight and _height <= ctld.maximumHoverHeight then if _height > ctld.minimumHoverHeight and _height <= ctld.maximumHoverHeight then
local _time = ctld.hoverStatus[_transUnit:getName()] local _time = ctld.hoverStatus[_transUnitName]
if _time == nil then if _time == nil then
ctld.hoverStatus[_transUnit:getName()] = ctld.hoverTime ctld.hoverStatus[_transUnitName] = ctld.hoverTime
_time = ctld.hoverTime _time = ctld.hoverTime
else else
_time = ctld.hoverStatus[_transUnit:getName()] - 1 _time = ctld.hoverStatus[_transUnitName] - 1
ctld.hoverStatus[_transUnit:getName()] = _time ctld.hoverStatus[_transUnitName] = _time
end end
if _time > 0 then if _time > 0 then
ctld.displayMessageToGroup(_transUnit, "Hovering above " .. _crate.details.desc .. " crate. \n\nHold hover for " .. _time .. " seconds! \n\nIf the countdown stops you're too far away!", 10,true) ctld.displayMessageToGroup(_transUnit, "Hovering above " .. _crate.details.desc .. " crate. \n\nHold hover for " .. _time .. " seconds! \n\nIf the countdown stops you're too far away!", 10,true)
else else
ctld.hoverStatus[_transUnit:getName()] = nil ctld.hoverStatus[_transUnitName] = nil
ctld.displayMessageToGroup(_transUnit, "Loaded " .. _crate.details.desc .. " crate!", 10,true) ctld.displayMessageToGroup(_transUnit, "Loaded " .. _crate.details.desc .. " crate!", 10,true)
--crates been moved once! --crates been moved once!
ctld.crateMove[_crate.crateUnit:getName()] = nil ctld.crateMove[_crateUnitName] = nil
if _transUnit:getCoalition() == 1 then if _transUnit:getCoalition() == 1 then
ctld.spawnedCratesRED[_crate.crateUnit:getName()] = nil ctld.spawnedCratesRED[_crateUnitName] = nil
else else
ctld.spawnedCratesBLUE[_crate.crateUnit:getName()] = nil ctld.spawnedCratesBLUE[_crateUnitName] = nil
end end
_crate.crateUnit:destroy() _crate.crateUnit:destroy()
local _copiedCrate = mist.utils.deepCopy(_crate.details) local _copiedCrate = mist.utils.deepCopy(_crate.details)
_copiedCrate.simulatedSlingload = true _copiedCrate.simulatedSlingload = true
-- tupper multiple crates
--ctld.inTransitSlingLoadCrates[_name] = _copiedCrate
table.insert(ctld.inTransitSlingLoadCrates[_name], _copiedCrate) table.insert(ctld.inTransitSlingLoadCrates[_name], _copiedCrate)
ctld.adaptWeightToCargo(_name) ctld.adaptWeightToCargo(_name)
end end
@ -2733,7 +2717,7 @@ function ctld.loadNearbyCrate(_name)
ctld.inTransitSlingLoadCrates[_transUnit:getName()] = {} ctld.inTransitSlingLoadCrates[_transUnit:getName()] = {}
end end
if #ctld.inTransitSlingLoadCrates[_name] < _crateCapacity then -- TUPPER multiple cargo --ctld.inTransitSlingLoadCrates[_name] == nil then if #ctld.inTransitSlingLoadCrates[_name] < _crateCapacity then
local _crates = ctld.getCratesAndDistance(_transUnit) local _crates = ctld.getCratesAndDistance(_transUnit)
for _, _crate in pairs(_crates) do for _, _crate in pairs(_crates) do
@ -2753,8 +2737,6 @@ function ctld.loadNearbyCrate(_name)
local _copiedCrate = mist.utils.deepCopy(_crate.details) local _copiedCrate = mist.utils.deepCopy(_crate.details)
_copiedCrate.simulatedSlingload = true _copiedCrate.simulatedSlingload = true
--tupper multiple cargo
-- ctld.inTransitSlingLoadCrates[_name] = _copiedCrate
table.insert(ctld.inTransitSlingLoadCrates[_name], _copiedCrate) table.insert(ctld.inTransitSlingLoadCrates[_name], _copiedCrate)
ctld.adaptWeightToCargo(_name) ctld.adaptWeightToCargo(_name)
return return
@ -2765,15 +2747,13 @@ function ctld.loadNearbyCrate(_name)
else else
-- crate onboard -- crate onboard
--tupper multiple crates
-- ctld.displayMessageToGroup(_transUnit, "You already have a "..ctld.inTransitSlingLoadCrates[_name].desc.." crate onboard!", 10,true)
local _currentCrate = "" local _currentCrate = ""
for i = 1, _crateCapacity, 1 do for i = 1, _crateCapacity, 1 do
if ctld.inTransitSlingLoadCrates[_name][i] ~= nil then if ctld.inTransitSlingLoadCrates[_name][i] ~= nil then
if i == 1 then if i == 1 then
_currentCrate = ctld.inTransitSlingLoadCrates[_name][i].desc _currentCrate = ctld.inTransitSlingLoadCrates[_name][i].desc
else else
_currentCrate = _currentCrate .. "\n" .. ctld.inTransitSlingLoadCrates[_name][i].desc _currentCrate = _currentCrate .. "\n" .. ctld.inTransitSlingLoadCrates[_name][i].desc
end end
end end
end end
@ -3356,60 +3336,50 @@ end
--unloads the sling crate when the helicopter is on the ground or between 4.5 - 10 meters --unloads the sling crate when the helicopter is on the ground or between 4.5 - 10 meters
function ctld.dropSlingCrate(_args) function ctld.dropSlingCrate(_args)
local _heli = ctld.getTransportUnit(_args[1]) local _unitname = _args[1]
local _heli = ctld.getTransportUnit(_unitname)
if _heli == nil then if _heli == nil then
return -- no heli! return -- no heli!
end end
-- tupper multiple crate
-- local _currentCrate = ctld.inTransitSlingLoadCrates[_heli:getName()] if ctld.inTransitSlingLoadCrates[_unitname] == nil then
if ctld.inTransitSlingLoadCrates[_heli:getName()] == nil then ctld.inTransitSlingLoadCrates[_unitname] = {}
ctld.inTransitSlingLoadCrates[_heli:getName()] = {} end
end
local _currentCrate = table.remove(ctld.inTransitSlingLoadCrates[_heli:getName()],#ctld.inTransitSlingLoadCrates[_heli:getName()]) local _currentCrate = ctld.inTransitSlingLoadCrates[_unitname][#ctld.inTransitSlingLoadCrates[_unitname]]
if _currentCrate == nil then if _currentCrate == nil then
if ctld.hoverPickup then if ctld.hoverPickup and ctld.loadCrateFromMenu then
ctld.displayMessageToGroup(_heli, "You are not currently transporting any crates. \n\nTo Pickup a crate, hover for "..ctld.hoverTime.." seconds above the crate or land and use F10 Crate Commands", 10)
elseif ctld.hoverPickup then
ctld.displayMessageToGroup(_heli, "You are not currently transporting any crates. \n\nTo Pickup a crate, hover for "..ctld.hoverTime.." seconds above the crate", 10) ctld.displayMessageToGroup(_heli, "You are not currently transporting any crates. \n\nTo Pickup a crate, hover for "..ctld.hoverTime.." seconds above the crate", 10)
else else
ctld.displayMessageToGroup(_heli, "You are not currently transporting any crates. \n\nTo Pickup a crate - land and use F10 Crate Commands to load one.", 10) ctld.displayMessageToGroup(_heli, "You are not currently transporting any crates. \n\nTo Pickup a crate - land and use F10 Crate Commands to load one.", 10)
end end
else else
local _heli = ctld.getTransportUnit(_args[1])
local _point = _heli:getPoint() local _point = _heli:getPoint()
local _unitId = ctld.getNextUnitId() local _unitId = ctld.getNextUnitId()
local _side = _heli:getCoalition() local _side = _heli:getCoalition()
local _name = string.format("%s #%i", _currentCrate.desc, _unitId) local _name = string.format("%s #%i", _currentCrate.desc, _unitId)
local _heightDiff = ctld.heightDiff(_heli) local _heightDiff = ctld.heightDiff(_heli)
if ctld.inAir(_heli) == false or _heightDiff <= 7.5 then if ctld.inAir(_heli) == false or _heightDiff <= 7.5 then
ctld.displayMessageToGroup(_heli, _currentCrate.desc .. " crate has been safely unhooked and is at your 12 o'clock", 10) ctld.displayMessageToGroup(_heli, _currentCrate.desc .. " crate has been safely unhooked and is at your 12 o'clock", 10)
_point = ctld.getPointAt12Oclock(_heli, 30) _point = ctld.getPointAt12Oclock(_heli, 30)
-- elseif _heightDiff > 40.0 then
-- ctld.inTransitSlingLoadCrates[_heli:getName()] = nil
-- ctld.displayMessageToGroup(_heli, "You were too high! The crate has been destroyed", 10)
-- return
elseif _heightDiff > 7.5 and _heightDiff <= 40.0 then elseif _heightDiff > 7.5 and _heightDiff <= 40.0 then
ctld.displayMessageToGroup(_heli, _currentCrate.desc .. " crate has been safely dropped below you", 10) ctld.displayMessageToGroup(_heli, _currentCrate.desc .. " crate has been safely dropped below you", 10)
else -- _heightDiff > 40.0 else -- _heightDiff > 40.0
-- ctld.inTransitSlingLoadCrates[_heli:getName()] = nil TUPPER MULTIPLE CRATE
ctld.displayMessageToGroup(_heli, "You were too high! The crate has been destroyed", 10) ctld.displayMessageToGroup(_heli, "You were too high! The crate has been destroyed", 10)
return return
end end
--remove crate from cargo --remove crate from cargo
-- ctld.inTransitSlingLoadCrates[_heli:getName()] = nil -- TUPPER MULTIPLE CRATES table.remove(ctld.inTransitSlingLoadCrates[_unitname],#ctld.inTransitSlingLoadCrates[_unitname])
ctld.adaptWeightToCargo(_heli:getName()) ctld.adaptWeightToCargo(_heli:getName())
local _spawnedCrate = ctld.spawnCrateStatic(_heli:getCountry(), _unitId, _point, _name, _currentCrate.weight,_side) ctld.spawnCrateStatic(_heli:getCountry(), _unitId, _point, _name, _currentCrate.weight,_side)
end end
end end