diff --git a/lua/autorun/server/sv_hook.lua b/lua/autorun/server/sv_hook.lua new file mode 100644 index 0000000..1faee53 --- /dev/null +++ b/lua/autorun/server/sv_hook.lua @@ -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) \ No newline at end of file diff --git a/lua/autorun/server/sv_saves.lua b/lua/autorun/server/sv_saves.lua new file mode 100644 index 0000000..d46cb82 --- /dev/null +++ b/lua/autorun/server/sv_saves.lua @@ -0,0 +1,4 @@ +utils = include("sv_utils.lua") +config = include("../sh_config.lua") + +utils.path_create(config.save_path .. "/ss") \ No newline at end of file diff --git a/lua/autorun/server/sv_utils.lua b/lua/autorun/server/sv_utils.lua index df362cb..2542563 100644 --- a/lua/autorun/server/sv_utils.lua +++ b/lua/autorun/server/sv_utils.lua @@ -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 \ No newline at end of file diff --git a/lua/autorun/sh_config.lua b/lua/autorun/sh_config.lua index 4e3a4f1..3e0c621 100644 --- a/lua/autorun/sh_config.lua +++ b/lua/autorun/sh_config.lua @@ -3,4 +3,6 @@ config = {} -- the config file path location config.config_path = "disease/config.json" +config.save_path = "disease/saves" + return config \ No newline at end of file