Kay I get this problem when i try to run my script.
attempt to call method 'Give' (a nil value)
This is the code:
[LUA]
function META:GiveWeapon(string)
Player:Give( string )
end
[/LUA]
Please help.
"Player" should be "self"
[CODE]function META:GiveWeapon(wep)
self:Give( wep )
end
[/CODE]
Try this
you need to put [lua]local META = FindMetaTable("Player") [/lua] before your function
and i think Player:Give() should be self:Give()
Not Working eh :(
I'm getting this
\gamemode\sh_player.lua:16: attempt to call method 'Give' (a nil value)
My SH_player.lua
[LUA]
function META:BuyWeapon(item)
self:Give( item )
end
[/LUA]
slay3r36, I have that.
the string you use for item is valid, right ?
try to put
[lua]concommand.Add("giveme", function(ply, cmd, args) ply:BuyWeapon(args[1]) end)[/lua]
and run
[CODE] giveme weapon_crowbar[/CODE] in your console
Hmmm, that works. Try help me here, Ima give you the full script.
sh_players.lua
[LUA]
function META:BuyWeapon(item)
self:Give( item )
end
[/LUA]
AddItems.lua
[LUA]
Items = {}
Items.Weapons = {}
Items.Weapons[1] = {"models/weapons/w_IRifle.mdl","Ar2","A powerful combine Weapon!", 500, "weapon_ar2"}
Items.Weapons[2] = {"models/weapons/W_pistol.mdl","Pistol","A standart weapon for War!", 200, "weapon_pistol"}
[/LUA]
The Menu, cl_init.lua
[LUA]
for k, v in pairs( Items.Weapons ) do
local icon = vgui.Create( "SpawnIcon", IconList )
icon:SetModel( v[1] )
icon:SetTooltip( "Name: " .. v[2] .. "\nDescription: " .. v[3] .. "\nPrice: " .. v[4] .. " dollars" )
CategoryList:AddItem( icon )
icon.DoClick = function( icon, ply )
LocalPlayer():BuyWeapon( v[5] )
LocalPlayer():RemoveMoney( v[4] )
end
end
[/LUA]
Make sure that your 'META:BuyWeapon" function is in your init.lua or a serverside file.
By the name of the lua file the function is in, sh_players sounds to be shared, yet you cannot use Give clientside.
Okay i've added the Meta function to init.lua and now when i press the icon to give me the gun i get this.
gamemode\init.lua:81: attempt to call method 'Give' (a nil value)
[LUA]
function META:BuyWeapon(item)
self:Give( item ) -- LINE 81
end
[/LUA]
try to remove the (") in "weapon_pistol" like[lua]Items.Weapons[2] = {"models/weapons/W_pistol.mdl","Pistol","A standart weapon for War!", 200, weapon_pistol} [/lua]
Doesn't matter, I get the same error ! Wtf is up with this.
You can't use :Give client-side, you need to make a concommand server-side and use [b][url=http://wiki.garrysmod.com/?title=G.RunConsoleCommand]G.RunConsoleCommand [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] in the icons DoClick function.
THanks guys i got it working.
Sorry, you need to Log In to post a reply to this thread.