So, I'm making a little VGUI tab for mayors items and it doesn't seem to put in the items, it works perfectly but doesn't add any items.
[CODE]
function GM.MayorPanel ( )
local W, H = 770, 580; ///
local DermaPanel = vgui.Create("DFrame")
DermaPanel:SetPos(ScrW() * .5 - W * .5, ScrH() * .5 - H * .5)
DermaPanel:SetSize(W, H)
DermaPanel:SetTitle("Mayor Panel")
DermaPanel:SetVisible(true)
DermaPanel:SetDraggable(false)
DermaPanel:ShowCloseButton(true)
DermaPanel:MakePopup()
local PropertySheet = vgui.Create("DPropertySheet", DermaPanel)
PropertySheet:StretchToParent(5, 30, 5, 5)
PropertySheet:AddSheet("Mayor Items", EntitiesTab())
end
function EntitiesTab()
local EntitiesPanel = vgui.Create("DPanelList")
EntitiesPanel:EnableVerticalScrollbar( true )
function EntitiesPanel:Update()
self:Clear(true)
local EntCat = vgui.Create("DCollapsibleCategory")
EntCat:SetLabel("Entities")
local EntPanel = vgui.Create("DPanelList")
EntPanel:SetSize(470, 200)
EntPanel:SetAutoSize(true)
EntPanel:SetSpacing(1)
EntPanel:EnableHorizontal(true)
EntPanel:EnableVerticalScrollbar(true)
local function AddEntIcon(Model, description, command)
local icon = vgui.Create("SpawnIcon")
icon:InvalidateLayout( true )
icon:SetModel(Model)
icon:SetIconSize(64)
icon:SetToolTip(description)
icon.DoClick = function() LocalPlayer():ConCommand("say "..command) end
EntPanel:AddItem(icon)
end
for k,v in pairs(M.B) do
AddEntIcon(v.model, "Newbie", "/buyitem "..v.name)
end
EntCat:SetContents(EntPanel)
self:AddItem(EntCat)
end
EntitiesPanel:Update()
return EntitiesPanel
end
[/CODE]
[CODE]
M.B = {}
table.insert(M.B, {name = T.Name, model = T.Model, entity = T.Ent, price = T.Price})
function M.AddMItem(t)
table.Add(M.B,t)
end
//
local T = {} // Don't change it!!!!!
T.Ent = "bank_atm"
T.Model = "models/env/misc/bank_atm/bank_atm.mdl"
T.Name = "Bank ATM" // Name of the item
T.Desc = "People can withdraw/deposit money and the city will get 2% of it." // Description of the item
T.Price = 2500 // Price of the item (from the CITY's money)
T.Inf = false // How many seconds it will be removed in.
M.AddMItem({T}) // Don't change it!!!!!
[/CODE]
You put the T in birdbrackets at M.AddMItem, this will make it a "double" table.
[lua]
M.B = {
[1] = {
T = {
["Ent"] = "bank_atm"
etc.
}
}
}
[/lua]
Remove the {} around T and you would get
[lua]
M.B = {
T = {
["Ent"] = "bank_atm"
etc.
}
}
[/lua]
instead.
Now it shows up items, but gets this:
It gets stuck in the corner when you press it up.
It shows the Description, runs the command, but doesn't display model :L
[CODE]
Trace:
1: Line 32 "Trace" lua\includes\extensions\debug.lua
2: Line 106 "SetModel" lua\vgui\spawnicon.lua
3: Line 38 "AddEntIcon" RP\gamemode\vgui\mayorpanel.lua
4: Line 46 "Update" RP\gamemode\vgui\mayorpanel.lua
5: Line 53 "EntitiesTab" RP\gamemode\vgui\mayorpanel.lua
6: Line 18 "MayorPanel" RP\gamemode\vgui\mayorpanel.lua
7: Line 110 "Function" RP\gamemode\cl_networking.lua
8: Line 87 "(null)" lua\includes\modules\usermessage.lua
[@RP\gamemode\vgui\mayorpanel.lua:46] bad key to string index (number expected, got string)
G[/CODE]
Oh, indexes are case-sensitive, it should be v.Model and v.Name, also you should put v.Name inside paranthesis as it could maybe interfer with the string concat.
[QUOTE=Donkie;30628997]You put the T in birdbrackets at M.AddMItem, this will make it a "double" table.
[lua]
blah
[/lua]
instead.[/QUOTE]
You forgot commas after each value.
If you got time you could add me on steam and help me xD
[url]http://steamcommunity.com/id/765735645647423[/url]
[QUOTE=zzaacckk;30637828]You forgot commas after each value.[/QUOTE]
I was just giving an example of how his table would look like.
Sorry, you need to Log In to post a reply to this thread.