diff --git a/lua/autorun/permanent.lua b/lua/autorun/permanent.lua index 6fb3640..e34e686 100644 --- a/lua/autorun/permanent.lua +++ b/lua/autorun/permanent.lua @@ -13,11 +13,13 @@ CAMI.RegisterPrivilege { if SERVER then + AddCSLuaFile "permanent/cl_menu.lua" include "permanent/sv_data.lua" include "permanent/sv_entity.lua" + include "permanent/sv_control.lua" else - // + include "permanent/cl_menu.lua" end \ No newline at end of file diff --git a/lua/permanent/cl_menu.lua b/lua/permanent/cl_menu.lua new file mode 100644 index 0000000..9233bd5 --- /dev/null +++ b/lua/permanent/cl_menu.lua @@ -0,0 +1,93 @@ + +local FRAME + +function permanent.OpenMenu() + + if IsValid(FRAME) then + + FRAME:Remove() + + end + + FRAME = vgui.Create("DFrame") + FRAME:SetSize(720, 480) + FRAME:Center() + FRAME:MakePopup() + FRAME:SetSizable(false) + FRAME:SetTitle("Permanent") + FRAME:SetIcon("icon16/world.png") + + local LIST = vgui.Create("DListView", FRAME) + LIST:Dock(FILL) + LIST:SetMultiSelect(false) + LIST:AddColumn("ID") + LIST:AddColumn("Class") + LIST:AddColumn("Creator") + LIST:AddColumn("Time") + + LIST.OnRowSelected = function(panel, index, row) + + local MENU = DermaMenu() + + MENU:AddOption("Copy ID", function() + + SetClipboardText(row:GetColumnText(1)) + + end):SetIcon("icon16/page_copy.png") + + MENU:AddOption("Copy SteamID", function() + + SetClipboardText(row:GetColumnText(3)) + + end):SetIcon("icon16/page_copy.png") + + MENU:AddOption("Remove", function() + + net.Start("Permanent", true) + net.WriteUInt(2, 2) + net.WriteEntity(row.ent) + net.SendToServer() + + end):SetIcon("icon16/page_delete.png") + + MENU:Open() + + end + + local function populate() + + for _, v in ipairs(ents.GetAll()) do + + if !v:GetNWBool("IsPermanent") then continue end + + LIST:AddLine(v:GetNWString("Permanent.ID"), v:GetClass(), v:GetNWString("Permanent.Creator"), os.date("%H:%M:%S - %d/%m/%Y", v:GetNWInt("Permanent.Time"))).ent = v + + end + + end + + local BUTTONS = vgui.Create("DPanel", FRAME) + BUTTONS:Dock(BOTTOM) + BUTTONS:SetSize(0, 30) + BUTTONS.Paint = function() end + + local RESPAWN = vgui.Create("DButton", BUTTONS) + RESPAWN:Dock(RIGHT) + RESPAWN:DockMargin(0, 5, 5, 5) + RESPAWN:SetSize(100, 0) + RESPAWN:SetText("Respawn") + RESPAWN:SetIcon("icon16/arrow_refresh.png") + RESPAWN.DoClick = function() + + net.Start("Permanent", true) + net.WriteUInt(3, 2) + net.SendToServer() + + LIST:Clear() + populate() + + end + + populate() + +end \ No newline at end of file diff --git a/lua/permanent/sv_control.lua b/lua/permanent/sv_control.lua new file mode 100644 index 0000000..2de1ba5 --- /dev/null +++ b/lua/permanent/sv_control.lua @@ -0,0 +1,35 @@ + +util.AddNetworkString("Permanent") + +local function remove(ply) + + local ent = net.ReadEntity() + if !(IsValid(ent) && ent:GetNWBool("IsPermanent")) then return end + + permanent.Remove(ent:GetNWString("Permanent.ID")) + ent:Remove() + +end + +local function respawn(ply) + + permanent.SpawnAll() + +end + +local operations = {} +operations[0] = function() end +operations[1] = function() end +operations[2] = remove +operations[3] = respawn + +net.Receive("Permanent", function(len, ply) + + if !CAMI.PlayerHasAccess(ply, "Permanent") then return end + + local oper = net.ReadUInt(2) + assert(operations[oper], "invalid operation") + + operations[oper](ply) + +end) \ No newline at end of file diff --git a/lua/permanent/sv_entity.lua b/lua/permanent/sv_entity.lua index 39eb2ad..c0feed2 100644 --- a/lua/permanent/sv_entity.lua +++ b/lua/permanent/sv_entity.lua @@ -74,6 +74,7 @@ function permanent.Spawn(id) ent:SetNWString("Permanent.ID", id) ent:SetNWString("Permanent.Creator", tbl.creator) + ent:SetNWInt("Permanent.Time", tbl.time) ent:SetNWBool("IsPermanent", true) return ent @@ -82,6 +83,8 @@ end function permanent.SpawnAll() + print("permanent.SpawnAll") + for _,v in ipairs(ents.GetAll()) do if !v:GetNWBool("IsPermanent") then continue end diff --git a/lua/weapons/gmod_tool/stools/permanent.lua b/lua/weapons/gmod_tool/stools/permanent.lua index 791b5b2..2666f25 100644 --- a/lua/weapons/gmod_tool/stools/permanent.lua +++ b/lua/weapons/gmod_tool/stools/permanent.lua @@ -43,7 +43,7 @@ function TOOL:Reload() if SERVER then return end - // + permanent.OpenMenu() end