Need some help with a derma menu. pl:Give wont work on a button.

So yea. Im trying to make my button give the player some weapons but it wont work.

Heres my code:



function start_menu()
local pl = LocalPlayer()

local smenu = vgui.Create( "DFrame" )
smenu:SetPos(0,0)
smenu:SetTall(ScrH())
smenu:SetWide(ScrW())
smenu:SetTitle( "Sellect Your Weapons!" ) 
smenu:SetVisible( true )
smenu:SetDraggable( false ) 
smenu:ShowCloseButton( false )
smenu:MakePopup()

local OCLogo = vgui.Create( "DImage", smenu )
OCLogo:SetImage( "OCDM/ocdm_startmenu_logo" )
OCLogo:SetPos( 140, 10 )
OCLogo:SizeToContents()

--local OCText = vgui.Create( "DImage", smenu )
--OCText:SetImage( "OCDM/OCDMnewtext" )
--OCText:SetPos( 190, 350 )
--OCText:SizeToContents()

local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton:SetText( "Desert Eagle And Fames" )
DermaButton:SetPos( 190, 190 )
DermaButton:SetSize( 900, 50 )
DermaButton.DoClick = function ()
smenu:Close() 
    pl:Give("weapon_real_cs_desert_eagle")
    pl:Give("weapon_real_cs_famas") -- What happens when you press the button
	end -- Guns1
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton:SetText( "Five Seven And P90" )
DermaButton:SetPos( 190, 270 )
DermaButton:SetSize( 900, 50 )
DermaButton.DoClick = function ()
smenu:Close()
    pl:Give("weapon_real_cs_five-seven")
    pl:Give("weapon_real_cs_p90")	-- What happens when you press the button
	end -- Guns2
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton:SetText( "P228 And Scout" )
DermaButton:SetPos( 190, 350 )
DermaButton:SetSize( 900, 50 )
DermaButton.DoClick = function ()
smenu:Close()
    pl:Give("weapon_real_cs_p228")
    pl:Give("weapon_real_cs_scout")	-- What happens when you press the button
	end -- Guns3
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton:SetText( "USP And TMP" )
DermaButton:SetPos( 190, 430 )
DermaButton:SetSize( 900, 50 )
DermaButton.DoClick = function ()
smenu:Close()
    pl:Give("weapon_real_cs_usp")
    pl:Give("weapon_real_cs_tmp")	-- What happens when you press the button
	end -- Guns4
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton:SetText( "Tactical Pistol And AUG/Bullpop" )
DermaButton:SetPos( 190, 510 )
DermaButton:SetSize( 900, 50 )
DermaButton.DoClick = function ()
smenu:Close()
    pl:Give("weapon_tactical_pistol")
    pl:Give("weapon_real_cs_aug")	-- What happens when you press the button
	end -- Guns5	
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton:SetText( "Disconnect" )
DermaButton:SetPos( 550, 890 )
DermaButton:SetSize( 250, 50 )
DermaButton.DoClick = function ()
smenu:Close()
    RunConsoleCommand( "disconnect" ) -- What happens when you press the button
	end -- Disconnect
end	
usermessage.Hook( "start_menu", start_menu )


Apparently lua tags doesent work :confused: Heres a pastebin with Lua tags: http://pastebin.com/ZQDXEhsY

As you can see. Im telling it that pl = LocalPlayer() but that doesent work.

Here is the error:
[gamemodes\ocdm_zombie\gamemode\cl_init.lua:95] attempt to call method ‘Give’ (a nil value)
(I get the same error for all of the buttons just a diffrent line ofc)

Thank you.

You need to add () after pl:Give

Example: pl:Give() (“weapon_real_cs_p228”)

Edit

I’m not sure if this works but it should do…

Im pretty sure this wont work but il try it now.

EDIT:
So yea what i thought. Didten work. Since im doing pl:Give**(“weapon_real_cs_p228”)**

Anyone else know how to fix this please?

Well, not sure about this, but you keep declaring


local DermaButton = vgui.Create( "DButton" )

try


function start_menu()
local pl = LocalPlayer()

local smenu = vgui.Create( "DFrame" )
smenu:SetPos(0,0)
smenu:SetTall(ScrH())
smenu:SetWide(ScrW())
smenu:SetTitle( "Sellect Your Weapons!" ) 
smenu:SetVisible( true )
smenu:SetDraggable( false ) 
smenu:ShowCloseButton( false )
smenu:MakePopup()

local OCLogo = vgui.Create( "DImage", smenu )
OCLogo:SetImage( "OCDM/ocdm_startmenu_logo" )
OCLogo:SetPos( 140, 10 )
OCLogo:SizeToContents()

--local OCText = vgui.Create( "DImage", smenu )
--OCText:SetImage( "OCDM/OCDMnewtext" )
--OCText:SetPos( 190, 350 )
--OCText:SizeToContents()

local DermaButton1 = vgui.Create( "DButton" )
DermaButton1:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton1:SetText( "Desert Eagle And Fames" )
DermaButton1:SetPos( 190, 190 )
DermaButton1:SetSize( 900, 50 )
DermaButton1.DoClick = function ()
smenu:Close() 
    pl:Give("weapon_real_cs_desert_eagle")
    pl:Give("weapon_real_cs_famas") -- What happens when you press the button
	end -- Guns1
local DermaButton2 = vgui.Create( "DButton" )
DermaButton2:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton2:SetText( "Five Seven And P90" )
DermaButton2:SetPos( 190, 270 )
DermaButton2:SetSize( 900, 50 )
DermaButton2.DoClick = function ()
smenu:Close()
    pl:Give("weapon_real_cs_five-seven")
    pl:Give("weapon_real_cs_p90")	-- What happens when you press the button
	end -- Guns2
local DermaButton3 = vgui.Create( "DButton" )
DermaButton3:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton3:SetText( "P228 And Scout" )
DermaButton3:SetPos( 190, 350 )
DermaButton3:SetSize( 900, 50 )
DermaButton3.DoClick = function ()
smenu:Close()
    pl:Give("weapon_real_cs_p228")
    pl:Give("weapon_real_cs_scout")	-- What happens when you press the button
	end -- Guns3
local DermaButton4 = vgui.Create( "DButton" )
DermaButton4:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton4:SetText( "USP And TMP" )
DermaButton4:SetPos( 190, 430 )
DermaButton4:SetSize( 900, 50 )
DermaButton4.DoClick = function ()
smenu:Close()
    pl:Give("weapon_real_cs_usp")
    pl:Give("weapon_real_cs_tmp")	-- What happens when you press the button
	end -- Guns4
local DermaButton5 = vgui.Create( "DButton" )
DermaButton5:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton5:SetText( "Tactical Pistol And AUG/Bullpop" )
DermaButton5:SetPos( 190, 510 )
DermaButton5:SetSize( 900, 50 )
DermaButton5.DoClick = function ()
smenu:Close()
    pl:Give("weapon_tactical_pistol")
    pl:Give("weapon_real_cs_aug")	-- What happens when you press the button
	end -- Guns5	
local DermaButton6 = vgui.Create( "DButton" )
DermaButton6:SetParent( smenu ) -- Set parent to our "smenu"
DermaButton6:SetText( "Disconnect" )
DermaButton6:SetPos( 550, 890 )
DermaButton6:SetSize( 250, 50 )
DermaButton6.DoClick = function ()
smenu:Close()
    RunConsoleCommand( "disconnect" ) -- What happens when you press the button
	end -- Disconnect
end	
usermessage.Hook( "start_menu", start_menu )

Well… Player:Give is serverside… and your code is client side.

Yeah, didnt think about that, You can try teams and make it so the team spawns with the weapons

Yes but doing local pl = LocalPlayer() shuld make it work.

Example:



function player_menu()
local pl = LocalPlayer()

local pmenu = vgui.Create( "DFrame" )
pmenu:SetPos( 20,20 ) 
pmenu:SetSize( 290, 170 ) 
pmenu:SetTitle( "" .. pl:Nick() .. "'s Account" )  
pmenu:SetVisible( true )
pmenu:SetDraggable( true ) 
pmenu:ShowCloseButton( true )
pmenu:MakePopup()
end


Doing pl:Nick() in a clientside code wont normaly work but doing pl = LocalPlayer() shuld tell it that pl = LocalPlayer.

Does anybody know how i would get this code to work? If its actually possible. And what am i doing wrong in my currently code?

Make a concommand server-side and run it in DoClick using RunConsoleCommand

Exactly. Thank you. Will do now.

I don’t think you’re quite grasping the concept of client- and server-side.

[editline]13th October 2010[/editline]

Automerge:argh: