• Multiple Credit Equipment Checker not working!
    17 replies, posted
Some of my Traitor menu equipment costs more than 1 credit. This is done using SWEP.Cost in each SWEP This is the function: [CODE]local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= item.cost then return true else return false end end[/CODE] item.cost is defined here: [CODE]for k, v in pairs(weapons.GetList()) do if v and v.CanBuy then local data = v.EquipMenuData or {} local base = { id = WEPS.GetClass(v), name = v.PrintName or "Unnamed", cost = v.Cost or 1, --COST IS DEFINED HERE!!!! limited = v.LimitedStock, kind = v.Kind or WEAPON_NONE, slot = (v.Slot or 0) + 1, material = v.Icon or "vgui/ttt/icon_id", -- the below should be specified in EquipMenuData, in which case -- these values are overwritten type = "Type not specified", model = "models/weapons/w_bugbait.mdl", desc = "No description specified.", donor = v.Tier or "None" }; -- Force material to nil so that model key is used when we are -- explicitly told to do so (ie. material is false rather than nil). if data.modelicon then base.material = nil end table.Merge(base, data) -- add this buyable weapon to all relevant equipment tables for _, r in pairs(v.CanBuy) do tbl[r] = tbl[r] or {} if (v.Tier or "None")== "None" and donor == false then table.insert(tbl[r], base) elseif donor == true and (v.Tier or "None") ~= "None" then table.insert(tbl[r],base) end end end end[/CODE] However, I get this error: [url]http://i.imgur.com/DBOijIH.png[/url] Please help! Nobody can play properly without a functioning T menu!
But that's a local variable. Where is HasEnoughCredits called?
[QUOTE=code_gs;47290352]But that's a local variable. Where is HasEnoughCredits called?[/QUOTE] It's in the same file (cl_equip.lua) where it decides whether or not to grey out the weapon.
But it's local to the loop. Can you post the whole file please?
[QUOTE=code_gs;47290503]But it's local to the loop. Can you post the whole file please?[/QUOTE] Most certainly! [CODE]---- Traitor equipment menu local GetTranslation = LANG.GetTranslation local GetPTranslation = LANG.GetParamTranslation local tiers = {none=1, bronze=2, silver=3, gold=4, ostrich=5} -- Buyable weapons are loaded automatically. Buyable items are defined in -- equip_items_shd.lua local Equipment = nil function GetEquipmentForRole(role,donor) -- need to build equipment cache? if true then --(not Equipment) or donor then -- start with all the non-weapon goodies local tbl = {[ROLE_TRAITOR]={},[ROLE_DETECTIVE]={}} if not donor then tbl = table.Copy(EquipmentItems) end -- find buyable weapons to load info from for k, v in pairs(weapons.GetList()) do if v and v.CanBuy then local data = v.EquipMenuData or {} local base = { id = WEPS.GetClass(v), name = v.PrintName or "Unnamed", cost = v.Cost or 1, limited = v.LimitedStock, kind = v.Kind or WEAPON_NONE, slot = (v.Slot or 0) + 1, material = v.Icon or "vgui/ttt/icon_id", -- the below should be specified in EquipMenuData, in which case -- these values are overwritten type = "Type not specified", model = "models/weapons/w_bugbait.mdl", desc = "No description specified.", donor = v.Tier or "None" }; -- Force material to nil so that model key is used when we are -- explicitly told to do so (ie. material is false rather than nil). if data.modelicon then base.material = nil end table.Merge(base, data) -- add this buyable weapon to all relevant equipment tables for _, r in pairs(v.CanBuy) do tbl[r] = tbl[r] or {} if (v.Tier or "None")== "None" and donor == false then table.insert(tbl[r], base) elseif donor == true and (v.Tier or "None") ~= "None" then table.insert(tbl[r],base) end end end end -- mark custom items for r, is in pairs(tbl) do for _, i in pairs(is) do if i and i.id then i.custom = not table.HasValue(DefaultEquipment[r], i.id) end end end Equipment = tbl end return Equipment and Equipment[role] or {} end local function ItemIsWeapon(item) return not tonumber(item.id) end local function CanCarryWeapon(item) return LocalPlayer():CanCarryType(item.kind) end --Checks if player's donor tier is high enough local function IsSufficientTier(item) local ply = LocalPlayer() local donorlevel = ply:GetUserGroup() local weapondonor = (item.donor or "None"):lower() local dlevel = 1 for i,v in pairs(tiers) do if donorlevel:match(i) then dlevel = v break end end weapondonor = tiers[weapondonor] if dlevel >= weapondonor then return true else return false end end local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= item.cost then return true else return false end end local color_bad = Color(220, 60, 60, 255) local color_good = Color(0, 200, 0, 255) -- Creates tabel of labels showing the status of ordering prerequisites local function PreqLabels(parent, x, y) local tbl = {} tbl.credits = vgui.Create("DLabel", parent) tbl.credits:SetToolTip(GetTranslation("equip_help_cost")) tbl.credits:SetPos(x, y) tbl.credits.Check = function(s, sel) local credits = LocalPlayer():GetCredits() return credits > 0, GetPTranslation("equip_cost", {num = credits}) end tbl.owned = vgui.Create("DLabel", parent) tbl.owned:SetToolTip(GetTranslation("equip_help_carry")) tbl.owned:CopyPos(tbl.credits) tbl.owned:MoveBelow(tbl.credits, y) tbl.owned.Check = function(s, sel) if ItemIsWeapon(sel) and (not CanCarryWeapon(sel)) then return false, GetPTranslation("equip_carry_slot", {slot = sel.slot}) elseif (not ItemIsWeapon(sel)) and LocalPlayer():HasEquipmentItem(sel.id) then return false, GetTranslation("equip_carry_own") else return true, GetTranslation("equip_carry") end end tbl.bought = vgui.Create("DLabel", parent) tbl.bought:SetToolTip(GetTranslation("equip_help_stock")) tbl.bought:CopyPos(tbl.owned) tbl.bought:MoveBelow(tbl.owned, y) tbl.bought.Check = function(s, sel) if sel.limited and LocalPlayer():HasBought(tostring(sel.id)) then return false, GetTranslation("equip_stock_deny") else return true, GetTranslation("equip_stock_ok") end end for k, pnl in pairs(tbl) do pnl:SetFont("TabLarge") end return function(selected) local allow = true for k, pnl in pairs(tbl) do local result, text = pnl:Check(selected) pnl:SetTextColor(result and color_good or color_bad) pnl:SetText(text) pnl:SizeToContents() allow = allow and result and IsSufficientTier(selected) end return allow end end -- quick, very basic override of DPanelSelect local PANEL = {} local function DrawSelectedEquipment(pnl) surface.SetDrawColor(255, 200, 0, 255) surface.DrawOutlinedRect(0, 0, pnl:GetWide(), pnl:GetTall()) end function PANEL:SelectPanel(pnl) if pnl ~= nil then self.BaseClass.SelectPanel(self, pnl) if pnl then pnl.PaintOver = DrawSelectedEquipment end end end vgui.Register("EquipSelect", PANEL, "DPanelSelect") local SafeTranslate = LANG.TryTranslation local color_darkened = Color(255,255,255, 80) -- TODO: make set of global role colour defs, these are same as wepswitch local color_slot = { [ROLE_TRAITOR] = Color(180, 50, 40, 255), [ROLE_DETECTIVE] = Color(50, 60, 180, 255) }; local eqframe = nil local function TraitorMenuPopup() local ply = LocalPlayer() if not IsValid(ply) or not ply:IsActiveSpecial() then return end -- Close any existing traitor menu if eqframe and ValidPanel(eqframe) then eqframe:Close() end local credits = ply:GetCredits() local can_order = credits > 0 local dframe = vgui.Create("DFrame") local w, h = 500, 350 dframe:SetSize(w, h) dframe:Center() dframe:SetTitle(GetTranslation("equip_title")) dframe:SetVisible(true) dframe:ShowCloseButton(true) dframe:SetMouseInputEnabled(true) dframe:SetDeleteOnClose(true) local m = 5 local dsheet = vgui.Create("DPropertySheet", dframe) -- Add a callback when switching tabs local oldfunc = dsheet.SetActiveTab dsheet.SetActiveTab = function(self, new) if self.m_pActiveTab != new and self.OnTabChanged then self:OnTabChanged(self.m_pActiveTab, new) end oldfunc(self, new) end dsheet:SetPos(0,0) dsheet:StretchToParent(m,m + 25,m,m) local padding = dsheet:GetPadding() local dequip = vgui.Create("DPanel", dsheet) dequip:SetPaintBackground(false) dequip:StretchToParent(padding,padding,padding,padding) local dequipdonor = vgui.Create("DPanel", dsheet) dequipdonor:SetPaintBackground(false) dequipdonor:StretchToParent(padding,padding,padding,padding) -- Determine if we already have equipment local owned_ids = {} for _, wep in pairs(ply:GetWeapons()) do if IsValid(wep) and wep:I
[QUOTE=r0uge;47290611]Most certainly! [CODE]---- Traitor equipment menu local GetTranslation = LANG.GetTranslation local GetPTranslation = LANG.GetParamTranslation local tiers = {none=1, bronze=2, silver=3, gold=4, ostrich=5} -- Buyable weapons are loaded automatically. Buyable items are defined in -- equip_items_shd.lua local Equipment = nil function GetEquipmentForRole(role,donor) -- need to build equipment cache? if true then --(not Equipment) or donor then -- start with all the non-weapon goodies local tbl = {[ROLE_TRAITOR]={},[ROLE_DETECTIVE]={}} if not donor then tbl = table.Copy(EquipmentItems) end -- find buyable weapons to load info from for k, v in pairs(weapons.GetList()) do if v and v.CanBuy then local data = v.EquipMenuData or {} local base = { id = WEPS.GetClass(v), name = v.PrintName or "Unnamed", cost = v.Cost or 1, limited = v.LimitedStock, kind = v.Kind or WEAPON_NONE, slot = (v.Slot or 0) + 1, material = v.Icon or "vgui/ttt/icon_id", -- the below should be specified in EquipMenuData, in which case -- these values are overwritten type = "Type not specified", model = "models/weapons/w_bugbait.mdl", desc = "No description specified.", donor = v.Tier or "None" }; -- Force material to nil so that model key is used when we are -- explicitly told to do so (ie. material is false rather than nil). if data.modelicon then base.material = nil end table.Merge(base, data) -- add this buyable weapon to all relevant equipment tables for _, r in pairs(v.CanBuy) do tbl[r] = tbl[r] or {} if (v.Tier or "None")== "None" and donor == false then table.insert(tbl[r], base) elseif donor == true and (v.Tier or "None") ~= "None" then table.insert(tbl[r],base) end end end end -- mark custom items for r, is in pairs(tbl) do for _, i in pairs(is) do if i and i.id then i.custom = not table.HasValue(DefaultEquipment[r], i.id) end end end Equipment = tbl end return Equipment and Equipment[role] or {} end local function ItemIsWeapon(item) return not tonumber(item.id) end local function CanCarryWeapon(item) return LocalPlayer():CanCarryType(item.kind) end --Checks if player's donor tier is high enough local function IsSufficientTier(item) local ply = LocalPlayer() local donorlevel = ply:GetUserGroup() local weapondonor = (item.donor or "None"):lower() local dlevel = 1 for i,v in pairs(tiers) do if donorlevel:match(i) then dlevel = v break end end weapondonor = tiers[weapondonor] if dlevel >= weapondonor then return true else return false end end local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= item.cost then return true else return false end end local color_bad = Color(220, 60, 60, 255) local color_good = Color(0, 200, 0, 255) -- Creates tabel of labels showing the status of ordering prerequisites local function PreqLabels(parent, x, y) local tbl = {} tbl.credits = vgui.Create("DLabel", parent) tbl.credits:SetToolTip(GetTranslation("equip_help_cost")) tbl.credits:SetPos(x, y) tbl.credits.Check = function(s, sel) local credits = LocalPlayer():GetCredits() return credits > 0, GetPTranslation("equip_cost", {num = credits}) end tbl.owned = vgui.Create("DLabel", parent) tbl.owned:SetToolTip(GetTranslation("equip_help_carry")) tbl.owned:CopyPos(tbl.credits) tbl.owned:MoveBelow(tbl.credits, y) tbl.owned.Check = function(s, sel) if ItemIsWeapon(sel) and (not CanCarryWeapon(sel)) then return false, GetPTranslation("equip_carry_slot", {slot = sel.slot}) elseif (not ItemIsWeapon(sel)) and LocalPlayer():HasEquipmentItem(sel.id) then return false, GetTranslation("equip_carry_own") else return true, GetTranslation("equip_carry") end end tbl.bought = vgui.Create("DLabel", parent) tbl.bought:SetToolTip(GetTranslation("equip_help_stock")) tbl.bought:CopyPos(tbl.owned) tbl.bought:MoveBelow(tbl.owned, y) tbl.bought.Check = function(s, sel) if sel.limited and LocalPlayer():HasBought(tostring(sel.id)) then return false, GetTranslation("equip_stock_deny") else return true, GetTranslation("equip_stock_ok") end end for k, pnl in pairs(tbl) do pnl:SetFont("TabLarge") end return function(selected) local allow = true for k, pnl in pairs(tbl) do local result, text = pnl:Check(selected) pnl:SetTextColor(result and color_good or color_bad) pnl:SetText(text) pnl:SizeToContents() allow = allow and result and IsSufficientTier(selected) end return allow end end -- quick, very basic override of DPanelSelect local PANEL = {} local function DrawSelectedEquipment(pnl) surface.SetDrawColor(255, 200, 0, 255) surface.DrawOutlinedRect(0, 0, pnl:GetWide(), pnl:GetTall()) end function PANEL:SelectPanel(pnl) if pnl ~= nil then self.BaseClass.SelectPanel(self, pnl) if pnl then pnl.PaintOver = DrawSelectedEquipment end end end vgui.Register("EquipSelect", PANEL, "DPanelSelect") local SafeTranslate = LANG.TryTranslation local color_darkened = Color(255,255,255, 80) -- TODO: make set of global role colour defs, these are same as wepswitch local color_slot = { [ROLE_TRAITOR] = Color(180, 50, 40, 255), [ROLE_DETECTIVE] = Color(50, 60, 180, 255) }; local eqframe = nil local function TraitorMenuPopup() local ply = LocalPlayer() if not IsValid(ply) or not ply:IsActiveSpecial() then return end -- Close any existing traitor menu if eqframe and ValidPanel(eqframe) then eqframe:Close() end local credits = ply:GetCredits() local can_order = credits > 0 local dframe = vgui.Create("DFrame") local w, h = 500, 350 dframe:SetSize(w, h) dframe:Center() dframe:SetTitle(GetTranslation("equip_title")) dframe:SetVisible(true) dframe:ShowCloseButton(true) dframe:SetMouseInputEnabled(true) dframe:SetDeleteOnClose(true) local m = 5 local dsheet = vgui.Create("DPropertySheet", dframe) -- Add a callback when switching tabs local oldfunc = dsheet.SetActiveTab dsheet.SetActiveTab = function(self, new) if self.m_pActiveTab != new and self.OnTabChanged then self:OnTabChanged(self.m_pActiveTab, new) end oldfunc(self, new) end dsheet:SetPos(0,0) dsheet:StretchToParent(m,m + 25,m,m) local padding = dsheet:GetPadding() local dequip = vgui.Create("DPanel", dsheet) dequip:SetPaintBackground(false) dequip:StretchToParent(padding,padding,padding,padding) local dequipdonor = vgui.Create("DPanel", dsheet) dequipdonor:SetPaintBackground(false) dequipdonor:StretchToParent(padding,padding,padding,padding) -- Determine if we already have equipment local owned_ids = {} for _, wep in pairs(ply:GetWeapons()) do if IsValid(wep) and wep:IsEquipment() then table.insert(owned_ids, wep:GetClass()) end
[QUOTE=Sm63;47291775]Dont do this ONLY clientside. Should edit weaponry.lua too so people cant ttt_order_equipment and bypass the menu. [url]http://facepunch.com/showthread.php?t=1287293&p=46357433#post46357433[/url][/QUOTE] Ehh... I've already done that, but what you said doesn't help solve my problem.
BUMP! This is very urgent - people can't play on my server without a working T menu - please help if possible!
Is it SWEP.Cost or SWEP.cost ? because youre using SWEP.cost in the function, but, youre using SWEP.Cost in the GetEquipmentForRole function
[QUOTE=Sm63;47295751]Is it SWEP.Cost or SWEP.cost ? because youre using SWEP.cost in the function, but, youre using SWEP.Cost in the GetEquipmentForRole function[/QUOTE] Where am I using SWEP.cost ?
[QUOTE=r0uge;47295776]Where am I using SWEP.cost ?[/QUOTE] [code] local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= item.cost then return true else return false end end [/code]
[QUOTE=Sm63;47295799][code] local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= item.cost then return true else return false end end [/code][/QUOTE] That's not SWEP.cost ... [CODE]cost = v.Cost or 1,[/CODE]
I seem to have fixed it on my client with this [code]local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= (item.cost or 1) then return true else return false end end[/code]
[QUOTE=Sm63;47295950]I seem to have fixed it on my client with this [code]local function HasEnoughCredits(item) local ply = LocalPlayer() local creds = ply:GetCredits() if creds >= (item.cost or 1) then return true else return false end end[/code][/QUOTE] Ok I'll give it a try - did you change any other code?
[QUOTE=r0uge;47295974]Ok I'll give it a try - did you change any other code?[/QUOTE] nope, just copy and pasted it onto a vanilla ttt, made the C4 have a SWEP.Cost = 3, edited the code to that, and tested it. It blurred out the C4 icon if I had less than 3 credits.
[QUOTE=Sm63;47295979]nope, just copy and pasted it onto a vanilla ttt, made the C4 have a SWEP.Cost = 3, edited the code to that, and tested it. It blurred out the C4 icon if I had less than 3 credits.[/QUOTE] Ok - it kinda works, it greys out the item if you cannot afford it however you can still buy it with the buy equipment button. When I bought a 3 credit item and had 2 credits, I received the item and my credits went to 255 (overflow), at which point I could no longer buy anything. How do I fix this?
[QUOTE=r0uge;47296025]Ok - it kinda works, it greys out the item if you cannot afford it however you can still buy it with the buy equipment button. When I bought a 3 credit item and had 2 credits, I received the item and my credits went to 255 (overflow), at which point I could no longer buy anything. How do I fix this?[/QUOTE] are you sure you edited weaponry.lua also are you Disabling the button if they cant afford it correctly?
[QUOTE=Sm63;47296098]are you sure you edited weaponry.lua also are you Disabling the button if they cant afford it correctly?[/QUOTE] Nevermind - fixed (used > instead of >=) Thanks for your help!
Sorry, you need to Log In to post a reply to this thread.