GMOD_disease/lua/autorun/server/sv_infect.lua

20 lines
681 B
Lua

config = include("sv_config.lua")
---@param side infected number? the steam id 64 of player infected
---@param side diseases table? a table of diseases
function infect(infected, diseases)
local file_path = config.save_path .. infected .. ".json"
local diseases_stages = {}
for _, disease_name in ipairs(diseases)
do
local disease_stage = {}
disease_stage.disease = disease_name
disease_stage.stage = 1
table.insert(diseases_stages, disease_stage)
end
local data = util.JSONToTable(file.Read(file_path))
table.Add(data.diseases, diseases_stages)
file.Write(file_path, util.TableToJSON(data, true))
end
return infect