add: save disease
This commit is contained in:
parent
136847609f
commit
a45536aeab
14
lua/autorun/server/sv_hook.lua
Normal file
14
lua/autorun/server/sv_hook.lua
Normal 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)
|
4
lua/autorun/server/sv_saves.lua
Normal file
4
lua/autorun/server/sv_saves.lua
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
utils = include("sv_utils.lua")
|
||||||
|
config = include("../sh_config.lua")
|
||||||
|
|
||||||
|
utils.path_create(config.save_path .. "/ss")
|
@ -8,4 +8,21 @@ function utils.split (str, sep)
|
|||||||
return new_table
|
return new_table
|
||||||
end
|
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
|
return utils
|
@ -3,4 +3,6 @@ config = {}
|
|||||||
-- the config file path location
|
-- the config file path location
|
||||||
config.config_path = "disease/config.json"
|
config.config_path = "disease/config.json"
|
||||||
|
|
||||||
|
config.save_path = "disease/saves"
|
||||||
|
|
||||||
return config
|
return config
|
Loading…
Reference in New Issue
Block a user