From e76ca8013e13fb3342047e79e12c6df6952261cd Mon Sep 17 00:00:00 2001 From: mrSkortch Date: Tue, 2 Jul 2024 16:33:38 -0600 Subject: [PATCH 1/4] Dynamic Slot Support MODIFIED: dbUpdate to check getPlayerName on the object to add dynamicSlot value MODIFIED: dbUpdate to save skill to client if it is from a dynamic slot MODIFIED: groupSpawned event to check playerName and MEunitsByName to add the unit to tempSpawnedGroups MODIFIED: writeDBTables to check if dynamicSlot is a passed value. If present will update mist.DBs.humansByName and mist.DBs.humansById for any player spawned in a dynamic slot FIXED: mist.random to just call math.random if the highNum is larger than 50. --- mist.lua | 39 ++++++++++++++++++++++------ mist_4_5_126.lua => mist_4_5_127.lua | 39 ++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 16 deletions(-) rename mist_4_5_126.lua => mist_4_5_127.lua (99%) diff --git a/mist.lua b/mist.lua index 5f1c5b4..9599d51 100644 --- a/mist.lua +++ b/mist.lua @@ -35,7 +35,7 @@ mist = {} -- don't change these mist.majorVersion = 4 mist.minorVersion = 5 -mist.build = 126 +mist.build = 127 -- forward declaration of log shorthand local log @@ -1072,6 +1072,10 @@ do -- the main scope newTable.units[unitId].type = unitData:getTypeName() newTable.units[unitId].unitId = tonumber(unitData:getID()) + + if unitData:getPlayerName() ~= "" and not mist.DBs.MEunitsByName[newTable.units[unitId].unitName] then + newTable.dynamicSlot = timer.getTime() + end newTable.units[unitId].groupName = newTable.groupName @@ -1092,7 +1096,11 @@ do -- the main scope mistAddedObjects[index] = nil end if found == false then - newTable.units[unitId].skill = "High" + if newTable.dynamicSlot then + newTable.units[unitId].skill = "Client" + else + newTable.units[unitId].skill = "High" + end newTable.units[unitId].alt_type = "BARO" end if newTable.units[unitId].alt_type == "RADIO" then -- raw postition MSL was grabbed for group, but spawn is AGL, so re-offset it @@ -1155,6 +1163,7 @@ do -- the main scope newTable.timeAdded = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time --mist.debug.dumpDBs() --end + --dbLog:warn(newTable) --dbLog:info('endDbUpdate') return newTable end @@ -1342,6 +1351,13 @@ do -- the main scope --dbLog:info('byId') mist.DBs.unitsById[tonumber(newUnitData.unitId)] = ldeepCopy(newUnitData) end + + if newTable.dynamicSlot then + mist.DBs.humansByName[newTable.units[1].unitName] = ldeepCopy(newUnitData) + if newUnitData.unitId then + mist.DBs.humansById[newTable.units[1].unitId] = ldeepCopy(newUnitData) + end + end mist.DBs.unitsByName[newUnitData.unitName] = ldeepCopy(newUnitData) end -- this is a really annoying DB to populate. Gotta create new tables in case its missing @@ -1384,6 +1400,9 @@ do -- the main scope --dbLog:info('add to dynGroups') mist.DBs.dynGroupsAdded[#mist.DBs.dynGroupsAdded + 1] = ldeepCopy(newTable) --dbLog:info('clear entry') + + + updateChecker[newTable.name] = nil --dbLog:info('return') return true @@ -1437,14 +1456,15 @@ do -- the main scope -- dont need to add units spawned in at the start of the mission if mist is loaded in init line if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime() then - if Object.getCategory(event.initiator) == 1 and not Unit.getPlayerName(event.initiator) then -- simple player check, will need to later check to see if unit was spawned with a player in a flight + if Object.getCategory(event.initiator) == 1 then --log:info('Object is a Unit') - if Unit.getGroup(event.initiator) then + local g = Unit.getGroup(event.initiator) + if g and event.initiator:getPlayerName() ~= "" and not mist.DBs.MEunitsByName[event.initiator:getName()] then -- log:info(Unit.getGroup(event.initiator):getName()) - local g = Unit.getGroup(event.initiator) - if not tempSpawnedGroups[g:getName()] then - --log:info('added') - tempSpawnedGroups[g:getName()] = {type = 'group', gp = g} + local gName = g:getName() + if not tempSpawnedGroups[gName] then + --log:warn('addedTo tempSpawnedGroups: $1', gName) + tempSpawnedGroups[gName] = {type = 'group', gp = g} tempSpawnGroupsCounter = tempSpawnGroupsCounter + 1 end else @@ -4800,6 +4820,9 @@ do -- group functions scope highNum = secondNum end local total = 1 + if highNum > 50 then + return math.random(lowNum, highNum) + end if math.abs(highNum - lowNum + 1) < 50 then -- if total values is less than 50 total = math.modf(50/math.abs(highNum - lowNum + 1)) -- make x copies required to be above 50 end diff --git a/mist_4_5_126.lua b/mist_4_5_127.lua similarity index 99% rename from mist_4_5_126.lua rename to mist_4_5_127.lua index 243bcca..9599d51 100644 --- a/mist_4_5_126.lua +++ b/mist_4_5_127.lua @@ -35,7 +35,7 @@ mist = {} -- don't change these mist.majorVersion = 4 mist.minorVersion = 5 -mist.build = 125 +mist.build = 127 -- forward declaration of log shorthand local log @@ -1072,6 +1072,10 @@ do -- the main scope newTable.units[unitId].type = unitData:getTypeName() newTable.units[unitId].unitId = tonumber(unitData:getID()) + + if unitData:getPlayerName() ~= "" and not mist.DBs.MEunitsByName[newTable.units[unitId].unitName] then + newTable.dynamicSlot = timer.getTime() + end newTable.units[unitId].groupName = newTable.groupName @@ -1092,7 +1096,11 @@ do -- the main scope mistAddedObjects[index] = nil end if found == false then - newTable.units[unitId].skill = "High" + if newTable.dynamicSlot then + newTable.units[unitId].skill = "Client" + else + newTable.units[unitId].skill = "High" + end newTable.units[unitId].alt_type = "BARO" end if newTable.units[unitId].alt_type == "RADIO" then -- raw postition MSL was grabbed for group, but spawn is AGL, so re-offset it @@ -1155,6 +1163,7 @@ do -- the main scope newTable.timeAdded = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time --mist.debug.dumpDBs() --end + --dbLog:warn(newTable) --dbLog:info('endDbUpdate') return newTable end @@ -1342,6 +1351,13 @@ do -- the main scope --dbLog:info('byId') mist.DBs.unitsById[tonumber(newUnitData.unitId)] = ldeepCopy(newUnitData) end + + if newTable.dynamicSlot then + mist.DBs.humansByName[newTable.units[1].unitName] = ldeepCopy(newUnitData) + if newUnitData.unitId then + mist.DBs.humansById[newTable.units[1].unitId] = ldeepCopy(newUnitData) + end + end mist.DBs.unitsByName[newUnitData.unitName] = ldeepCopy(newUnitData) end -- this is a really annoying DB to populate. Gotta create new tables in case its missing @@ -1384,6 +1400,9 @@ do -- the main scope --dbLog:info('add to dynGroups') mist.DBs.dynGroupsAdded[#mist.DBs.dynGroupsAdded + 1] = ldeepCopy(newTable) --dbLog:info('clear entry') + + + updateChecker[newTable.name] = nil --dbLog:info('return') return true @@ -1437,14 +1456,15 @@ do -- the main scope -- dont need to add units spawned in at the start of the mission if mist is loaded in init line if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime() then - if Object.getCategory(event.initiator) == 1 and not Unit.getPlayerName(event.initiator) then -- simple player check, will need to later check to see if unit was spawned with a player in a flight + if Object.getCategory(event.initiator) == 1 then --log:info('Object is a Unit') - if Unit.getGroup(event.initiator) then + local g = Unit.getGroup(event.initiator) + if g and event.initiator:getPlayerName() ~= "" and not mist.DBs.MEunitsByName[event.initiator:getName()] then -- log:info(Unit.getGroup(event.initiator):getName()) - local g = Unit.getGroup(event.initiator) - if not tempSpawnedGroups[g:getName()] then - --log:info('added') - tempSpawnedGroups[g:getName()] = {type = 'group', gp = g} + local gName = g:getName() + if not tempSpawnedGroups[gName] then + --log:warn('addedTo tempSpawnedGroups: $1', gName) + tempSpawnedGroups[gName] = {type = 'group', gp = g} tempSpawnGroupsCounter = tempSpawnGroupsCounter + 1 end else @@ -4800,6 +4820,9 @@ do -- group functions scope highNum = secondNum end local total = 1 + if highNum > 50 then + return math.random(lowNum, highNum) + end if math.abs(highNum - lowNum + 1) < 50 then -- if total values is less than 50 total = math.modf(50/math.abs(highNum - lowNum + 1)) -- make x copies required to be above 50 end From fad41b68e9335928c4f65d96f5624522cde66a75 Mon Sep 17 00:00:00 2001 From: FullGas1 <51051389+FullGas1@users.noreply.github.com> Date: Wed, 17 Jul 2024 01:32:40 +0200 Subject: [PATCH 2/4] Update mist_4_5_127.lua 2 fixes detailled in Issues Thank's --- mist_4_5_127.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mist_4_5_127.lua b/mist_4_5_127.lua index 9599d51..b42596a 100644 --- a/mist_4_5_127.lua +++ b/mist_4_5_127.lua @@ -982,6 +982,7 @@ do -- the main scope local newObject if Group.getByName(event) then newObject = Group.getByName(event) + objType = "group" elseif StaticObject.getByName(event) then newObject = StaticObject.getByName(event) objType = "static" @@ -1412,7 +1413,8 @@ do -- the main scope -- object is static object or group. -- call dbUpdate to get the table - local tbl = dbUpdate(object) + local tbl = {} + tbl.data = dbUpdate(object) if tbl then local res = writeDBTables(tbl) if not res then From d46930cb50cd65c89f0fe39c80d7187fb057c622 Mon Sep 17 00:00:00 2001 From: FullGas1 <51051389+FullGas1@users.noreply.github.com> Date: Sun, 21 Jul 2024 23:02:59 +0200 Subject: [PATCH 3/4] Update mist_4_5_127.lua update mist.DBs for dynamic groups spwaned update mist.DBs for dynamic groups spwaned --- mist_4_5_127.lua | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/mist_4_5_127.lua b/mist_4_5_127.lua index b42596a..6e8853a 100644 --- a/mist_4_5_127.lua +++ b/mist_4_5_127.lua @@ -1423,8 +1423,35 @@ do -- the main scope end -- call writeDBTables with that table. end - - local function updateDBTables() + ------------------------------------------------------------------------------------------ + function mist.updateMISTDBsDynSpwans(params, t) -- Update mist.DBs tables with planes & helos dynamic slots spwaned + -- to allow dynamic slots to access MIST functions + if t == nil then t = timer.getTime() end + + local table1 = {} + local table2 = {} + + table1 = mist.mergeTables(coalition.getGroups(1,0), coalition.getGroups(2,0)) -- detect red & blue planes + table1 = mist.mergeTables(table1, coalition.getGroups(1,1)) -- detect red helos + table1 = mist.mergeTables(table1, coalition.getGroups(2,1)) -- detect blue helos + + local grps = {} + for i=1, #table1 do + grps[#grps+1] = table1[i]:getName() + end + + if grps ~= nil then + for k,v in pairs(grps) do + --trigger.action.outText(v,5) + mist.forceAddToDB(v) + end + end + timer.scheduleFunction(mist.updateMISTDBsDynSpwans, nil, t + 5) + end + --mist.updateMISTDBsDynSpwans(nil, timer.getTime()) -- run need be located in mist.init() +end + +local function updateDBTables() local i = #writeGroups local savesPerRun = math.ceil(i/10) @@ -1683,8 +1710,10 @@ do -- the main scope -- call main the first time therafter it reschedules itself. mist.main() --log:msg('MIST version $1.$2.$3 loaded', mist.majorVersion, mist.minorVersion, mist.build) - - mist.scheduleFunction(verifyDB, {}, timer.getTime() + 1) + + mist.updateMISTDBsDynSpwans(nil, timer.getTime()) + + mist.scheduleFunction(verifyDB, {}, timer.getTime() + 1) return end From 6c343981158f992013a403c22edfaee1fcba9344 Mon Sep 17 00:00:00 2001 From: FullGas1 <51051389+FullGas1@users.noreply.github.com> Date: Sun, 21 Jul 2024 23:08:46 +0200 Subject: [PATCH 4/4] Update mist_4_5_127.lua update DBs after cleaning code --- mist_4_5_127.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mist_4_5_127.lua b/mist_4_5_127.lua index 6e8853a..da027b7 100644 --- a/mist_4_5_127.lua +++ b/mist_4_5_127.lua @@ -1428,12 +1428,10 @@ do -- the main scope -- to allow dynamic slots to access MIST functions if t == nil then t = timer.getTime() end - local table1 = {} - local table2 = {} - + local table1 = {} table1 = mist.mergeTables(coalition.getGroups(1,0), coalition.getGroups(2,0)) -- detect red & blue planes - table1 = mist.mergeTables(table1, coalition.getGroups(1,1)) -- detect red helos - table1 = mist.mergeTables(table1, coalition.getGroups(2,1)) -- detect blue helos + table1 = mist.mergeTables(table1, coalition.getGroups(1,1)) -- detect red helos + table1 = mist.mergeTables(table1, coalition.getGroups(2,1)) -- detect blue helos local grps = {} for i=1, #table1 do @@ -1442,7 +1440,6 @@ do -- the main scope if grps ~= nil then for k,v in pairs(grps) do - --trigger.action.outText(v,5) mist.forceAddToDB(v) end end