mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Mission units destroyed are stored in a json file being written mission runtime. (First step that will remove the need to save the debriefing manually after mission)
Using Mist framework to do this in the mission script env.
This commit is contained in:
21
resources/scripts/MissionScripting.lua
Normal file
21
resources/scripts/MissionScripting.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
--Initialization script for the Mission lua Environment (SSE)
|
||||
|
||||
dofile('Scripts/ScriptingSystem.lua')
|
||||
|
||||
--Sanitize Mission Scripting environment
|
||||
--This makes unavailable some unsecure functions.
|
||||
--Mission downloaded from server to client may contain potentialy harmful lua code that may use these functions.
|
||||
--You can remove the code below and make availble these functions at your own risk.
|
||||
|
||||
-- local function sanitizeModule(name)
|
||||
-- _G[name] = nil
|
||||
-- package.loaded[name] = nil
|
||||
-- end
|
||||
--
|
||||
-- do
|
||||
-- sanitizeModule('os')
|
||||
-- sanitizeModule('io')
|
||||
-- sanitizeModule('lfs')
|
||||
-- require = nil
|
||||
-- loadlib = nil
|
||||
-- end
|
||||
50
resources/scripts/dcs_liberation.lua
Normal file
50
resources/scripts/dcs_liberation.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
local jsonlib = lfs.writedir() .. "Scripts\\DCSLiberation\\json.lua"
|
||||
json = loadfile(jsonlib)()
|
||||
|
||||
killed_aircrafts = {};
|
||||
killed_ground_units = {};
|
||||
weapons_fired = {}
|
||||
|
||||
local function messageAll(message)
|
||||
local msg = {}
|
||||
msg.text = message
|
||||
msg.displayTime = 25
|
||||
msg.msgFor = {coa = {'all'}}
|
||||
mist.message.add(msg)
|
||||
end
|
||||
|
||||
write_state = function()
|
||||
log("Writing DCS Liberation State...")
|
||||
local stateFile = lfs.writedir()..[[Scripts\DCSLiberation\state.json]]
|
||||
local fp = io.open(stateFile, 'w')
|
||||
local game_state = {
|
||||
["killed_aircrafts"] = killed_aircrafts,
|
||||
["killed_ground_units"] = killed_ground_units,
|
||||
["weapons_fired"] = weapons_fired,
|
||||
}
|
||||
fp:write(json:encode(game_state))
|
||||
fp:close()
|
||||
log("Done writing DCS Liberation state.")
|
||||
end
|
||||
|
||||
mist.scheduleFunction(write_state, {}, timer.getTime() + 10, 60, timer.getTime() + 3600)
|
||||
|
||||
activeWeapons = {}
|
||||
local function onCrash(event)
|
||||
if event.id == world.event.S_EVENT_CRASH and event.initiator then
|
||||
messageAll("Crash :" .. event.initiator.getName(event.initiator))
|
||||
killed_aircrafts[#killed_aircrafts + 1] = event.initiator.getName(event.initiator)
|
||||
end
|
||||
|
||||
if event.id == world.event.S_EVENT_DEAD and event.initiator then
|
||||
killed_ground_units[#killed_ground_units + 1] = event.initiator.getName(event.initiator)
|
||||
end
|
||||
|
||||
if event.id == world.event.S_EVENT_SHOT and event.weapon then
|
||||
weapons_fired[#weapons_fired + 1] = event.weapon.getTypeName(event.weapon)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
mist.addEventHandler(onCrash)
|
||||
1054
resources/scripts/json.lua
Normal file
1054
resources/scripts/json.lua
Normal file
File diff suppressed because it is too large
Load Diff
6822
resources/scripts/mist_4_3_74.lua
Normal file
6822
resources/scripts/mist_4_3_74.lua
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user