add: save disease

This commit is contained in:
camille lechauve 2023-09-03 21:40:13 +02:00
parent 136847609f
commit a45536aeab
4 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,14 @@
config = include("../sh_config.lua")
hook.Add("PlayerInitialSpawn", "reAddDisease", function (ply)
local file_path = config.save_path .. "/" .. ply:SteamID64() .. ".json"
print(file_path)
if not file.Exists(file_path, "DATA")
then
local default = {}
default.diseases = {}
file.Write(file_path, util.TableToJSON(default, true))
end
local data = file.Read(file_path)
ply.diseases = util.JSONToTable(data)
end)

View File

@ -0,0 +1,4 @@
utils = include("sv_utils.lua")
config = include("../sh_config.lua")
utils.path_create(config.save_path .. "/ss")

View File

@ -8,4 +8,21 @@ function utils.split (str, sep)
return new_table
end
function utils.path_create(path)
local dirs = utils.split(path, "/")
table.remove(dirs)
local tmp = "";
for i, dir in ipairs(dirs) do
tmp = tmp .. dir
print(tmp)
if not file.Exists(tmp, "DATA")
then
file.CreateDir(tmp)
end
tmp = tmp .. "/"
end
end
return utils

View File

@ -3,4 +3,6 @@ config = {}
-- the config file path location
config.config_path = "disease/config.json"
config.save_path = "disease/saves"
return config