mirror of
https://github.com/ciribob/DCS-CTLD.git
synced 2025-08-15 06:17:22 +00:00
adapted and corrected code
This commit is contained in:
parent
d041a5cd19
commit
b2448048b9
128
CTLD.lua
128
CTLD.lua
@ -2535,7 +2535,7 @@ function ctld.checkTransportStatus()
|
||||
--env.info("CTLD Transport Unit Dead event")
|
||||
ctld.inTransitTroops[_name] = nil
|
||||
ctld.inTransitFOBCrates[_name] = nil
|
||||
ctld.inTransitSlingLoadCrates[_name] = {} -- Tupper Multiple crates
|
||||
ctld.inTransitSlingLoadCrates[_name] = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2543,7 +2543,6 @@ end
|
||||
function ctld.adaptWeightToCargo(unitName)
|
||||
local _weight = ctld.getWeightOfCargo(unitName)
|
||||
trigger.action.setUnitInternalCargo(unitName, _weight)
|
||||
|
||||
end
|
||||
|
||||
function ctld.getWeightOfCargo(unitName)
|
||||
@ -2576,42 +2575,32 @@ function ctld.getWeightOfCargo(unitName)
|
||||
_weight = _weight + FOB_CRATE_WEIGHT
|
||||
_description = _description .. string.format("1 FOB Crate oboard (%s kg)\n", FOB_CRATE_WEIGHT)
|
||||
end
|
||||
|
||||
-- TUPPER mutiple internal crates
|
||||
|
||||
local _heli = ctld.getTransportUnit(unitName)
|
||||
local _heliType = _heli:getTypeName()
|
||||
local _cargoCapacity = 1
|
||||
if ctld.inTransitSlingLoadCrates[_heli:getName()] == nil then
|
||||
ctld.inTransitSlingLoadCrates[_heli:getName()] = {}
|
||||
if ctld.inTransitSlingLoadCrates[unitName] == nil then
|
||||
ctld.inTransitSlingLoadCrates[unitName] = {}
|
||||
end
|
||||
|
||||
if ctld.internalCargoLimits[_heli:getTypeName()] then
|
||||
_cargoCapacity = ctld.internalCargoLimits[_heli:getTypeName()]
|
||||
if ctld.internalCargoLimits[_heliType] then
|
||||
_cargoCapacity = ctld.internalCargoLimits[_heliType]
|
||||
end
|
||||
|
||||
-- add simulated slingload crates weight
|
||||
-- replaced by tupper
|
||||
-- local _crate = ctld.inTransitSlingLoadCrates[unitName]
|
||||
-- if _crate then
|
||||
-- if _crate.simulatedSlingload then
|
||||
-- _weight = _weight + _crate.weight
|
||||
-- _description = _description .. string.format("1 %s crate onboard (%s kg)\n", _crate.desc, _crate.weight)
|
||||
-- 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)
|
||||
for i = 1, _cargoCapacity, 1 do
|
||||
local _crate = ctld.inTransitSlingLoadCrates[unitName][i]
|
||||
if _crate ~= nil and _crate.simulatedSlingload then
|
||||
_weight = _weight + _crate.weight
|
||||
if i > 1 then
|
||||
_description = _description .. "\n"
|
||||
end
|
||||
|
||||
_description = _description .. string.format("%s crate onboard (%s kg)", _crate.desc, _crate.weight)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
_description = "No cargo."
|
||||
end
|
||||
@ -2628,65 +2617,60 @@ function ctld.checkHoverStatus()
|
||||
|
||||
local _reset = true
|
||||
local _transUnit = ctld.getTransportUnit(_name)
|
||||
-- TUPPER mutiple internal crates
|
||||
local _cargoCapacity = 1
|
||||
if ctld.inTransitSlingLoadCrates[_transUnit:getName()] == nil then
|
||||
ctld.inTransitSlingLoadCrates[_transUnit:getName()] = {}
|
||||
local _transUnitName = _transUnit:getName()
|
||||
local _transUnitTypename = _transUnit:getTypeName()
|
||||
|
||||
if ctld.inTransitSlingLoadCrates[_transUnitName] == nil then
|
||||
ctld.inTransitSlingLoadCrates[_transUnitName] = {}
|
||||
end
|
||||
if ctld.internalCargoLimits[_transUnit:getTypeName()] then
|
||||
_cargoCapacity = ctld.internalCargoLimits[_transUnit:getTypeName()]
|
||||
local _cargoCapacity = 1
|
||||
if ctld.internalCargoLimits[_transUnitTypename] then
|
||||
_cargoCapacity = ctld.internalCargoLimits[_transUnitTypename]
|
||||
end
|
||||
|
||||
--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
|
||||
|
||||
|
||||
local _crates = ctld.getCratesAndDistance(_transUnit)
|
||||
|
||||
for _, _crate in pairs(_crates) do
|
||||
local _crateUnitName = _crate.crateUnit:getName()
|
||||
if _crate.dist < ctld.maxDistanceFromCrate and _crate.details.unit ~= "FOB" then
|
||||
|
||||
--check height!
|
||||
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
|
||||
|
||||
local _time = ctld.hoverStatus[_transUnit:getName()]
|
||||
local _time = ctld.hoverStatus[_transUnitName]
|
||||
|
||||
if _time == nil then
|
||||
ctld.hoverStatus[_transUnit:getName()] = ctld.hoverTime
|
||||
ctld.hoverStatus[_transUnitName] = ctld.hoverTime
|
||||
_time = ctld.hoverTime
|
||||
else
|
||||
_time = ctld.hoverStatus[_transUnit:getName()] - 1
|
||||
ctld.hoverStatus[_transUnit:getName()] = _time
|
||||
_time = ctld.hoverStatus[_transUnitName] - 1
|
||||
ctld.hoverStatus[_transUnitName] = _time
|
||||
end
|
||||
|
||||
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)
|
||||
else
|
||||
ctld.hoverStatus[_transUnit:getName()] = nil
|
||||
ctld.hoverStatus[_transUnitName] = nil
|
||||
ctld.displayMessageToGroup(_transUnit, "Loaded " .. _crate.details.desc .. " crate!", 10,true)
|
||||
|
||||
--crates been moved once!
|
||||
ctld.crateMove[_crate.crateUnit:getName()] = nil
|
||||
ctld.crateMove[_crateUnitName] = nil
|
||||
|
||||
if _transUnit:getCoalition() == 1 then
|
||||
ctld.spawnedCratesRED[_crate.crateUnit:getName()] = nil
|
||||
ctld.spawnedCratesRED[_crateUnitName] = nil
|
||||
else
|
||||
ctld.spawnedCratesBLUE[_crate.crateUnit:getName()] = nil
|
||||
ctld.spawnedCratesBLUE[_crateUnitName] = nil
|
||||
end
|
||||
|
||||
_crate.crateUnit:destroy()
|
||||
|
||||
local _copiedCrate = mist.utils.deepCopy(_crate.details)
|
||||
_copiedCrate.simulatedSlingload = true
|
||||
-- tupper multiple crates
|
||||
--ctld.inTransitSlingLoadCrates[_name] = _copiedCrate
|
||||
table.insert(ctld.inTransitSlingLoadCrates[_name], _copiedCrate)
|
||||
ctld.adaptWeightToCargo(_name)
|
||||
end
|
||||
@ -2733,7 +2717,7 @@ function ctld.loadNearbyCrate(_name)
|
||||
ctld.inTransitSlingLoadCrates[_transUnit:getName()] = {}
|
||||
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)
|
||||
|
||||
for _, _crate in pairs(_crates) do
|
||||
@ -2753,8 +2737,6 @@ function ctld.loadNearbyCrate(_name)
|
||||
|
||||
local _copiedCrate = mist.utils.deepCopy(_crate.details)
|
||||
_copiedCrate.simulatedSlingload = true
|
||||
--tupper multiple cargo
|
||||
-- ctld.inTransitSlingLoadCrates[_name] = _copiedCrate
|
||||
table.insert(ctld.inTransitSlingLoadCrates[_name], _copiedCrate)
|
||||
ctld.adaptWeightToCargo(_name)
|
||||
return
|
||||
@ -2765,15 +2747,13 @@ function ctld.loadNearbyCrate(_name)
|
||||
|
||||
else
|
||||
-- crate onboard
|
||||
--tupper multiple crates
|
||||
-- ctld.displayMessageToGroup(_transUnit, "You already have a "..ctld.inTransitSlingLoadCrates[_name].desc.." crate onboard!", 10,true)
|
||||
local _currentCrate = ""
|
||||
for i = 1, _crateCapacity, 1 do
|
||||
if ctld.inTransitSlingLoadCrates[_name][i] ~= nil then
|
||||
if i == 1 then
|
||||
_currentCrate = ctld.inTransitSlingLoadCrates[_name][i].desc
|
||||
_currentCrate = ctld.inTransitSlingLoadCrates[_name][i].desc
|
||||
else
|
||||
_currentCrate = _currentCrate .. "\n" .. ctld.inTransitSlingLoadCrates[_name][i].desc
|
||||
_currentCrate = _currentCrate .. "\n" .. ctld.inTransitSlingLoadCrates[_name][i].desc
|
||||
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
|
||||
function ctld.dropSlingCrate(_args)
|
||||
local _heli = ctld.getTransportUnit(_args[1])
|
||||
local _unitname = _args[1]
|
||||
local _heli = ctld.getTransportUnit(_unitname)
|
||||
|
||||
if _heli == nil then
|
||||
return -- no heli!
|
||||
end
|
||||
-- tupper multiple crate
|
||||
-- local _currentCrate = ctld.inTransitSlingLoadCrates[_heli:getName()]
|
||||
if ctld.inTransitSlingLoadCrates[_heli:getName()] == nil then
|
||||
ctld.inTransitSlingLoadCrates[_heli:getName()] = {}
|
||||
end
|
||||
local _currentCrate = table.remove(ctld.inTransitSlingLoadCrates[_heli:getName()],#ctld.inTransitSlingLoadCrates[_heli:getName()])
|
||||
|
||||
|
||||
if ctld.inTransitSlingLoadCrates[_unitname] == nil then
|
||||
ctld.inTransitSlingLoadCrates[_unitname] = {}
|
||||
end
|
||||
|
||||
local _currentCrate = ctld.inTransitSlingLoadCrates[_unitname][#ctld.inTransitSlingLoadCrates[_unitname]]
|
||||
|
||||
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)
|
||||
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)
|
||||
end
|
||||
else
|
||||
|
||||
local _heli = ctld.getTransportUnit(_args[1])
|
||||
|
||||
local _point = _heli:getPoint()
|
||||
|
||||
local _unitId = ctld.getNextUnitId()
|
||||
|
||||
local _side = _heli:getCoalition()
|
||||
|
||||
local _name = string.format("%s #%i", _currentCrate.desc, _unitId)
|
||||
|
||||
|
||||
local _heightDiff = ctld.heightDiff(_heli)
|
||||
|
||||
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)
|
||||
_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
|
||||
ctld.displayMessageToGroup(_heli, _currentCrate.desc .. " crate has been safely dropped below you", 10)
|
||||
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)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--remove crate from cargo
|
||||
-- ctld.inTransitSlingLoadCrates[_heli:getName()] = nil -- TUPPER MULTIPLE CRATES
|
||||
table.remove(ctld.inTransitSlingLoadCrates[_unitname],#ctld.inTransitSlingLoadCrates[_unitname])
|
||||
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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user