2 Commits

Author SHA1 Message Date
Ciaran Fisher
55170e1ae3 Merge pull request #37 from dimpah/JTAC_LS
1.71 JTAC Laser/Smoke mod
2018-04-15 15:53:31 +01:00
dimpah
b45d6a9ce3 1.71 JTAC Laser/Smoke mod
*Adds a new menu item under F10 menu named "JTAC command" when a JTAC is created. From there you can order them to change lasing codes and smoke color.
*Fixed a bug that script prevent you spawn new crates after a period of time (configured by "crateWaitTime" variable)
2018-02-05 13:56:30 +02:00
7 changed files with 6232 additions and 6124 deletions

224
CTLD.lua
View File

@@ -16,8 +16,15 @@
- jmontleon - https://github.com/jmontleon - jmontleon - https://github.com/jmontleon
- emilianomolina - https://github.com/emilianomolina - emilianomolina - https://github.com/emilianomolina
Version: 1.73 - 15/04/2018 Version: 1.72 - 18/02/2018
- Allow minimum distance from friendly logistics to be set - Bug fix for crate spam
- Improved JTAC Performance - priority & targeting
- Added JTAC report for in view
- Added ability to set maximum group size that can be carried
- Added new sling load crates
- Fixed bug where crates and / or groups would disappear
- Fixed bug where count in zone wouldn't work for mission crates
- Delayed config of F10 menu and other scheduled functions so they can be overwritten by mission if a user wants
]] ]]
ctld = {} -- DONT REMOVE! ctld = {} -- DONT REMOVE!
@@ -47,8 +54,6 @@ ctld.maximumMoveDistance = 2000 -- max distance for troops to move from drop poi
ctld.minimumDeployDistance = 1000 -- minimum distance from a friendly pickup zone where you can deploy a crate ctld.minimumDeployDistance = 1000 -- minimum distance from a friendly pickup zone where you can deploy a crate
ctld.despawnTroopsTimer = -1 -- if this value is a positive number, any deployed troops will despawn after that amount of seconds have elapsed
ctld.numberOfTroops = 10 -- default number of troops to load on a transport heli or C-130 ctld.numberOfTroops = 10 -- default number of troops to load on a transport heli or C-130
-- also works as maximum size of group that'll fit into a helicopter unless overridden -- also works as maximum size of group that'll fit into a helicopter unless overridden
ctld.enableFastRopeInsertion = true -- allows you to drop troops by fast rope ctld.enableFastRopeInsertion = true -- allows you to drop troops by fast rope
@@ -112,6 +117,9 @@ ctld.AASystemLimitBLUE = 20 -- Blue side limit
--END AA SYSTEM CONFIG -- --END AA SYSTEM CONFIG --
-- ***************** JTAC CONFIGURATION ***************** -- ***************** JTAC CONFIGURATION *****************
ctld.laser_codes = { 1113, 1688, 1322} -- Put here the available laser codes. The first value is the default for RED and the second for BLUE
ctld.deployedJTACs = {} --Store deployed JTAC units here
ctld.JTACCommandMenuPath = {}
ctld.JTAC_LIMIT_RED = 10 -- max number of JTAC Crates for the RED Side ctld.JTAC_LIMIT_RED = 10 -- max number of JTAC Crates for the RED Side
ctld.JTAC_LIMIT_BLUE = 10 -- max number of JTAC Crates for the BLUE Side ctld.JTAC_LIMIT_BLUE = 10 -- max number of JTAC Crates for the BLUE Side
@@ -125,6 +133,7 @@ ctld.JTAC_smokeOn_BLUE = true -- enables marking of target with smoke for BLUE f
ctld.JTAC_smokeColour_RED = 4 -- RED side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4 ctld.JTAC_smokeColour_RED = 4 -- RED side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4
ctld.JTAC_smokeColour_BLUE = 1 -- BLUE side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4 ctld.JTAC_smokeColour_BLUE = 1 -- BLUE side smoke colour -- Green = 0 , Red = 1, White = 2, Orange = 3, Blue = 4
ctld.JTAC_smokeColous = {"Green", "Red", "White", "Orange", "Blue", "No smoke"}
ctld.JTAC_jtacStatusF10 = true -- enables F10 JTAC Status menu ctld.JTAC_jtacStatusF10 = true -- enables F10 JTAC Status menu
@@ -132,8 +141,6 @@ ctld.JTAC_location = true -- shows location of target in JTAC message
ctld.JTAC_lock = "all" -- "vehicle" OR "troop" OR "all" forces JTAC to only lock vehicles or troops or all ground units ctld.JTAC_lock = "all" -- "vehicle" OR "troop" OR "all" forces JTAC to only lock vehicles or troops or all ground units
ctld.JTAC_despawnTimer = -1 -- if this value is a positive number, any deployed JTACS will despawn after that amount of seconds have elapsed
-- ***************** Pickup, dropoff and waypoint zones ***************** -- ***************** Pickup, dropoff and waypoint zones *****************
-- Available colors (anything else like "none" disables smoke): "green", "red", "white", "orange", "blue", "none", -- Available colors (anything else like "none" disables smoke): "green", "red", "white", "orange", "blue", "none",
@@ -1659,32 +1666,6 @@ function ctld.troopsOnboard(_heli, _troops)
end end
end end
-- tracks the troops dropped or JTACS
-- stores group name and expiry time -- reset on redrop
ctld.droppedTroopsTracker = {}
function ctld.despawnTimer(groupName,despawnTimer)
if despawnTimer > 0 then
-- resets timer if time reused
ctld.droppedTroopsTracker[groupName] = (timer.getTime() +despawnTimer) - 1
timer.scheduleFunction(function()
-- checks timer hasnt been reset
if ctld.droppedTroopsTracker[groupName] < timer.getTime() then
local group = Group.getByName(groupName)
if group then
group:destroy()
end
end
end, nil, timer.getTime() + ctld.despawnTroopsTimer)
end
end
-- if its dropped by AI then there is no player name so return the type of unit -- if its dropped by AI then there is no player name so return the type of unit
function ctld.getPlayerNameOrType(_heli) function ctld.getPlayerNameOrType(_heli)
@@ -1781,9 +1762,6 @@ function ctld.deployTroops(_heli, _troops)
ctld.processCallback({unit = _heli, unloaded = _droppedTroops, action = "dropped_troops"}) ctld.processCallback({unit = _heli, unloaded = _droppedTroops, action = "dropped_troops"})
-- create timer
ctld.despawnTimer(_droppedTroops:getName(),ctld.despawnTroopsTimer)
else else
--extract zone! --extract zone!
@@ -1825,18 +1803,12 @@ function ctld.deployTroops(_heli, _troops)
ctld.processCallback({unit = _heli, unloaded = _droppedVehicles, action = "dropped_vehicles"}) ctld.processCallback({unit = _heli, unloaded = _droppedVehicles, action = "dropped_vehicles"})
-- create timer
ctld.despawnTimer(_droppedVehicles:getName(),ctld.despawnTroopsTimer)
trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " dropped vehicles from " .. _heli:getTypeName() .. " into combat", 10) trigger.action.outTextForCoalition(_heli:getCoalition(), ctld.getPlayerNameOrType(_heli) .. " dropped vehicles from " .. _heli:getTypeName() .. " into combat", 10)
end end
end end
end end
end end
function ctld.insertIntoTroopsArray(_troopType,_count,_troopArray) function ctld.insertIntoTroopsArray(_troopType,_count,_troopArray)
for _i = 1, _count do for _i = 1, _count do
@@ -2923,7 +2895,7 @@ function ctld.unpackCrates(_arguments)
local _crate = ctld.getClosestCrate(_heli, _crates) local _crate = ctld.getClosestCrate(_heli, _crates)
if ctld.inLogisticsZone(_heli) == true or ctld.farEnoughFromLogisticZone(_heli) == false then if ctld.inLogisticsZone(_heli) == true or ctld.farEnoughFromLogisticZone(_heli) == true then
ctld.displayMessageToGroup(_heli, "You can't unpack that here! Take it to where it's needed!", 20) ctld.displayMessageToGroup(_heli, "You can't unpack that here! Take it to where it's needed!", 20)
@@ -2999,14 +2971,10 @@ function ctld.unpackCrates(_arguments)
if ctld.isJTACUnitType(_crate.details.unit) and ctld.JTAC_dropEnabled then if ctld.isJTACUnitType(_crate.details.unit) and ctld.JTAC_dropEnabled then
local _code = table.remove(ctld.jtacGeneratedLaserCodes, 1) local _side = _heli:getCoalition()
--put to the end local _code = ctld.jtacGetLaserCodeBySide(_side)
table.insert(ctld.jtacGeneratedLaserCodes, _code)
-- create timer ctld.CreateJTAC(_spawnedGroups:getName(), _code)
ctld.despawnTimer(_spawnedGroups:getName(),ctld.JTAC_despawnTimer)
ctld.JTACAutoLase(_spawnedGroups:getName(), _code) --(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
end end
end end
@@ -4445,9 +4413,8 @@ function ctld.farEnoughFromLogisticZone(_heli)
--get distance --get distance
local _dist = ctld.getDistance(_heliPoint, _logistic:getPoint()) local _dist = ctld.getDistance(_heliPoint, _logistic:getPoint())
-- env.info("DIST ".._dist)
if _dist <= ctld.minimumDeployDistance then if _dist <= ctld.minimumDeployDistance then
-- env.info("TOO CLOSE ".._dist)
_farEnough = false _farEnough = false
end end
end end
@@ -4953,7 +4920,120 @@ ctld.jtacCurrentTargets = {}
ctld.jtacRadioAdded = {} --keeps track of who's had the radio command added ctld.jtacRadioAdded = {} --keeps track of who's had the radio command added
ctld.jtacGeneratedLaserCodes = {} -- keeps track of generated codes, cycles when they run out ctld.jtacGeneratedLaserCodes = {} -- keeps track of generated codes, cycles when they run out
ctld.jtacLaserPointCodes = {} ctld.jtacLaserPointCodes = {}
ctld.jtacColor = {}
function ctld.CreateJTAC(group, code)
local _side = ctld.getGroup(group)[1]:getCoalition()
ctld.jtacLaserPointCodes[group] = code
if _side == 1 then
ctld.jtacColor[group] = ctld.JTAC_smokeColour_RED
else
ctld.jtacColor[group] = ctld.JTAC_smokeColour_BLUE
end
ctld.JTACAutoLase(group, code)
if ctld.deployedJTACs[_side] == nil then
ctld.deployedJTACs[_side] = {}
end
table.insert(ctld.deployedJTACs[_side], group)
ctld.refreshJTACMenu(_side)
end
function ctld.changeLaserCode(_args)
local _SelectedLazingCode = tonumber(_args[2])
if tonumber(ctld.jtacLaserPointCodes[_args[1]]) ~= _SelectedLazingCode then
--TODO: check unit's life
ctld.JTACAutoLaseStop(_args[1])
local _smoke
if _args[3] == 1 then
_smoke = ctld.JTAC_smokeOn_RED
else
_smoke = ctld.JTAC_smokeOn_BLUE
end
timer.scheduleFunction(ctld.timerJTACAutoLase, { _args[1], _SelectedLazingCode, _smoke, ctld.JTAC_lock, ctld.jtacColor[_args[1]]}, timer.getTime() + 5) --TODO: check interval
ctld.notifyCoalition(_args[1]..": Changing laser code to ".. _SelectedLazingCode, 10, _args[3])
ctld.jtacLaserPointCodes[_args[1]] = _SelectedLazingCode
else
ctld.notifyCoalition(_args[1]..": I'm already lazing with code ".. _SelectedLazingCode, 10, _args[3])
end
end
function ctld.changeJTACColor(_args)
if ctld.GetColorName(ctld.jtacColor[_args[1]]) ~= _args[2] then
ctld.JTACAutoLaseStop(_args[1])
local _smoke
if _args[3] == 1 then
_smoke = ctld.JTAC_smokeOn_RED
else
_smoke = ctld.JTAC_smokeOn_BLUE
end
local _Color = -1 -- no smoke?
if _args[2] == "Green" then
_Color = 0
elseif _args[2] == "Red" then
_Color = 1
elseif _args[2] == "White" then
_Color = 2
elseif _args[2] == "Orange" then
_Color = 3
elseif _args[2] == "Blue" then
_Color = 4
end
timer.scheduleFunction(ctld.timerJTACAutoLase, { _args[1], ctld.jtacLaserPointCodes[_args[1]], _smoke, ctld.JTAC_lock, _Color }, timer.getTime() + 5) --TODO: check interval
ctld.notifyCoalition(_args[1]..": Changing color to ".._args[2], 10, _args[3])
ctld.jtacColor[_args[1]] = _Color
else
ctld.notifyCoalition(_args[1]..": Smoke color is already ".._args[2]..".", 10, _args[3])
end
end
function ctld.refreshJTACMenu(_side)
if ctld.JTACCommandMenuPath[tostring(_side)] ~= nil then
missionCommands.removeItemForCoalition(_side, ctld.JTACCommandMenuPath[tostring(_side)])
end
local _JTACMenu
if next(ctld.deployedJTACs[_side]) ~= nil then
_JTACMenu = missionCommands.addSubMenuForCoalition(_side, "JTAC Command", nil)
else
return
end
ctld.JTACCommandMenuPath[tostring(_side)] = _JTACMenu
local itemNo = 0
--Add one menu item foreach deployed JTAC unit?
local _JTACMenuItem = {}
local _JTACMenuItemLaser = {}
local _JTACMenuItemColor = {}
for _, _JTACGroup in pairs(ctld.deployedJTACs[_side]) do
_JTACMenuItem[itemNo] = missionCommands.addSubMenuForCoalition(_side, _JTACGroup, _JTACMenu)
--Add laser code submenus
_JTACMenuItemLaser[itemNo] = missionCommands.addSubMenuForCoalition(_side, "Change laser code", _JTACMenuItem[itemNo])
for _, _laseCode in pairs(ctld.laser_codes) do
missionCommands.addCommandForCoalition(_side, "to ".._laseCode, _JTACMenuItemLaser[itemNo], ctld.changeLaserCode, { _JTACGroup, _laseCode, _side})
end
--Add color change submenus
_JTACMenuItemColor[itemNo] = missionCommands.addSubMenuForCoalition(_side, "Change smoke color", _JTACMenuItem[itemNo])
for _, _smokeColor in pairs(ctld.JTAC_smokeColous) do
missionCommands.addCommandForCoalition(_side, "to ".._smokeColor, _JTACMenuItemColor[itemNo], ctld.changeJTACColor, { _JTACGroup, _smokeColor, _side})
end
itemNo = itemNo + 1
end
end
function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour) function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
@@ -4969,8 +5049,6 @@ function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
end end
ctld.jtacLaserPointCodes[_jtacGroupName] = _laserCode
local _jtacGroup = ctld.getGroup(_jtacGroupName) local _jtacGroup = ctld.getGroup(_jtacGroupName)
local _jtacUnit local _jtacUnit
@@ -5002,8 +5080,18 @@ function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
if ctld.jtacUnits[_jtacGroupName] ~= nil then if ctld.jtacUnits[_jtacGroupName] ~= nil then
ctld.notifyCoalition("JTAC Group " .. _jtacGroupName .. " KIA!", 10, ctld.jtacUnits[_jtacGroupName].side) local _side = ctld.jtacUnits[_jtacGroupName].side
end ctld.notifyCoalition("JTAC Group " .. _jtacGroupName .. " KIA!", 10, _side)
ctld.deployedJTACs[_side] = {}
for _jtacGroupName, _jtacDetails in pairs(ctld.jtacUnits) do
_jtacUnit = Unit.getByName(_jtacDetails.name)
if _jtacUnit ~= nil and _jtacUnit:getLife() > 0 and _jtacUnit:getCoalition() == _side then
table.insert(ctld.deployedJTACs[_side], _jtacGroupName)
end
end
ctld.refreshJTACMenu(ctld.jtacUnits[_jtacGroupName].side)
end
--remove from list --remove from list
ctld.jtacUnits[_jtacGroupName] = nil ctld.jtacUnits[_jtacGroupName] = nil
@@ -5086,7 +5174,7 @@ function ctld.JTACAutoLase(_jtacGroupName, _laserCode, _smoke, _lock, _colour)
-- store current target for easy lookup -- store current target for easy lookup
ctld.jtacCurrentTargets[_jtacGroupName] = { name = _enemyUnit:getName(), unitType = _enemyUnit:getTypeName(), unitId = _enemyUnit:getID() } ctld.jtacCurrentTargets[_jtacGroupName] = { name = _enemyUnit:getName(), unitType = _enemyUnit:getTypeName(), unitId = _enemyUnit:getID() }
ctld.notifyCoalition(_jtacGroupName .. " lasing new target " .. _enemyUnit:getTypeName() .. '. CODE: ' .. _laserCode .. ctld.getPositionString(_enemyUnit), 10, _jtacUnit:getCoalition()) ctld.notifyCoalition(_jtacGroupName .. " lasing new target " .. _enemyUnit:getTypeName() .. '. CODE: ' .. _laserCode .. ctld.getPositionString(_enemyUnit) .. ". Smoke: " .. ctld.GetColorName(_colour), 10, _jtacUnit:getCoalition())
-- create smoke -- create smoke
if _smoke == true then if _smoke == true then
@@ -5514,6 +5602,8 @@ function ctld.getJTACStatus(_args)
local _enemyUnit = ctld.getCurrentUnit(_jtacUnit, _jtacGroupName) local _enemyUnit = ctld.getCurrentUnit(_jtacUnit, _jtacGroupName)
local _jtacColor = ctld.jtacColor[_jtacGroupName]
local _laserCode = ctld.jtacLaserPointCodes[_jtacGroupName] local _laserCode = ctld.jtacLaserPointCodes[_jtacGroupName]
if _laserCode == nil then if _laserCode == nil then
@@ -5521,7 +5611,7 @@ function ctld.getJTACStatus(_args)
end end
if _enemyUnit ~= nil and _enemyUnit:getLife() > 0 and _enemyUnit:isActive() == true then if _enemyUnit ~= nil and _enemyUnit:getLife() > 0 and _enemyUnit:isActive() == true then
_message = _message .. "" .. _jtacGroupName .. " targeting " .. _enemyUnit:getTypeName() .. " CODE: " .. _laserCode .. ctld.getPositionString(_enemyUnit) .. "\n" _message = _message .. "" .. _jtacGroupName .. " targeting " .. _enemyUnit:getTypeName() .. " CODE: " .. _laserCode .. ctld.getPositionString(_enemyUnit) ..". Visual indication: " .. ctld.GetColorName(_jtacColor).. " smoke." .. "\n"
local _list = ctld.listNearbyEnemies(_jtacUnit) local _list = ctld.listNearbyEnemies(_jtacUnit)
@@ -5548,7 +5638,21 @@ function ctld.getJTACStatus(_args)
ctld.notifyCoalition(_message, 10, _side) ctld.notifyCoalition(_message, 10, _side)
end end
function ctld.GetColorName(_Color)
local _ColorName = "No"
if _Color == 0 then
_ColorName = "Green"
elseif _Color == 1 then
_ColorName = "Red"
elseif _Color == 2 then
_ColorName = "White"
elseif _Color == 3 then
_ColorName = "Orange"
elseif _Color == 4 then
_ColorName = "Blue"
end
return _ColorName
end
function ctld.isInfantry(_unit) function ctld.isInfantry(_unit)
@@ -5612,6 +5716,10 @@ function ctld.generateLaserCode()
end end
end end
function ctld.jtacGetLaserCodeBySide(_side)
return ctld.laser_codes[_side]
end
function ctld.containsDigit(_number, _numberToFind) function ctld.containsDigit(_number, _numberToFind)
local _thisNumber = _number local _thisNumber = _number

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.