xcom Posted October 26, 2013 Posted October 26, 2013 Hi, I've been working on getting a "mission save" so that we could do on going campaigns. I used Splinter's script for refrence - http://forums.eagle.ru/showthread.php?t=109730 Here's what I've come up with so far - http://pastebin.com/dyYxVA45 With the above script I get files written to the indicated folder every minute with the mist.DBs.aliveUnits. What I'm doing is using mist.DBs.aliveUnits with mist.utils.oneLineSerialize to write the table into a file. My problem is that the table that gets written is not something I can use the coalition.addGroup function with, I need to know which record is for which country and which is a Airplane/Heli/Ship/Vehicle so I can run the coalition.addGroup function correctly. Is there a way to run the coalition.addGroup function in a way that will identify that info from the record or maybe have the table write that info? Thanks in advance! [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
Grimes Posted October 26, 2013 Posted October 26, 2013 mist.DBs.aliveUnits contains most of the data required to spawn a unit. The problem is you will need to search it at a group level and build the new group table from there. local newGroups = {} for rtId, unitData in pairs(mist.DBs.aliveUnits) do if not newGroups[unitData.groupName] then newGroups[unitData.groupName] = {} newGroups[unitData.groupName].units = {} end end The problem with doing it that way is you don't know the order of the units within a group, so chances are they would be slightly random. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Teknetinium Posted October 26, 2013 Posted October 26, 2013 Interesting, keep up the good work. 51st PVO Discord SATAC YouTube
xcom Posted October 26, 2013 Author Posted October 26, 2013 Thanks Grimes, I'll give it a try. I don't really mind if the order of the units are random as long as all of them are there. Did you have any simpler way in mind? @Teknetinium, Hopefully this will work and we can start doing some big 'on going campaigns' without worries of the server crashing or working hard on many different missions. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
xcom Posted January 2, 2014 Author Posted January 2, 2014 I got the script working but am still struggling with the correct format of the saved file. I want to make it as similar as possible to the saved mission file which is in the miz file. Question - Will it be possible to take the complie.lua file which is in the DCS scripts folder and use it to compile the current data from the mission? Here is the code - local function mark_flyable(u) u.group.flyable = true u.role = "pilot" table.insert(db.clients[u.group.coalition], u) --print("flyable: "..u.group.name.."/"..u.name.." skill: "..u.skill) end local function cmp_clients(a, b) ag = a.group.name bg = b.group.name if ag < bg then return true end if ag > bg then return false end if a.onboard_num < b.onboard_num then return true end --if a.onboard_num > b.onboard_num then return false end return false end local function insertRole(clt, roleId, index) local roleUnit = {unitId = (roleId.."_"..clt.."_"..index), role = roleId, group = {}} roleUnit.group.flyable = true roleUnit.group.coalition = clt roleUnit.group.name = "Virtual unit" roleUnit.type = roleId db.units[roleUnit.unitId] = roleUnit table.insert(db.clients[clt], roleUnit) end local function register_group(coalitionName, countryIndex, country, category, group) group.units = group.units or {} for unitIndex, unit in pairs(group.units) do db.coalitions_by_group[group.groupId] = db.coalitions_by_group[group.groupId] or coalitionName if not unit.unitId then unit.unitId = unit.name end unit.unitId = tostring(unit.unitId) or unit.unitId db.units[unit.unitId] = unit unit.group = group -- link to our own group group.category = category -- link group to its category group.country = country -- link group to its country group.coalition = coalitionName if unit.skill == "Player" then db.human = unit; mark_flyable(unit) elseif unit.skill == "Client" then mark_flyable(unit) end db.groups_by_u[group.name] = db.groups_by_u[group.name] or {} table.insert(db.groups_by_u[group.name],unit) db.countries_by_u[countryIndex] = db.countries_by_u[countryIndex] or {} table.insert(db.countries_by_u[countryIndex],unit) db.coalitions_by_u[coalitionName] = db.coalitions_by_u[coalitionName] or {} table.insert(db.coalitions_by_u[coalitionName],unit) end -- for unitIndex,unit end function add_group(coalitionName, countryId, category, group) if mission.coalition[coalitionName] ~= nil then for countryIndex, country in pairs(mission.coalition[coalitionName].country) do if countryId == country.id then register_group(coalitionName, countryIndex, country, category, group) return true end end return false else register_group(coalitionName, 1, nil, category, group) return true end end function compile_mission() db = db or {} db.human = nil db.units = {} db.groups_by_u = {} -- עאבכטצא הטםאלטקוסךט טחלוםועס ג סטלו (ףהאכעס דנףןן) db.coalitions_by_u = {} db.countries_by_u = {} db.clients = { red = {}, blue = {} } db.units_by_ID = {} db.coalitions_by_group = {} --ןונובטנאול גסו םטע ג לטססטט ט חאםמסטל טץ ג באחף for k1,v1 in pairs(mission.coalition) do for k2,v2 in pairs(v1.country) do for k,v in pairs( {"helicopter","ship","vehicle","plane","static"} ) do v2[v] = v2[v] or {} v2[v].group = v2[v].group or {} for k3,v3 in pairs(v2[v].group) do register_group(k1, k2, v2, v, v3) end -- for k3,v3 end -- for k,v end -- for k2,v2 end --for k1,v1 table.sort(db.clients.red, cmp_clients); table.sort(db.clients.blue, cmp_clients) end function append_commanders() if mission.groundControl then for role, value in pairs(mission.groundControl.roles) do for i = 1, value.red do insertRole("red", role, i) end for i = 1, value.blue do insertRole("blue", role, i) end end end end function register_unit(missionID_, ID_ ) missionID_ = tostring(missionID_) or missionID_ if not db then return 1 end if not db.units_by_ID then return 2 end if not db.units then return 3 end --if not db.units[missionID_] then return 4 end local oldID = db.units[missionID_].ID if oldID ~= nil then db.units_by_ID[oldID] = nil end db.units[missionID_].ID = ID_ -- runtime objectID db.units_by_ID[iD_] = db.units[missionID_] return 0 end -- func function set_human(id, player_name) id = tostring(id) or id local unit = db.units[id] if not unit.group.flyable then return false end db.human = unit unit.skill = "Player" unit.player_name = player_name; return true end function unset_human(id) id = tostring(id) or id if db.human and db.human.unitId == id then db.human.player_name = nil db.human = nil return true end return false end function set_player_name(id, name) id = tostring(id) or id local unit = db.units[id] if unit then unit.player_name = name end end function isSeveralClients() local clientsCount = #db.clients.red + #db.clients.blue if clientsCount == 0 then return false end if clientsCount > 1 then return true end if #db.clients.red == 1 and db.clients.red[1].skill == 'Player' then return false end if #db.clients.blue == 1 and db.clients.blue[1].skill == 'Player' then return false end return true end For example, the compile_mission function looks like is the one doing the startup work, I guess just need to figure out how to put all the info into those db files. Much appriciate any help, gotta get this script working already! :helpsmilie: [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
spinter Posted January 2, 2014 Posted January 2, 2014 I got the script working but am still struggling with the correct format of the saved file. I want to make it as similar as possible to the saved mission file which is in the miz file. Question - Will it be possible to take the complie.lua file which is in the DCS scripts folder and use it to compile the current data from the mission? Here is the code - local function mark_flyable(u) u.group.flyable = true u.role = "pilot" table.insert(db.clients[u.group.coalition], u) --print("flyable: "..u.group.name.."/"..u.name.." skill: "..u.skill) end local function cmp_clients(a, b) ag = a.group.name bg = b.group.name if ag < bg then return true end if ag > bg then return false end if a.onboard_num < b.onboard_num then return true end --if a.onboard_num > b.onboard_num then return false end return false end local function insertRole(clt, roleId, index) local roleUnit = {unitId = (roleId.."_"..clt.."_"..index), role = roleId, group = {}} roleUnit.group.flyable = true roleUnit.group.coalition = clt roleUnit.group.name = "Virtual unit" roleUnit.type = roleId db.units[roleUnit.unitId] = roleUnit table.insert(db.clients[clt], roleUnit) end local function register_group(coalitionName, countryIndex, country, category, group) group.units = group.units or {} for unitIndex, unit in pairs(group.units) do db.coalitions_by_group[group.groupId] = db.coalitions_by_group[group.groupId] or coalitionName if not unit.unitId then unit.unitId = unit.name end unit.unitId = tostring(unit.unitId) or unit.unitId db.units[unit.unitId] = unit unit.group = group -- link to our own group group.category = category -- link group to its category group.country = country -- link group to its country group.coalition = coalitionName if unit.skill == "Player" then db.human = unit; mark_flyable(unit) elseif unit.skill == "Client" then mark_flyable(unit) end db.groups_by_u[group.name] = db.groups_by_u[group.name] or {} table.insert(db.groups_by_u[group.name],unit) db.countries_by_u[countryIndex] = db.countries_by_u[countryIndex] or {} table.insert(db.countries_by_u[countryIndex],unit) db.coalitions_by_u[coalitionName] = db.coalitions_by_u[coalitionName] or {} table.insert(db.coalitions_by_u[coalitionName],unit) end -- for unitIndex,unit end function add_group(coalitionName, countryId, category, group) if mission.coalition[coalitionName] ~= nil then for countryIndex, country in pairs(mission.coalition[coalitionName].country) do if countryId == country.id then register_group(coalitionName, countryIndex, country, category, group) return true end end return false else register_group(coalitionName, 1, nil, category, group) return true end end function compile_mission() db = db or {} db.human = nil db.units = {} db.groups_by_u = {} -- עאבכטצא הטםאלטקוסךט טחלוםועס ג סטלו (ףהאכעס דנףןן) db.coalitions_by_u = {} db.countries_by_u = {} db.clients = { red = {}, blue = {} } db.units_by_ID = {} db.coalitions_by_group = {} --ןונובטנאול גסו םטע ג לטססטט ט חאםמסטל טץ ג באחף for k1,v1 in pairs(mission.coalition) do for k2,v2 in pairs(v1.country) do for k,v in pairs( {"helicopter","ship","vehicle","plane","static"} ) do v2[v] = v2[v] or {} v2[v].group = v2[v].group or {} for k3,v3 in pairs(v2[v].group) do register_group(k1, k2, v2, v, v3) end -- for k3,v3 end -- for k,v end -- for k2,v2 end --for k1,v1 table.sort(db.clients.red, cmp_clients); table.sort(db.clients.blue, cmp_clients) end function append_commanders() if mission.groundControl then for role, value in pairs(mission.groundControl.roles) do for i = 1, value.red do insertRole("red", role, i) end for i = 1, value.blue do insertRole("blue", role, i) end end end end function register_unit(missionID_, ID_ ) missionID_ = tostring(missionID_) or missionID_ if not db then return 1 end if not db.units_by_ID then return 2 end if not db.units then return 3 end --if not db.units[missionID_] then return 4 end local oldID = db.units[missionID_].ID if oldID ~= nil then db.units_by_ID[oldID] = nil end db.units[missionID_].ID = ID_ -- runtime objectID db.units_by_ID[iD_] = db.units[missionID_] return 0 end -- func function set_human(id, player_name) id = tostring(id) or id local unit = db.units[id] if not unit.group.flyable then return false end db.human = unit unit.skill = "Player" unit.player_name = player_name; return true end function unset_human(id) id = tostring(id) or id if db.human and db.human.unitId == id then db.human.player_name = nil db.human = nil return true end return false end function set_player_name(id, name) id = tostring(id) or id local unit = db.units[id] if unit then unit.player_name = name end end function isSeveralClients() local clientsCount = #db.clients.red + #db.clients.blue if clientsCount == 0 then return false end if clientsCount > 1 then return true end if #db.clients.red == 1 and db.clients.red[1].skill == 'Player' then return false end if #db.clients.blue == 1 and db.clients.blue[1].skill == 'Player' then return false end return true end For example, the compile_mission function looks like is the one doing the startup work, I guess just need to figure out how to put all the info into those db files. Much appriciate any help, gotta get this script working already! :helpsmilie: I do not know how to help you but I feel today! ====VIAF==== Spinter 155° "Pantere Nere" TsSimComms My Site aiupgrade.net
mwd2 Posted January 4, 2014 Posted January 4, 2014 is it possible to save the value of a flag or variable outside of the mission, so it is possibel to get this value after the mission ends or the server crashed!?! Something like write the value to a file during the mission, everytime the value is changed!? Playing: DCS World Intel i7-13700KF, 64GB DDR5 @5600MHz, RTX 4080 ZOTAC Trinity, WIN 11 64Bit Prof. Squadron "Serious Uglies" / Discord-Server: https://discord.gg/2WccwBh Ghost0815
RagnarDa Posted January 4, 2014 Posted January 4, 2014 is it possible to save the value of a flag or variable outside of the mission, so it is possibel to get this value after the mission ends or the server crashed!?! Something like write the value to a file during the mission, everytime the value is changed!? Yes. Probably something like: local fdir = lfs.writedir() .. [[saves\]] .. "SaveGame.sav" local f = io.open(fdir, 'w') f:write( ...input save info in string format here... ) f:close()and then to load: io.read("*all") local lines = {} for line in io.lines() do ... do something ... endPlease note that you must disable the sanitization of the io and lfs libraries in ./Scripts/MissionScripting.lua Check out: http://www.lua.org/pil/21.1.html DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is.
xcom Posted January 4, 2014 Author Posted January 4, 2014 Mwd2, that's exactly what my script is doing - http://pastebin.com/dyYxVA45 Basically what RagnarDa wrote is The same. RagnarDa what about the compile.lua you think we can use it to build the mission file correctly when saving? [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
RagnarDa Posted January 4, 2014 Posted January 4, 2014 RagnarDa what about the compile.lua you think we can use it to build the mission file correctly when saving? I can't tell you much about that file since I don't know anything about it. First of all, when and in what context is it run? What are the database object (db) used for? Saving to file or populating the mission? DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is.
xcom Posted January 4, 2014 Author Posted January 4, 2014 I'm not sure exactly when it is run or what the DB files are for, as it seems the functions in this script file are the ones used to create the mission file that resides inside the miz file, I'm guessing that by taking some of the functions from that compile script file we could definetly create a similar mission file that we can then deploy to a file every decided time. These functions for instance are the ones that create most of the mission file I think, but I'm not sure excatly how to use it or deploy it with the save script - function compile_mission() db = db or {} db.human = nil db.units = {} db.groups_by_u = {} -- עאבכטצא הטםאלטקוסךט טחלוםועס ג סטלו (ףהאכעס דנףןן) db.coalitions_by_u = {} db.countries_by_u = {} db.clients = { red = {}, blue = {} } db.units_by_ID = {} db.coalitions_by_group = {} --ןונובטנאול גסו םטע ג לטססטט ט חאםמסטל טץ ג באחף for k1,v1 in pairs(mission.coalition) do for k2,v2 in pairs(v1.country) do for k,v in pairs( {"helicopter","ship","vehicle","plane","static"} ) do v2[v] = v2[v] or {} v2[v].group = v2[v].group or {} for k3,v3 in pairs(v2[v].group) do register_group(k1, k2, v2, v, v3) end -- for k3,v3 end -- for k,v end -- for k2,v2 end --for k1,v1 table.sort(db.clients.red, cmp_clients); table.sort(db.clients.blue, cmp_clients) end local function register_group(coalitionName, countryIndex, country, category, group) group.units = group.units or {} for unitIndex, unit in pairs(group.units) do db.coalitions_by_group[group.groupId] = db.coalitions_by_group[group.groupId] or coalitionName if not unit.unitId then unit.unitId = unit.name end unit.unitId = tostring(unit.unitId) or unit.unitId db.units[unit.unitId] = unit unit.group = group -- link to our own group group.category = category -- link group to its category group.country = country -- link group to its country group.coalition = coalitionName if unit.skill == "Player" then db.human = unit; mark_flyable(unit) elseif unit.skill == "Client" then mark_flyable(unit) end db.groups_by_u[group.name] = db.groups_by_u[group.name] or {} table.insert(db.groups_by_u[group.name],unit) db.countries_by_u[countryIndex] = db.countries_by_u[countryIndex] or {} table.insert(db.countries_by_u[countryIndex],unit) db.coalitions_by_u[coalitionName] = db.coalitions_by_u[coalitionName] or {} table.insert(db.coalitions_by_u[coalitionName],unit) end -- for unitIndex,unit end Got any idea here? I'm kind of blocked without huge trail and error tests here :/ [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
RagnarDa Posted January 5, 2014 Posted January 5, 2014 Well the mission file in the .miz seems to be a regular Lua list. I'm not sure you need the code in compile.lua. DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is.
Recommended Posts