After getting used to the Huey and CTTS playing nice together, it was a shame to have such issues with it after the DCS v1.2.12 updates rolled out.
My assumptions: 1) CTTS was meant for troop transport and logistics scripting (things on the ground), 2) dropped troops should head towards any enemy troops nearby, not just the first unit (leader), and 3) "nearest enemy" should mean just that
My modifications: FindNearestEnemy() in CTTS.lua (v1.04)
As Grimes mentioned (http://forums.eagle.ru/showpost.php?p=2257672&postcount=5), coalition.getGroups() will now return all groups/units dead and alive. My first change was to narrow down the returned groups to ground units only as ENO suggested here (http://forums.eagle.ru/showpost.php?p=2058688&postcount=10):
local RedList = coalition.getGroups(1, Group.Category.GROUND)
local BlueList = coalition.getGroups(2, Group.Category.GROUND)My next change was to loop through the returned units array and check for the first one that has life, rather than always using the first index:
for x = 1, #units do
if units[x]:getLife() > 0 then
leader = units[x]
break
end
endI then added a check to ensure that we have a valid "leader":
if leader ~= nil thenI found that it now skips the dead units and returns the coordinates to the first unit that has health for the group (it was actually the leader:getPoint() call that was throwing the error).
I also changed the logic to use the actual nearest enemy:
if dist < minDist then
minDist = dist
EnemyPos = leaderpos
endI have attached the method snippet in case anyone wants to see the full LUA code for themselves.
This is my attempt at fixing my SP game, and in no way take credit for CTTS. I have sent a PM to geloxo and he may decide upon future updates for CTTS.
Please let me know if you see other issues in your SP games using CTTS. I have not done nearly enough flying lately to test every scenario, but this should get us visibly moving troops again! FindNearestEnemy.lua