• Giving weapons through Derma?
    2 replies, posted
I've tried a few things to get the player to be given a weapon after they press the button but it keeps giving me [CODE]attempt to call method 'Give' (a nil value)[/CODE] this is the peice of code i've tried [B]lua/autorun/client/cl_core.lua[/B] [CODE] local ply = LocalPlayer() local M16 = vgui.Create( "DButton", ShopPanel1 ) M16:SetVisible( false ) M16:SetSize( 210, 30 ) M16:SetPos( 75, 65 ) M16:SetText( "M16" ) M16.DoClick = function () ply:Give("weapon_zm_m16") end[/CODE]
Give is a server side function, and you are trying to call it on the client. So what you will need to do is either make a server file for the client one to communicate to, or make this one shared. So move it to lua/autorun/shared/sh_core.lua or whatever you want to call it. [lua] if CLIENT then local ply = LocalPlayer() local M16 = vgui.Create( "DButton", ShopPanel1 ) M16:SetVisible( false ) M16:SetSize( 210, 30 ) M16:SetPos( 75, 65 ) M16:SetText( "M16" ) M16.DoClick = function () RunConsoleCommand("giveM16") end else concommand.Add("giveM16", function (ply, cmd, args) ply:Give("weapon_zm_m16") end) end [/lua] Now you will run the console command "giveM16" on the client, which will run that function on the server.
[QUOTE=Sio;43568072]Give is a server side function, and you are trying to call it on the client. So what you will need to do is either make a server file for the client one to communicate to, or make this one shared. So move it to lua/autorun/shared/sh_core.lua or whatever you want to call it. [lua] if CLIENT then local ply = LocalPlayer() local M16 = vgui.Create( "DButton", ShopPanel1 ) M16:SetVisible( false ) M16:SetSize( 210, 30 ) M16:SetPos( 75, 65 ) M16:SetText( "M16" ) M16.DoClick = function () RunConsoleCommand("giveM16") end else concommand.Add("giveM16", function (ply, cmd, args) ply:Give("weapon_zm_m16") end) end [/lua] Now you will run the console command "giveM16" on the client, which will run that function on the server.[/QUOTE] but wont this allow people to put givem16 in their console?
Sorry, you need to Log In to post a reply to this thread.