• Why does my spawnmenu not work.
    14 replies, posted
Hi guys, my code isn't working.. Why? - Nothing happens when i run custommenu [lua]function proplist() local props = {} props[1] = "models/props_junk/garbage_milkcarton002a.mdl" props[2] = "models/props_junk/PopCan01a.mdl" props[3] = "models/props_junk/garbage_takeoutcarton001a.mdl" props[4] = "models/props_junk/watermelon01.mdl" props[5] = "models/props_junk/garbage_metalcan001a.mdl" props[6] = "models/props_lab/box01a.mdl" props[7] = "models/props_lab/box01b.mdl" local frame = vgui.Create("DFrame") local IconList = vgui.Create("DPanelList", frame) frame:Center() frame:SetSize(250,200) frame:SetTitle("Prop Catalog") frame:MakePopup() IconList:EnableVerticalScrollbar( true ) IconList:EnableHorizontal( true ) IconList:SetPadding( 4 ) IconList:SetPos(10,30) IconList:SetSize(200,160) for k,v in pairs(props) do local icon = vgui.Create( "SpawnIcon", IconList ) icon:SetModel( v ) IconList:AddItem( icon ) icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("gm_spawn", v) end end end concommand.Add("custommenu", proplist)[/lua] Also i want to be able to add it to my server so when people press Q it opens this.
You need to move [lua]concommand.Add("custommenu", proplist) [/lua] outside the function, so after the final "end".
Now getting error :( spawnmenu.lua:12: attempt to index global 'vgui' (a nil value)
You're running this on the client, right? Not the server?
On singleplayer.
Are you running the file with lua_openscript_cl?
Yes but i just now get unknown command even thought it suggests it. [editline]10:41PM[/editline] I was running without cl but i see now. -- Still getting Unknown Command when i do custommenu [editline]11:14PM[/editline] All fixed, changed custommenu to slist and it works...
Post the entire code so people know how you fixed it.
Oh ok sure. Stick this in your cl_init.lua for your gamemode if you wanna. [lua] function proplist() print ("List Opening") local props = {} props[1] = "models/props_junk/garbage_milkcarton002a.mdl" props[2] = "models/props_junk/PopCan01a.mdl" props[3] = "models/props_junk/garbage_takeoutcarton001a.mdl" props[4] = "models/props_junk/watermelon01.mdl" props[5] = "models/props_junk/garbage_metalcan001a.mdl" props[6] = "models/props_lab/box01a.mdl" props[7] = "models/props_lab/box01b.mdl" local slframe = vgui.Create("DFrame") local IconList = vgui.Create("DPanelList", slframe) slframe:Center() slframe:SetSize(250,200) slframe:SetTitle("Prop Catalog") slframe:MakePopup() IconList:EnableVerticalScrollbar( true ) IconList:EnableHorizontal( true ) IconList:SetPadding( 4 ) IconList:SetPos(10,30) IconList:SetSize(200,160) for k,v in pairs(props) do local icon = vgui.Create( "SpawnIcon", IconList ) icon:SetModel( v ) IconList:AddItem( icon ) icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("gm_spawn", v) end end end concommand.Add("slist", proplist) function GM:OnSpawnMenuOpen( ply ) LocalPlayer():ConCommand("slist") end [/lua]
Okay, I don't need it at all, just that some people might have a similar problem and see it :v:
Well i donated it to the Wiki, trying to find out how i can have a small derma menu with tools on it...
Make a custom button that does the console command to give you to tool :v: (A pretty hacky way, but atleast it's a start :P)
I didn't know the tools can be given thru console lol. What's the syntax of that anyway because I only know gmod_tool but that's justa swep name lol
I'm not sure but I think it's something like [lua]ply:Give( "gmod_tool" )[/lua] and then [lua]ply:ConCommand("gmod_toolmode modegoeshere")[/lua] [SP]To get the leaf blower from JBmod type this in your console: gmod_toolmode leafblower[/SP]
Oo thanks i will try that [editline]11:54AM[/editline] ok im getting an error of : spawnmenu.lua:51: function arguments expected near '=' The code being [lua] weldb:SetSize(100, 50) weldb:SetPos(250, 30) weldb:SetText("Weld") weldb:DoClick = function( weldb ) LocalPlayer():ConCommand("gmod_toolmode weld") [/lua] I fixed that.. Mainly because i did :doclick and not .doclick.
Sorry, you need to Log In to post a reply to this thread.