GMOD_disease/lua/autorun/client/cl_infect.lua

87 lines
2.5 KiB
Lua

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')