• derma menu give player weapon
    13 replies, posted
right i have been looking on google and on facepunch for a way for me to have it so when i click on the button it gives a weapon [code]function dermaShop() local ply = LocalPlayer() local base = vgui.Create( "DFrame" ) local butt = vgui.Create( "DButton" ) base:SetPos( ScrW()/2 - 225, ScrH()/2 - 100 ) base:SetSize( 450, 200 ) base:SetVisible(true) base:SetTitle( "Hi Mum" ) base:SetDraggable(false) base:ShowCloseButton(true) base:MakePopup() butt:SetParent( base ) butt:SetText( "Meow" ) butt:Center() butt:SetSize( 150, 50 ) butt:SetSize( 150, 50 ) function butt:DoClick() RunConsoleCommand("GiveMeAGun") end end[/code] and i keep getting a error [code][ERROR] gamemodes/order/gamemode/init.lua:287: attempt to call method 'Give' (a nil value) 1. unknown - gamemodes/order/gamemode/init.lua:287 2. unknown - lua/includes/modules/concommand.lua:54[/code] any ideas on what to do for giving a weapon a gun when the button is clicked?
What's your serverside code?
[QUOTE=mib999;47838267]What's your serverside code?[/QUOTE] concommand.Add("giveM16", function (ply, cmd, args) ply:Give("weapon_or_flamethrower") end)
How? You run GiveMeAGun ConCommand and not giveM16
Either way the problem is that you are calling the :Give function clientside.
[QUOTE=mib999;47838489]How? You run GiveMeAGun ConCommand and not giveM16[/QUOTE] sorry i was editing it xD "concommand.Add("GiveMeAGun", function (ply, cmd, args) ply:Give("weapon_or_flamethrower") end)" [editline]30th May 2015[/editline] [QUOTE=Robotboy655;47838495]Either way the problem is that you are calling the :Give function clientside.[/QUOTE] yes i know that but even the concommand isnt on the client file but is there a way around this? any way is there a way i can do this so the player get the weapon when they click on the button
if (SERVER) then concommand.Add("GiveMeAGun", function (ply, cmd, args) ply:Give("weapon_or_flamethrower") end) end
[QUOTE=Robotboy655;47838545]if (SERVER) then concommand.Add("GiveMeAGun", function (ply, cmd, args) ply:Give("weapon_or_flamethrower") end) end[/QUOTE] when clicking the button i get Unknown command: GiveMeAGun
Your console command must be created in a serverside or shared file. gamemodes/order/gamemode/init.lua will do.
[QUOTE=Robotboy655;47838695]Your console command must be created in a serverside or shared file. gamemodes/order/gamemode/init.lua will do.[/QUOTE] its in my shared i still get it
Your shared is not included from init.lua
[QUOTE=Robotboy655;47838743]Your shared is not included from init.lua[/QUOTE] shared.lua [code] if (SERVER) then concommand.Add("GiveMeAGun", function (ply, cmd, args) ply:Give("weapon_or_flamethrower") end) end [/code] cl_init.lua [code] include( 'shared.lua' ) include( 'sh_init.lua' ) function dermaShop() local ply = LocalPlayer() local base = vgui.Create( "DFrame" ) local butt = vgui.Create( "DButton" ) base:SetPos( ScrW()/2 - 225, ScrH()/2 - 100 ) base:SetSize( 450, 200 ) base:SetVisible(true) base:SetTitle( "Hi Mum" ) base:SetDraggable(false) base:ShowCloseButton(true) base:MakePopup() butt:SetParent( base ) butt:SetText( "Meow" ) butt:Center() butt:SetSize( 150, 50 ) function butt:DoClick() RunConsoleCommand("GiveMeAGun") end end usermessage.Hook( "Openplz", dermaShop ) [/code] init.lua [code] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) function GM:PlayerButtonDown( ply, key ) if (key == 13) then umsg.Start( "Openplz", ply ) umsg.End() end end [/code]
Does it still print the Lua error? Does it print "unknown command"? Have you restarted your game?
[QUOTE=Robotboy655;47838901]Does it still print the Lua error? Does it print "unknown command"? Have you restarted your game?[/QUOTE] so i did this and it worked xD if (SERVER) then concommand.Add("GiveMeAGun", function (ply, cmd, args) ply:Give("weapon_or_flamethrower") ply:PrintMessage( HUD_PRINTTALK, "You got the FlameThrower" ) end) end
Sorry, you need to Log In to post a reply to this thread.