From 658ed9b2121bec111de750a979798cf6cc88c92f Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 7 May 2016 04:18:55 -0400 Subject: Gravestone fixed --- entities/entities/gms_gravestone.lua | 3 +- gamemode/cl_deathmenu.lua | 79 ++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/entities/entities/gms_gravestone.lua b/entities/entities/gms_gravestone.lua index c1fff07..76f46f0 100644 --- a/entities/entities/gms_gravestone.lua +++ b/entities/entities/gms_gravestone.lua @@ -71,12 +71,13 @@ if ( CLIENT ) then end - function ENT:Use( ply ) table.sort(self.deathWeapons) table.sort(self.deathResources) ply:CancelProcess() ply:DeathMenu(self.deathResources, self.deathWeapons) + + end if ( SERVER ) then diff --git a/gamemode/cl_deathmenu.lua b/gamemode/cl_deathmenu.lua index 6b023eb..b228ee8 100644 --- a/gamemode/cl_deathmenu.lua +++ b/gamemode/cl_deathmenu.lua @@ -46,6 +46,13 @@ local function receive_message(len) res = net.ReadTable() wep = net.ReadTable() +for k,v in pairs(wep) do + print("death weapon: "..k.." : "..v) + end + for k,v in pairs(res) do + print("death resource: "..k.." : "..v) + end + if (active == 0) then dmFrame = vgui.Create("dmFrame") active = 1 end end @@ -164,9 +171,7 @@ function PANEL:Init() local tbl1 = string.Split(res[k], " ") local tbl2 = string.Split(tbl1[#tbl1], "x") - local ntbl = tbl1 - table.remove(ntbl) - rName = string.Implode(" ", ntbl) + local amount = tbl2[2] resPNL.DoClick = function() @@ -178,10 +183,9 @@ function PANEL:Init() if (amount - 1 <= 0) then amount = 0 for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, 1, i) + if (getResName(v) == getResName(o)) then + print(getResName(v).." : "..getResName(o)) + giveRes(getResName(o), 1, i) table.remove(res,i) end end @@ -191,12 +195,9 @@ function PANEL:Init() for i,o in pairs(res) do - - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, 1, i) - res[i] = rName .. " x" .. amount + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), 1, i) + res[i] = getResName(o) .. " x" .. amount v = res[i] end end @@ -213,10 +214,8 @@ function PANEL:Init() for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, 5, i) + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), 5, i) table.remove(res, i) end end @@ -230,10 +229,8 @@ function PANEL:Init() for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, num2, i) + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), num2, i) table.remove(res,i) end end @@ -244,11 +241,9 @@ function PANEL:Init() for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, 5, i) - res[i] = rName .. " x" .. amount + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), 5, i) + res[i] = getResName(o) .. " x" .. amount v = res[i] end end @@ -264,10 +259,8 @@ function PANEL:Init() amount = 0 for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, 10, i) + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), 10, i) table.remove(res, i) end end @@ -280,10 +273,8 @@ function PANEL:Init() for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, num2, i) + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), num2, i) table.remove(res,i) end end @@ -296,11 +287,9 @@ function PANEL:Init() for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, 10, i) - res[i] = rName .. " x" .. amount + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), 10, i) + res[i] = getResName(o) .. " x" .. amount v = res[i] end end @@ -312,10 +301,8 @@ function PANEL:Init() for i,o in pairs(res) do - spl1 = string.Split(v, " ") - spl2 = string.Split(o, " ") - if (spl1[#spl1] == spl2[#spl2]) then - giveRes(rName, amount, i) + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), amount, i) amount = 0 table.remove(res,i) end @@ -345,6 +332,12 @@ function PANEL:Init() end +function getResName(str) + spl = string.Split(str, " ") + table.remove(spl) + return string.Implode(" ", spl) +end + function PANEL:Close() active = 0 self:Remove() -- cgit v1.2.3-70-g09d2 From 17d19d5c8e8d849b9d7c7ffb2aa8f52a26e2d605 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 7 May 2016 15:20:17 -0400 Subject: Gravestone code cleaned up a bit --- gamemode/cl_deathmenu.lua | 184 +++++++++++++--------------------------------- 1 file changed, 53 insertions(+), 131 deletions(-) diff --git a/gamemode/cl_deathmenu.lua b/gamemode/cl_deathmenu.lua index b228ee8..0a3474b 100644 --- a/gamemode/cl_deathmenu.lua +++ b/gamemode/cl_deathmenu.lua @@ -177,139 +177,12 @@ function PANEL:Init() resPNL.DoClick = function() local mb = DermaMenu() + addMenuButton(mb, resPNL, "Take x1", amount, 1, v) + addMenuButton(mb, resPNL, "Take x5", amount, 5, v) + addMenuButton(mb, resPNL, "Take x10", amount, 10, v) + addMenuButton(mb, resPNL, "Take All", amount, amount, v) - mb:AddOption("Take x1", function() - - if (amount - 1 <= 0) then - amount = 0 - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - print(getResName(v).." : "..getResName(o)) - giveRes(getResName(o), 1, i) - table.remove(res,i) - end - end - resPNL:Remove() - else - amount = amount - 1 - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), 1, i) - res[i] = getResName(o) .. " x" .. amount - v = res[i] - end - end - - end - - end) - mb:AddOption("Take x5", function() - - if (amount - 5 <= 0) then - - if (amount - 5 == 0) then - amount = 0 - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), 5, i) - table.remove(res, i) - end - end - resPNL:Remove() - else - - num1 = amount - 5 - num2 = 5 + num1 - amount = 0 - - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), num2, i) - table.remove(res,i) - end - end - resPNL:Remove() - end - else - amount = amount - 5 - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), 5, i) - res[i] = getResName(o) .. " x" .. amount - v = res[i] - end - end - - end - - end) - mb:AddOption("Take x10", function() - - if (amount - 10 <= 0) then - - if (amount - 10 == 0) then - amount = 0 - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), 10, i) - table.remove(res, i) - end - end - resPNL:Remove() - else - - num1 = amount - 10 - num2 = 10 + num1 - amount = 0 - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), num2, i) - table.remove(res,i) - end - end - - resPNL:Remove() - - end - else - amount = amount - 10 - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), 10, i) - res[i] = getResName(o) .. " x" .. amount - v = res[i] - end - end - - end - end) - mb:AddOption("Take All", function() - - - for i,o in pairs(res) do - if (getResName(v) == getResName(o)) then - giveRes(getResName(o), amount, i) - amount = 0 - table.remove(res,i) - end - end - - resPNL:Remove() - end) mb:Open() end @@ -338,6 +211,55 @@ function getResName(str) return string.Implode(" ", spl) end +function addMenuButton(mb, resPNL, name, amount, remove, v) + mb:AddOption(name, function() + + if (amount - remove <= 0) then + + if (amount - remove == 0) then + amount = 0 + for i,o in pairs(res) do + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), remove, i) + table.remove(res, i) + end + end + resPNL:Remove() + else + + num1 = amount - remove + num2 = remove + num1 + amount = 0 + + + for i,o in pairs(res) do + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), num2, i) + table.remove(res,i) + end + end + + resPNL:Remove() + end + + else + + amount = amount - remove + + + for i,o in pairs(res) do + if (getResName(v) == getResName(o)) then + giveRes(getResName(o), remove, i) + res[i] = getResName(o) .. " x" .. amount + v = res[i] + end + end + + end + + end) +end + function PANEL:Close() active = 0 self:Remove() -- cgit v1.2.3-70-g09d2