When I try to use LocalPlayer():GiveAmmo( 100, "Pistol" ) in the following code....
[lua]
local CategoryContentFive = vgui.Create( "DButton" )
--CategoryContentFive:SetPos( 100, 30 )
CategoryContentFive:SetSize( 25, 25 )
CategoryContentFive:SetText( "Pistol Ammo" )
CategoryContentFive.DoClick = function()
LocalPlayer():GiveAmmo( 100, "Pistol" )
LocalPlayer():GiveAmmo( 100, "357" )
end
SCategoryList:AddItem( CategoryContentFive )
[/lua]
That code is located in a menu function in cl_init.
I get the following error:
[code]
Battleground/gamemode/cl_init.lua:68: attempt to call method 'GiveAmmo' (a nil value)
[/code]
I think it's because derma is clientside.
Help please.
You could put it on a console command, you can do any required checks with the console command and start it with `(same symbol used to open the console)
GiveAmmo() is server side stop running it clientside
That's what I thought, how should I make it give ammo then, the button. make a concommand that they execute on press, and in the specific concommand I'd have the function.
You could do something like
[lua]concommand.Add("giveammo",function(pl,cmd,args)
local ammo, amt = args[1],tonumber(args[2])
if not amt then pl:ChatPrint("That is not a valid amount of ammo!") return end
pl:GiveAmmo(amt,ammo)
end)[/lua]
Or you could make them run a concommand
Sorry, you need to Log In to post a reply to this thread.