LUA Scripting Help PERP

Hello.
So me and my friend is hosting a server.
Its running gamemode PERP 3.5.
So im not that experienced at lua scripting etc, but im wondering.
We got this “prop” menu where we can spawn weapons, props and alot more.
We type this code in the console : +giveitempanel
Or like I did:


bind x "+giveitempanel"

You can only open it once and then you have to reconnect to open it again.
This is the error you get when you lock the menu after opened it, then trying to reopen it.


 [@PERP3\gamemode\vgui\giveitem.lua:47] Tried to use invalid object (type Panel) (Object was NULL or not of the right type)


Please reply, thank you.

Post the full giveitem.lua file here please (in code or lua tags)


 local Frame

local function GiveItemPanelCreate()

Frame = vgui.Create("DFrame")
Frame:SetSize(ScrW() * 0.5, ScrH() * 0.5)
Frame:Center()
Frame:SetTitle("Please give me an item. *beg* *beg* *beg* *beg* *beg*")

Frame.List = vgui.Create("DPanelList", Frame)
Frame.List:StretchToParent(5, 27, 5, 5)
Frame.List:EnableVerticalScrollbar(true)
Frame.List:EnableHorizontal(true)

for i=1, #ITEM_DATABASE do
local v = ITEM_DATABASE*
if(not v) then continue end

local sub = vgui.Create("DPanel")
sub:SetSize(73, 89)
sub.Paint = function()
surface.SetDrawColor(Color(100, 100, 100, 255))
surface.DrawRect(2, 2, sub:GetWide() - 4, sub:GetTall() - 4)

surface.SetTextColor(Color(255, 255, 255, 255))
surface.SetFont("Default")
local x, y = surface.GetTextSize(v.Name)

surface.SetTextPos(5, 5)
surface.DrawText(v.Name)
end

sub.spawnicon = vgui.Create("SpawnIcon", sub)
sub.spawnicon:SetModel(v.WorldModel)
sub.spawnicon:SetPos(5, 20)
sub.spawnicon.DoClick = function()
RunConsoleCommand("perpx_giveitembeg", v.ID)
end

Frame.List:AddItem(sub)
end
end

concommand.Add("+giveitempanel", function() if(not SinglePlayer() and not LocalPlayer():IsSuperAdmin()) then return end
if(not Frame) then GiveItemPanelCreate() end Frame:MakePopup() Frame:SetVisible(true) end)
concommand.Add("-giveitempanel", function() if(not SinglePlayer() and not LocalPlayer():IsSuperAdmin()) then return end
Frame:SetVisible(false) end)


It might be thinking Frame is a table because of the (stupid) way you did List.


concommand.Add("+giveitempanel", function() if(not SinglePlayer() and not LocalPlayer():IsSuperAdmin()) then return end
if(!Frame || type(Frame)!= "Panel") then GiveItemPanelCreate() end Frame:MakePopup() Frame:SetVisible(true) end)

Untested but it’s all I can think of.

Panels are basically tables right? It’s been too long.

So can you post the whole code? :slight_smile:
Im not that smart or good at lua.


local Frame

local function GiveItemPanelCreate()

Frame = vgui.Create("DFrame")
Frame:SetSize(ScrW() * 0.5, ScrH() * 0.5)
Frame:Center()
Frame:SetTitle("Please give me an item. *beg* *beg* *beg* *beg* *beg*")

Frame.List = vgui.Create("DPanelList", Frame)
Frame.List:StretchToParent(5, 27, 5, 5)
Frame.List:EnableVerticalScrollbar(true)
Frame.List:EnableHorizontal(true)

for i=1, #ITEM_DATABASE do
local v = ITEM_DATABASE*
if(not v) then continue end

local sub = vgui.Create("DPanel")
sub:SetSize(73, 89)
sub.Paint = function()
surface.SetDrawColor(Color(100, 100, 100, 255))
surface.DrawRect(2, 2, sub:GetWide() - 4, sub:GetTall() - 4)

surface.SetTextColor(Color(255, 255, 255, 255))
surface.SetFont("Default")
local x, y = surface.GetTextSize(v.Name)

surface.SetTextPos(5, 5)
surface.DrawText(v.Name)
end

sub.spawnicon = vgui.Create("SpawnIcon", sub)
sub.spawnicon:SetModel(v.WorldModel)
sub.spawnicon:SetPos(5, 20)
sub.spawnicon.DoClick = function()
RunConsoleCommand("perpx_giveitembeg", v.ID)
end

Frame.List:AddItem(sub)
end
end

concommand.Add("+giveitempanel", function() if(not SinglePlayer() and not LocalPlayer():IsSuperAdmin()) then return end
if(!Frame || type(Frame)!= "Panel") then GiveItemPanelCreate() end Frame:MakePopup() Frame:SetVisible(true) end)
concommand.Add("-giveitempanel", function() if(not SinglePlayer() and not LocalPlayer():IsSuperAdmin()) then return end
Frame:SetVisible(false) end)

Have you edited something or is it just the same as I posted?

He added a check to see if it was a panel or not.

So what he posted, will it work?

It is more of debugged.

So can someone try to get me a code, that works?
Edit: I got it to work, with some coding and fixing.