add infect menu aaand reformat the project
This commit is contained in:
parent
8463b22928
commit
7bb58e5c09
87
lua/autorun/client/cl_infect.lua
Normal file
87
lua/autorun/client/cl_infect.lua
Normal file
@ -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')
|
1
lua/autorun/client/cl_init.lua
Normal file
1
lua/autorun/client/cl_init.lua
Normal file
@ -0,0 +1 @@
|
|||||||
|
include("cl_infect.lua")
|
51
lua/autorun/server/menus/sv_infect_menu.lua
Normal file
51
lua/autorun/server/menus/sv_infect_menu.lua
Normal file
@ -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")
|
@ -3,6 +3,6 @@ config = {}
|
|||||||
-- the config file path location
|
-- the config file path location
|
||||||
config.settings_path = "disease/settings.json"
|
config.settings_path = "disease/settings.json"
|
||||||
|
|
||||||
config.save_path = "disease/saves"
|
config.save_path = "disease/saves/"
|
||||||
|
|
||||||
return config
|
return config
|
@ -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)
|
|
20
lua/autorun/server/sv_infect.lua
Normal file
20
lua/autorun/server/sv_infect.lua
Normal file
@ -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
|
3
lua/autorun/server/sv_init.lua
Normal file
3
lua/autorun/server/sv_init.lua
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
include("menus/sv_infect_menu.lua")
|
||||||
|
include("sv_saves.lua")
|
||||||
|
include("sv_settings.lua")
|
@ -1,4 +1,21 @@
|
|||||||
utils = include("sv_utils.lua")
|
utils = include("sv_utils.lua")
|
||||||
config = include("../sh_config.lua")
|
config = include("sv_config.lua")
|
||||||
|
|
||||||
utils.path_create(config.save_path .. "/ss")
|
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)
|
@ -1,5 +1,5 @@
|
|||||||
utils = include("sv_utils.lua")
|
utils = include("sv_utils.lua")
|
||||||
config = include("../sh_config.lua")
|
config = include("sv_config.lua")
|
||||||
symbtoms_list = include("sv_symbtom_list.lua")
|
symbtoms_list = include("sv_symbtom_list.lua")
|
||||||
Symbtom = include("sv_symbtom.lua")
|
Symbtom = include("sv_symbtom.lua")
|
||||||
Disease = include("sv_disease.lua")
|
Disease = include("sv_disease.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user