Hi Grimes.
I have been using a mission called CASCAP for years (created by Jinx) and trying to keep it up to date and add some events. But since patch 2.9 I have a problem with the air-to-ground taskings that I can't solve (not a lua expert at all, learning with tries).
That is one example of the spawning script :
function MA_createTask12(zoneName) -- easy tasking
local unitType
local NpointH
local zone = trigger.misc.getZone(zoneName)
repeat --Find a random spot of LAND within the large AO zone
unitSpawnZone1 = mist.getRandPointInCircle(zone.point, zone.radius)
NpointH = land.getHeight(unitSpawnZone1)
unitSpawnZone = mist.utils.makeVec3(unitSpawnZone1, NpointH)
until land.getSurfaceType(unitSpawnZone1) == land.SurfaceType.LAND
local units = {}
groupSize = 3 + mist.random(3)
local i
for i = 1, groupSize do --Insert a random number (min 1, max 5)of random (selection 14 possible) vehicles into table units{}
local randomNumber = mist.random(14)
if randomNumber == 1 then
unitType = 'Ural-375 ZU-23'
elseif randomNumber == 2 then
unitType = 'ZSU-23-4 Shilka'
elseif randomNumber == 3 then
unitType = 'Strela-1 9P31'
elseif randomNumber == 4 then
unitType = 'Strela-10M3'
elseif randomNumber == 5 then
unitType = 'BTR-80'
elseif randomNumber == 6 then
unitType = 'BMD-1'
elseif randomNumber == 7 then
unitType = 'BMP-1'
elseif randomNumber == 8 then
unitType = 'BMP-2'
elseif randomNumber == 9 then
unitType = 'BMP-3'
elseif randomNumber == 10 then
unitType = 'BRDM-2'
elseif randomNumber == 11 then
unitType = 'T-55'
elseif randomNumber == 12 then
unitType = 'T-72B'
elseif randomNumber == 13 then
unitType = 'T-80UD'
elseif randomNumber == 14 then
unitType = 'T-90'
end
repeat --Place every unit within a 100m radius circle from the spot previously randomly chosen
unitPosition = mist.getRandPointInCircle(unitSpawnZone, 100)
until land.getSurfaceType(unitPosition) == land.SurfaceType.LAND
table.insert(units,
{
["x"] = unitPosition.x,
["y"] = unitPosition.y,
["type"] = unitType,
["name"] = 'Red Target Group Unit ' .. i,
["heading"] = 0,
["playerCanDrive"] = true,
["skill"] = "Random"
})
end
for i = 1, groupSize*3 do --Insert three times as many infantry soldiers as there are vehicles in the group into the table units{}
unitType = 'Soldier AK'
repeat --Place every unit within a 100m radius circle from the spot previously randomly chosen
unitPosition = mist.getRandPointInCircle(unitSpawnZone, 100)
until land.getSurfaceType(unitPosition) == land.SurfaceType.LAND
table.insert(units,
{
["x"] = unitPosition.x,
["y"] = unitPosition.y,
["type"] = unitType,
["name"] = 'Red Target Group Unit ' .. groupSize+i,
["heading"] = 0,
["skill"] = "Random"
})
end
mist.dynAdd({country = 'RUSSIA', category = 'GROUND_UNIT', name = 'Red Target Group', hidden = false, units = units }) --Create and spawn the group
--Code to notify the clients of the new objective MGRS grid location. A message is displayed, and also added to F10 menu for continuous review
mgrs = coord.LLtoMGRS(coord.LOtoLL(unitSpawnZone))
mgrsString = mist.tostringMGRS(mgrs, 3)
lat, lon = coord.LOtoLL(unitSpawnZone)
llString = mist.tostringLL(lat, lon, 2)
ll2String = mist.tostringLL(lat, lon, 0, true)
brString = MA_getBearingRange()
QFE = mist.utils.round((env.mission.weather.qnh * 1.33322) - ((land.getHeight(unitSpawnZone1)/0.3048)/30),2)
elev = mist.utils.round(land.getHeight(unitSpawnZone1) * 3.28084)
_targetInfoPath = missionCommands.addSubMenu('Target information', _taskingsGroundPath)
missionCommands.addCommand('TARGET: Group of ' .. groupSize .. ' vehicles and infantry.', _targetInfoPath, MA_emptyFunction)
missionCommands.addCommand('LAT LON: ' .. llString .. '.', _targetInfoPath, MA_emptyFunction)
missionCommands.addCommand('LAT LON: ' .. ll2String .. '.', _targetInfoPath, MA_emptyFunction)
missionCommands.addCommand('MGRS/UTM: ' .. mgrsString .. '.', _targetInfoPath, MA_emptyFunction)
missionCommands.addCommand(brString, _targetInfoPath, MA_emptyFunction)
missionCommands.addCommand('QFE: '.. QFE .. ' mbar / ' .. elev .. ' feet.', _targetInfoPath, MA_emptyFunction)
_targetMarkersPath = missionCommands.addSubMenu('Target markers', _taskingsGroundPath)
missionCommands.addCommand('Request smoke on target area', _targetMarkersPath, MA_smokeRequested)
missionCommands.addCommand('Request illumination flare over target area', _targetMarkersPath, MA_illBombRequested)
missionCommands.addCommand('Skip current objective', _taskingsGroundPath, MA_skipTask)
MA_out('An enemy group of ' .. groupSize .. ' vehicles and infantry has been located. Consult your F10 radio commands for more information.', 5)
groupAliveCheckTaskID = mist.scheduleFunction(MA_groundGroupAliveCheck,{},timer.getTime()+5)
local con = Group.getByName('Red Target Group'):getController()
-- con:setOption(0, 0) --fire at will
con:setOption(9, 2) --radar on
mist.respawnGroup('JTAC1')
local jtac = Group.getByName('JTAC1')
local target = Group.getByName('Red Target Group'):getID()
local Orbit = {
id = 'Orbit',
params = {
pattern = 'Circle',
point = unitSpawnZone1,
altitude = 5000
}
}
jtac:getController():pushTask(Orbit)
local task = {
id = 'FAC_EngageGroup',
params = {
groupId = target,
weaponType = 2956984318,
frequency = 252,
designation = 'Laser',
datalink = true,
},
}
jtac:getController():pushTask(task)
local SetInvisible = {
id = 'SetInvisible',
params = {
value = true
}
}
jtac:getController():setCommand(SetInvisible)
local SetImmortal = {
id = 'SetImmortal',
params = {
value = true
}
}
jtac:getController():setCommand(SetImmortal)
Script = {
id = 'CTLD.lua',
params = {
command = ctld.JTACAutoLase('JTAC1', 1674)
}
}
end
If I skip it using a destroy() function, I can ask a new group just fine.
But if I kill the group and ask a new one, the group spawn but the script ends and the new radio menu with the coordinates isn't generated and the JTAC doesn't spawn. (MA_taskCompleted just rebuilds the F10 radio menu to be able to ask a new tasking) :
function MA_groundGroupAliveCheck()
local groupName = 'Red Target Group'
if Group.getByName(groupName) and Group.getByName(groupName):isExist() == true and #Group.getByName(groupName):getUnits() > 0 then
groupAliveCheckTaskID = mist.scheduleFunction(MA_groundGroupAliveCheck,{},timer.getTime()+5)
else
MA_taskCompleted()
end
end
In the DCS log, the error is "attempt to index local 'avgPosT' (a nil value)". The line number gives the reference to this part :
function MA_getBearingRange()
local avgPos = MA_getAvgPos('Red Target Group')
local ref = mist.utils.makeVec3(mist.DBs.missionData.bullseye.blue, 0)
local vec = {x = avgPos.x - ref.x, y = avgPos.y - ref.y, z = avgPos.z - ref.z}
local dir = mist.utils.round(mist.utils.toDegree(mist.utils.getDir(vec, ref)), 0)
local dist = mist.utils.get2DDist(avgPos, ref)
local distMetric = mist.utils.round(dist/1000, 0)
local distImperial = mist.utils.round(mist.utils.metersToNM(dist), 0)
dir = string.format('%03d', dir)
return 'Target area: Bulls ' .. dir .. ' for ' .. distMetric .. 'km/' .. distImperial .. 'nm'
end
This value isn't nil at first spawn, but each time at second spawn when the group is destroyed by a player (and not skipped).
Tried to simply delete the BullsEye reference part but then the JTAC doesn't fly to the group to orbit.
This turns me crazy and I don't know what did change in DCS 2.9 to create this bug.
Sorry for the long post but any help would be appreciated.
PS : whole script is attached.
CASCAP Infinity Georgia West.lua