mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2025-08-15 10:47:23 +00:00
v59
-removed the new 3rd variable from mist.utils.getDir and just made the 2nd variable optional instead -Added check to DB update functions to only update if data from the group has changed from what is currently in the DB. This fixes an issue I had where some data was lost if you spawned a group normally after mission start and then used a respawn, clone, or teleport function on said group -fixed issue with dynAdd functions naming a group with the country ID insead of country name -added mist.getAvgPoint(). Function is similar to mist.getAvgPos except it uses raw vec2/3 coordinates instead of units -added mist.utils.roundTbl() Has the same input values as mist.utils.round except it accepts a table and it rounds all numbers in the first level of the table to the passed percision.
This commit is contained in:
parent
d9f5f24632
commit
5af7e9d7b4
69
mist.lua
69
mist.lua
@ -15,7 +15,7 @@ mist = {}
|
|||||||
-- don't change these
|
-- don't change these
|
||||||
mist.majorVersion = 4
|
mist.majorVersion = 4
|
||||||
mist.minorVersion = 0
|
mist.minorVersion = 0
|
||||||
mist.build = 58
|
mist.build = 59
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------
|
||||||
-- the main area
|
-- the main area
|
||||||
@ -241,7 +241,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--mist.debug.writeData(mist.utils.serialize,{'msg', newTable}, timer.getAbsTime() ..'Group.lua')
|
||||||
newTable['timeAdded'] = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
|
newTable['timeAdded'] = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
|
||||||
--mist.debug.dumpDBs()
|
--mist.debug.dumpDBs()
|
||||||
--end
|
--end
|
||||||
@ -254,6 +254,7 @@ do
|
|||||||
local function checkSpawnedEvents()
|
local function checkSpawnedEvents()
|
||||||
if #tempSpawnedUnits > 0 then
|
if #tempSpawnedUnits > 0 then
|
||||||
local groupsToAdd = {}
|
local groupsToAdd = {}
|
||||||
|
local added = false
|
||||||
local ltemp = tempSpawnedUnits
|
local ltemp = tempSpawnedUnits
|
||||||
local ltable = table
|
local ltable = table
|
||||||
|
|
||||||
@ -265,7 +266,7 @@ do
|
|||||||
local spawnedObj = ltemp[x]
|
local spawnedObj = ltemp[x]
|
||||||
if spawnedObj and spawnedObj:isExist() then
|
if spawnedObj and spawnedObj:isExist() then
|
||||||
local found = false
|
local found = false
|
||||||
for index, name in pairs(groupsToAdd) do
|
for name, val in pairs(groupsToAdd) do
|
||||||
if spawnedObj:getCategory() == 1 then -- normal groups
|
if spawnedObj:getCategory() == 1 then -- normal groups
|
||||||
if mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
if mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
||||||
found = true
|
found = true
|
||||||
@ -280,26 +281,37 @@ do
|
|||||||
end
|
end
|
||||||
-- for some reason cargo objects are returning as category == 6.
|
-- for some reason cargo objects are returning as category == 6.
|
||||||
if found == false then
|
if found == false then
|
||||||
|
added = true
|
||||||
if spawnedObj:getCategory() == 1 then -- normal groups
|
if spawnedObj:getCategory() == 1 then -- normal groups
|
||||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getGroup():getName()
|
groupsToAdd[spawnedObj:getGroup():getName()] = true
|
||||||
elseif spawnedObj:getCategory() == 3 or spawnedObj:getCategory() == 6 then -- static objects
|
elseif spawnedObj:getCategory() == 3 or spawnedObj:getCategory() == 6 then -- static objects
|
||||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getName()
|
groupsToAdd[spawnedObj:getName()] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
table.remove(ltemp, x)
|
table.remove(ltemp, x)
|
||||||
if x%updatesPerRun == 0 then
|
if x%updatesPerRun == 0 then
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if added == true then
|
||||||
if #groupsToAdd > 0 then
|
for groupName, val in pairs(groupsToAdd) do
|
||||||
for groupId, groupName in pairs(groupsToAdd) do
|
local dataChanged = false
|
||||||
if not mist.DBs.groupsByName[groupName] or mist.DBs.groupsByName[groupName] and mist.DBs.groupsByName[groupName].startTime + 10 < timer.getAbsTime() then
|
if mist.DBs.groupsByName[groupName] then
|
||||||
|
for _index, data in pairs(mist.DBs.groupsByName[groupName]) do
|
||||||
|
if data.unitName ~= spawnedObj:getName() and data.unitId ~= spawnedObj:getID() and data.type ~= spawnedObj:getTypeName() then
|
||||||
|
dataChanged = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if dataChanged == false then
|
||||||
|
groupsToAdd[groupName] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if groupsToAdd[groupName] == true or not mist.DBs.groupsByName[groupName] then
|
||||||
writeGroups[#writeGroups + 1] = dbUpdate(groupName)
|
writeGroups[#writeGroups + 1] = dbUpdate(groupName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -309,6 +321,7 @@ do
|
|||||||
|
|
||||||
|
|
||||||
local function updateDBTables()
|
local function updateDBTables()
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
for index, newTable in pairs(writeGroups) do
|
for index, newTable in pairs(writeGroups) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@ -548,7 +561,7 @@ do
|
|||||||
|
|
||||||
if newObj.clone or not newObj.name then
|
if newObj.clone or not newObj.name then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex = mistDynAddIndex + 1
|
||||||
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex)
|
newObj.name = (country.name[newCountry] .. ' static ' .. mistDynAddIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newObj.dead then
|
if not newObj.dead then
|
||||||
@ -649,7 +662,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
||||||
newGroup['name'] = tostring(tostring(cntry) .. tostring(typeName) .. mistDynAddIndex)
|
newGroup['name'] = tostring(tostring(country.name[cntry]) .. tostring(typeName) .. mistDynAddIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newGroup.hidden then
|
if not newGroup.hidden then
|
||||||
@ -961,9 +974,9 @@ mist.utils.zoneToVec3 = function(zone)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- gets heading-error corrected direction from point along vector vec.
|
-- gets heading-error corrected direction from point along vector vec.
|
||||||
function mist.utils.getDir(vec, point, raw)
|
function mist.utils.getDir(vec, point)
|
||||||
local dir = math.atan2(vec.z, vec.x)
|
local dir = math.atan2(vec.z, vec.x)
|
||||||
if not raw then
|
if point then
|
||||||
dir = dir + mist.getNorthCorrection(point)
|
dir = dir + mist.getNorthCorrection(point)
|
||||||
end
|
end
|
||||||
if dir < 0 then
|
if dir < 0 then
|
||||||
@ -1014,6 +1027,15 @@ mist.utils.round = function(num, idp)
|
|||||||
return math.floor(num * mult + 0.5) / mult
|
return math.floor(num * mult + 0.5) / mult
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mist.utils.roundTbl = function(tbl, idp)
|
||||||
|
for id, val in pairs(tbl) do
|
||||||
|
if type(val) == 'number' then
|
||||||
|
tbl[id] = mist.utils.round(val, idp)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
-- porting in Slmod's dostring
|
-- porting in Slmod's dostring
|
||||||
mist.utils.dostring = function(s)
|
mist.utils.dostring = function(s)
|
||||||
local f, err = loadstring(s)
|
local f, err = loadstring(s)
|
||||||
@ -3418,6 +3440,21 @@ mist.flagFunc.group_alive_more_than = function(vars)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mist.getAvgPoint = function(points)
|
||||||
|
local avgX, avgY, avgZ, totNum = 0, 0, 0, 0
|
||||||
|
for i = 1, #points do
|
||||||
|
local nPoint = mist.utils.makeVec3(points[i])
|
||||||
|
if nPoint.z then
|
||||||
|
avgX = avgX + nPoint.x
|
||||||
|
avgY = avgY + nPoint.y
|
||||||
|
avgZ = avgZ + nPoint.z
|
||||||
|
totNum = totNum + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if totNum ~= 0 then
|
||||||
|
return {x = avgX/totNum, y = avgY/totNum, z = avgZ/totNum}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--Gets the average position of a group of units (by name)
|
--Gets the average position of a group of units (by name)
|
||||||
|
|||||||
@ -1,3 +1,10 @@
|
|||||||
|
v59
|
||||||
|
-removed the new 3rd variable from mist.utils.getDir and just made the 2nd variable optional instead
|
||||||
|
-Added check to DB update functions to only update if data from the group has changed from what is currently in the DB. This fixes an issue I had where some data was lost if you spawned a group normally after mission start and then used a respawn, clone, or teleport function on said group
|
||||||
|
-fixed issue with dynAdd functions naming a group with the country ID insead of country name
|
||||||
|
-added mist.getAvgPoint(). Function is similar to mist.getAvgPos except it uses raw vec2/3 coordinates instead of units
|
||||||
|
-added mist.utils.roundTbl() Has the same input values as mist.utils.round except it accepts a table and it rounds all numbers in the first level of the table to the passed percision.
|
||||||
|
|
||||||
v58
|
v58
|
||||||
-added optional variable to mist.utils.getDir() If present this function will return the "raw" heading, this is useful in assigning the heading variable within a task.
|
-added optional variable to mist.utils.getDir() If present this function will return the "raw" heading, this is useful in assigning the heading variable within a task.
|
||||||
-mist.utils.makeVec3 now supports being given a table in WP format. Specifically it now coverts a table {x, y, alt) to vec3
|
-mist.utils.makeVec3 now supports being given a table in WP format. Specifically it now coverts a table {x, y, alt) to vec3
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user