diff --git a/lua/autorun/client/cl_disease.lua b/lua/autorun/client/cl_disease.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/autorun/client/cl_infect.lua b/lua/autorun/client/cl_infect.lua new file mode 100644 index 0000000..c363b9f --- /dev/null +++ b/lua/autorun/client/cl_infect.lua @@ -0,0 +1,87 @@ +local infect_menu + +local selected_diseases = {} +local selected_player = {} + +concommand.Add("infect", function(ply) + infect_menu = vgui.Create("DFrame") + infect_menu:SetTitle("infect_menu") + infect_menu:SetSize(400, 300) + infect_menu:Center() + infect_menu:MakePopup() + local infect_button = vgui.Create("DButton", infect_menu) + infect_button:SetText("infect") + infect_button:SetPos(5, 255) + infect_button:SetSize(390, 40) + function infect_button:DoClick() + if #selected_player == 0 or #selected_diseases == 0 + then + return + end + net.Start("infect") + local data = {} + data.infecteds = selected_player + data.diseases = selected_diseases + net.WriteTable(data) + net.SendToServer() + selected_player = {} + selected_diseases = {} + fill_infect_menu() + end + fill_infect_menu() +end) + +function fill_infect_menu() + net.Start("get_diseases_name") + net.SendToServer() + net.Start("get_players_data") + net.SendToServer() +end + +net.Receive("get_players_data", function () + local players_data = net.ReadTable() + local players_panel = vgui.Create("DScrollPanel", infect_menu) + players_panel:SetPos(5, 30) + players_panel:SetSize(190, 250) + for i, player_data in ipairs(players_data) + do + local button = vgui.Create("DCheckBoxLabel", players_panel) + button:SetText(player_data.nick) + button:SetSize(180, 25) + button:SetPos(5, (i - 1) * 25 + 5) + button.SteamID64 = player_data.SteamID64 + function button:OnChange(bVal) + if bVal + then + table.insert(selected_player, self.SteamID64) + + else + table.RemoveByValue(selected_player, self.SteamID64) + end + end + end +end) + +net.Receive("get_diseases_name", function () + local disease_name_list = net.ReadTable() + local diseases_panel = vgui.Create("DScrollPanel", infect_menu) + diseases_panel:SetPos(200, 30) + diseases_panel:SetSize(190, 250) + for i, disease_name in ipairs(disease_name_list) + do + local button = vgui.Create("DCheckBoxLabel", diseases_panel) + button:SetText(disease_name) + button:SetSize(180, 25) + button:SetPos(5, (i - 1) * 25 + 5) + function button:OnChange(bVal) + if bVal + then + table.insert(selected_diseases, disease_name) + else + table.RemoveByValue(selected_diseases, disease_name) + end + end + end +end) + +print('toto') \ No newline at end of file diff --git a/lua/autorun/client/cl_init.lua b/lua/autorun/client/cl_init.lua new file mode 100644 index 0000000..455806d --- /dev/null +++ b/lua/autorun/client/cl_init.lua @@ -0,0 +1 @@ +include("cl_infect.lua") \ No newline at end of file diff --git a/lua/autorun/server/menus/sv_infect_menu.lua b/lua/autorun/server/menus/sv_infect_menu.lua new file mode 100644 index 0000000..ac4df4e --- /dev/null +++ b/lua/autorun/server/menus/sv_infect_menu.lua @@ -0,0 +1,51 @@ +settings = include("../sv_settings.lua") +config = include("../sv_config.lua") +infect = include("../sv_infect.lua") + +util.AddNetworkString("get_diseases_name") +util.AddNetworkString("get_players_data") +util.AddNetworkString("infect") + +net.Receive("get_diseases_name", function (len, ply) + local name_list = {} + for i, disease in ipairs(settings.diseases) + do + table.insert(name_list, disease.name) + end + net.Start("get_diseases_name") + net.WriteTable(name_list) + net.Send(ply) +end) + +net.Receive("get_players_data", function (len, ply) + local files, _ = file.Find(config.save_path .. "*", "DATA") + local data = {} + for i, file_ in ipairs(files) + do + local ply_data = util.JSONToTable(file.Read(config.save_path .. file_)) + local ret = {} + local ply = player.GetBySteamID64(ply_data.SteamID64) + if ply == false + then + ret.nick = ply_data.name + else + ret.nick = ply:Nick() + end + ret.SteamID64 = ply_data.SteamID64 + table.insert(data, ret) + end + net.Start("get_players_data") + net.WriteTable(data) + net.Send(ply) +end) + +net.Receive("infect", function (len, ply) + local data = net.ReadTable() + for _, infected in ipairs(data.infecteds) + do + print("1") + infect(infected, data.diseases) + end +end) + +print("bozo") \ No newline at end of file diff --git a/lua/autorun/sh_config.lua b/lua/autorun/server/sv_config.lua similarity index 75% rename from lua/autorun/sh_config.lua rename to lua/autorun/server/sv_config.lua index a5d26df..409c5c8 100644 --- a/lua/autorun/sh_config.lua +++ b/lua/autorun/server/sv_config.lua @@ -3,6 +3,6 @@ config = {} -- the config file path location config.settings_path = "disease/settings.json" -config.save_path = "disease/saves" +config.save_path = "disease/saves/" return config \ No newline at end of file diff --git a/lua/autorun/server/sv_hook.lua b/lua/autorun/server/sv_hook.lua deleted file mode 100644 index 1faee53..0000000 --- a/lua/autorun/server/sv_hook.lua +++ /dev/null @@ -1,14 +0,0 @@ -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_infect.lua b/lua/autorun/server/sv_infect.lua new file mode 100644 index 0000000..edd85ed --- /dev/null +++ b/lua/autorun/server/sv_infect.lua @@ -0,0 +1,20 @@ +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 \ No newline at end of file diff --git a/lua/autorun/server/sv_init.lua b/lua/autorun/server/sv_init.lua new file mode 100644 index 0000000..68b9983 --- /dev/null +++ b/lua/autorun/server/sv_init.lua @@ -0,0 +1,3 @@ +include("menus/sv_infect_menu.lua") +include("sv_saves.lua") +include("sv_settings.lua") diff --git a/lua/autorun/server/sv_saves.lua b/lua/autorun/server/sv_saves.lua index d46cb82..b4a36bb 100644 --- a/lua/autorun/server/sv_saves.lua +++ b/lua/autorun/server/sv_saves.lua @@ -1,4 +1,21 @@ utils = include("sv_utils.lua") -config = include("../sh_config.lua") +config = include("sv_config.lua") -utils.path_create(config.save_path .. "/ss") \ No newline at end of file +utils.path_create(config.save_path .. "/ss") + +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 data = {} + data.diseases = {} + data.SteamID64 = ply:SteamID64() + data.name = ply:Nick() + file.Write(file_path, util.TableToJSON(data, true)) + end + local data = util.JSONToTable(file.Read(file_path)) + data.name = ply:Nick() + file.Write(file_path, util.TableToJSON(data, true)) + ply.diseases = data.diseases +end) \ No newline at end of file diff --git a/lua/autorun/server/sv_settings.lua b/lua/autorun/server/sv_settings.lua index 751796d..502c479 100644 --- a/lua/autorun/server/sv_settings.lua +++ b/lua/autorun/server/sv_settings.lua @@ -1,5 +1,5 @@ utils = include("sv_utils.lua") -config = include("../sh_config.lua") +config = include("sv_config.lua") symbtoms_list = include("sv_symbtom_list.lua") Symbtom = include("sv_symbtom.lua") Disease = include("sv_disease.lua")