Mathilde411

menu - serverside

Jul 23rd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.12 KB | None | 0 0
  1. local function DrawGUI()
  2.     local frame = vgui.Create("DFrame")
  3.     frame:Center()
  4.     frame:SetSize(140,80)
  5.     frame:SetTitle("")
  6.     frame:MakePopup()
  7.     frame:ShowCloseButton(true)
  8.     frame:SetDraggable( true )
  9.  
  10.     local player_select = vgui.Create("DComboBox", frame)
  11.     player_select:SetPos(10, 30)
  12.     player_select:SetSize(120, 20)
  13.     player_select:SetText("Selectionnez un Joueur")
  14.     for k, v in pairs(player.GetAll()) do
  15.         player_select:AddChoice(tostring(v:Name()))
  16.     end
  17.  
  18.     local submit_but = vgui.Create("DButton", frame)
  19.     submit_but:SetSize(120,20)
  20.     submit_but:SetPos(10,50)
  21.     submit_but:SetText("Info")
  22.     submit_but.DoClick = function()
  23.         if(not player_select:GetValue() or player_select:GetValue() == "Selectionnez un Joueur") then return end
  24.         frame:Close()
  25.         net.Start("instructor_menu")
  26.         net.WriteString(player_select:GetValue())
  27.         net.SendToServer()
  28.     end
  29. end
  30. net.Receive("instructor_menu", DrawGUI)
  31.  
  32. local function DrawInfoGUI()
  33.     local car_checkbox = nil
  34.     local bus_checkbox = nil
  35.     local truck_checkbox = nil
  36.     local car_points = nil
  37.     local bus_points = nil
  38.     local truck_points = nil
  39.     local car_instructor_checkbox = nil
  40.     local bus_instructor_checkbox = nil
  41.     local truck_instructor_checkbox = nil
  42.    
  43.     local infos = {}
  44.     local points = {}
  45.     local name = net.ReadString()
  46.     while true do
  47.         key = net.ReadString()
  48.         if(key == "fin") then
  49.             break;
  50.         elseif(key == "car") then
  51.             infos["car"] = net.ReadInt(32) == 1
  52.             points["car"] = net.ReadInt(32)
  53.         elseif(key == "bus") then
  54.             infos["bus"] = net.ReadInt(32) == 1
  55.             points["bus"] = net.ReadInt(32)
  56.         elseif(key == "truck") then
  57.             infos["truck"] = net.ReadInt(32) == 1
  58.             points["truck"] = net.ReadInt(32)
  59.         elseif(key == "instructors") then
  60.             infos["carInstructor"] = net.ReadInt(32) == 1
  61.             infos["busInstructor"] = net.ReadInt(32) == 1
  62.             infos["truckInstructor"] = net.ReadInt(32) == 1
  63.         end
  64.     end
  65.     local tabs = 0
  66.     if infos["car"] then tabs = tabs + 1 end
  67.     if infos["bus"] then tabs = tabs + 1 end
  68.     if infos["truck"] then tabs = tabs + 1 end
  69.     if infos["carInstructor"] then tabs = tabs + 2 end
  70.     if tabs == 0 then return end
  71.  
  72.     local frame = vgui.Create("DFrame")
  73.     frame:Center()
  74.     frame:SetSize(135, 200)
  75.     frame:SetTitle(name)
  76.     frame:MakePopup()
  77.     frame:ShowCloseButton(true)
  78.     frame:SetDraggable( true )
  79.    
  80.     local main_label = vgui.Create("DLabel", frame)
  81.     main_label:SetPos(5, 20)
  82.     main_label:SetText("Permis:")
  83.     local initial = 40
  84.     if infos["car"] then
  85.         car_checkbox = vgui.Create("DCheckBox", frame)
  86.         car_checkbox:SetPos(5, initial)
  87.         car_checkbox:SetValue(infos["car"])
  88.         local car_label = vgui.Create("DLabel", frame)
  89.         car_label:SetPos(22, initial - 3)
  90.         car_label:SetText("Voiture")
  91.         car_points = vgui.Create("DNumberWang", frame)
  92.         car_points:SetPos(70, initial)
  93.         car_points:SetValue(points["car"])
  94.         car_points:SetSize(25, 15)
  95.         car_points:SetMinMax(0, 12)
  96.         car_points:SetDecimals(0)
  97.         local car_label_points = vgui.Create("DLabel", frame)
  98.         car_label_points:SetPos(97, initial - 3)
  99.         car_label_points:SetText("Points")
  100.         initial = initial + 20
  101.         car_checkbox.OnChange = function()
  102.             if (car_checkbox:GetChecked()) then
  103.                 car_points:SetValue(12)
  104.             else
  105.                 car_points:SetValue(0)
  106.             end
  107.         end
  108.     end
  109.    
  110.     if infos["bus"] then
  111.         bus_checkbox = vgui.Create("DCheckBox", frame)
  112.         bus_checkbox:SetPos(5, initial)
  113.         bus_checkbox:SetValue(infos["bus"])
  114.         local bus_label = vgui.Create("DLabel", frame)
  115.         bus_label:SetPos(22, initial - 3)
  116.         bus_label:SetText("Bus")
  117.         bus_points = vgui.Create("DNumberWang", frame)
  118.         bus_points:SetPos(70, initial)
  119.         bus_points:SetValue(points["bus"])
  120.         bus_points:SetSize(25, 15)
  121.         bus_points:SetMinMax(0, 12)
  122.         bus_points:SetDecimals(0)
  123.         local bus_label_points = vgui.Create("DLabel", frame)
  124.         bus_label_points:SetPos(97, initial - 3)
  125.         bus_label_points:SetText("Points")
  126.         initial = initial + 20
  127.         bus_checkbox.OnChange = function()
  128.             if (bus_checkbox:GetChecked()) then
  129.                 bus_points:SetValue(12)
  130.             else
  131.                 bus_points:SetValue(0)
  132.             end
  133.         end
  134.     end
  135.    
  136.     if infos["truck"] then
  137.         truck_checkbox = vgui.Create("DCheckBox", frame)
  138.         truck_checkbox:SetPos(5, initial)
  139.         truck_checkbox:SetValue(infos["truck"])
  140.         local truck_label = vgui.Create("DLabel", frame)
  141.         truck_label:SetPos(22, initial - 3)
  142.         truck_label:SetText("Camion")
  143.         truck_points = vgui.Create("DNumberWang", frame)
  144.         truck_points:SetPos(70, initial)
  145.         truck_points:SetValue(points["truck"])
  146.         truck_points:SetSize(25, 15)
  147.         truck_points:SetMinMax(0, 12)
  148.         truck_points:SetDecimals(0)
  149.         local truck_label_points = vgui.Create("DLabel", frame)
  150.         truck_label_points:SetPos(97, initial - 3)
  151.         truck_label_points:SetText("Points")
  152.         initial = initial + 20
  153.         truck_checkbox.OnChange = function()
  154.             if (truck_checkbox:GetChecked()) then
  155.                 truck_points:SetValue(12)
  156.             else
  157.                 truck_points:SetValue(0)
  158.             end
  159.         end
  160.     end
  161.    
  162.     if infos["carInstructor"] then
  163.         local instructor_label = vgui.Create("DLabel", frame)
  164.         instructor_label:SetPos(5, initial)
  165.         instructor_label:SetText("Instructeur:")
  166.         initial = initial + 20
  167.         car_instructor_checkbox = vgui.Create("DCheckBox", frame)
  168.         car_instructor_checkbox:SetPos(5, initial)
  169.         car_instructor_checkbox:SetValue(infos["carInstructor"])
  170.         local car_instructor_label = vgui.Create("DLabel", frame)
  171.         car_instructor_label:SetPos(22, initial - 3)
  172.         car_instructor_label:SetText("Voiture")
  173.         initial = initial + 20
  174.         bus_instructor_checkbox = vgui.Create("DCheckBox", frame)
  175.         bus_instructor_checkbox:SetPos(5, initial)
  176.         bus_instructor_checkbox:SetValue(infos["busInstructor"])
  177.         local bus_instructor_label = vgui.Create("DLabel", frame)
  178.         bus_instructor_label:SetPos(22, initial - 3)
  179.         bus_instructor_label:SetText("Bus")
  180.         initial = initial + 20
  181.         truck_instructor_checkbox = vgui.Create("DCheckBox", frame)
  182.         truck_instructor_checkbox:SetPos(5, initial)
  183.         truck_instructor_checkbox:SetValue(infos["truckInstructor"])
  184.         local truck_instructor_label = vgui.Create("DLabel", frame)
  185.         truck_instructor_label:SetPos(22, initial - 3)
  186.         truck_instructor_label:SetText("Camion")
  187.         initial = initial + 20
  188.     end
  189.    
  190.     local submit_but = vgui.Create("DButton", frame)
  191.     submit_but:SetSize(125,15)
  192.     submit_but:SetPos(5,initial)
  193.     submit_but:SetText("Mettre à Jour")
  194.     submit_but.DoClick = function()
  195.         net.Start("instructor_info_menu")
  196.         net.WriteString(name)
  197.         if infos["car"] then
  198.             net.WriteString("car")
  199.             if(car_checkbox:GetValue()) then
  200.                 if(car_points:GetValue() <= 0) then
  201.                     net.WriteInt(0, 32)
  202.                     net.WriteInt(0, 32)
  203.                 elseif (car_points:GetValue() > 12) then
  204.                     net.WriteInt(1, 32)
  205.                     net.WriteInt(12, 32)
  206.                 else
  207.                     net.WriteInt(1, 32)
  208.                     net.WriteInt(car_points:GetValue(), 32)
  209.                 end
  210.             else
  211.             net.WriteInt(0, 32)
  212.             net.WriteInt(0, 32)
  213.             end
  214.         end
  215.         if infos["bus"] then
  216.             net.WriteString("bus")
  217.             if(bus_checkbox:GetValue()) then
  218.                 if(bus_points:GetValue() <= 0) then
  219.                     net.WriteInt(0, 32)
  220.                     net.WriteInt(0, 32)
  221.                 elseif (bus_points:GetValue() > 12) then
  222.                     net.WriteInt(1, 32)
  223.                     net.WriteInt(12, 32)
  224.                 else
  225.                     net.WriteInt(1, 32)
  226.                     net.WriteInt(bus_points:GetValue(), 32)
  227.                 end
  228.             else
  229.                 net.WriteInt(0, 32)
  230.                 net.WriteInt(0, 32)
  231.             end
  232.         end
  233.         if infos["truck"] then
  234.             net.WriteString("truck")
  235.             if(truck_checkbox:GetValue()) then
  236.                 if(truck_points:GetValue() <= 0) then
  237.                     net.WriteInt(0, 32)
  238.                     net.WriteInt(0, 32)
  239.                 elseif (truck_points:GetValue() > 12) then
  240.                     net.WriteInt(1, 32)
  241.                     net.WriteInt(12, 32)
  242.                 else
  243.                     net.WriteInt(1, 32)
  244.                     net.WriteInt(truck_points:GetValue(), 32)
  245.                 end
  246.             else
  247.                 net.WriteInt(0, 32)
  248.                 net.WriteInt(0, 32)
  249.             end
  250.         end
  251.         if infos["carInstructor"] then
  252.             net.WriteString("instructors")
  253.             if car_instructor_checkbox:GetValue() then
  254.                 net.WriteInt(1, 32)
  255.             else
  256.                 net.WriteInt(0, 32)
  257.             end
  258.             if bus_instructor_checkbox:GetValue() then
  259.                 net.WriteInt(1, 32)
  260.             else
  261.                 net.WriteInt(0, 32)
  262.             end
  263.             if truck_instructor_checkbox:GetValue() then
  264.                 net.WriteInt(1, 32)
  265.             else
  266.                 net.WriteInt(0, 32)
  267.             end
  268.         end
  269.         net.WriteString("fin")
  270.         net.SendToServer()
  271.         frame:Close()
  272.     end
  273. end
  274. net.Receive("instructor_info_menu", DrawInfoGUI)
Add Comment
Please, Sign In to add comment