Hi all!
I'm rather new to DCS scripting and MIST, but I've been trying to create a script for a little mission I want to run with some friends.
I'm trying to post a message in-game when we've destroyed ~80% of each individual SAM-site and then respawn it, but instead of writing a statement for each individual unit I figured I would simply create a table with all the units I want to be able to respawn, and then put a reference to the table in the mist.flagFunc.group_alive_less_than function.
I can't get it to work.
I feel like I've tried everything I can imagine to get it to work, but I'm at my wits end.
Could someone please look over my code and see if they can figure out where I went wrong?
spawnGroups = {} -- table containing units for respawning (and other things)
spawnGroups[1] = "Halo 1"
spawnGroups[2] = "RED AWACS"
spawnGroups[3] = "HOS SU-27"
spawnGroups[4] = "SAM NORTH"
spawnGroups[5] = "SAM SOUTH"
spawnGroups[6] = "CONVOY 1"
spawnGroups[7] = "Train 1"
local groupNames = {} -- Initialize groupNames table
-- Populate groupNames with values from spawnGroups[4], spawnGroups[5], and spawnGroups[6]
for a = 4, 6 do
local groupName = tostring(spawnGroups[a])
if groupName and mist.DBs.groupsByName[groupName] then
groupNames[#groupNames + 1] = groupName
else
-- Handle the case where the group name is not valid
local errorMessage = "Invalid group name or group not found: " .. tostring(groupName)
print(errorMessage)
env.info(errorMessage)
trigger.action.outText(errorMessage, 5) -- Display the error message in-game for visibility
end
end
-- Use the populated groupNames table in mist.flagFunc.group_alive_less_than
mist.flagFunc.group_alive_less_than {
units = table.concat(groupNames, ","), -- Combine groupNames with commas
flag = 100,
percent = 20,
toggle = true,
interval = 60,
}
Thank you in advance for any and all help on this
*edit
I just went back to the PDF documentation, and noticed that the description states:
mist.flagFunc.group_alive_less_than
mist.flagFunc.group_alive_less_than (table vars)
vars has the following recognized fields (required entries in blue, optional in green):
{
groupName = string groupName,
flag = number/string flag,
percent = number percent,
stopflag = number/string stopflag,
interval = number interval,
toggle = boolean toggle,
}
but the example reads:
mist.flagFunc.group_alive_less_than {
units = 'myGroup,
flag = 100,
percent = 20,
toggle = true,
}
so should I use 'groupName' or 'units' for the variable?