• button.DoClick Help
    6 replies, posted
Simple question, im trying to make it so when you click a button it gives you an item. [code] vddb.DoClick = function( ply ) ply:Give("ent_food_coke") end, [/code] ????
Use LocalPlayer() ?
ply doesn't exist in any sense for DoClick. You'd have to have ply defined somewhere else in the code for it to be able to pull from. On top of that, if this is a VGUI button then you can't do Ent:Give() because give is a serverside function whereas the VGUI is client side. You'd have to do a netmessage to the server telling it to give the player the weapon. In short: (Not tested, just wrote it out in basic form) [code]if SERVER then util.AddNetworkString("givingstuff") net.Receive("givingstuff",function(len,ply) stringtogivetoplayer = net.ReadString() if ply:IsValid() and len > 0 then ply:Give(stringtogivetoplayer) end end) end if CLIENT then drawstuff vddb.DoClick() = function() net.Start("givingstuff") net.WriteString("ent_food_coke") net.SendToServer() end end[/code]
I don't mean to be rude, but please start reading the basics of lua or the gmod wiki pages relating to stuff people are giving you Other users have been extremely generous and given you full net library code in two different threads now, but you still don't seem to understand it
[QUOTE=Borris_Squad;49893169]Simple question, im trying to make it so when you click a button it gives you an item. [code] vddb.DoClick = function( ply ) ply:Give("ent_food_coke") end, [/code] ????[/QUOTE] quick tip: 'ply' never means ANYTHING unless you make it mean something.
[QUOTE=NiandraLades;49893520]I don't mean to be rude, but please start reading the basics of lua or the gmod wiki pages relating to stuff people are giving you Other users have been extremely generous and given you full net library code in two different threads now, but you still don't seem to understand it[/QUOTE] I try to learn from the wiki, but i have great difficulty learning with out full examples, also when places like the wiki uses terms i dont know, and some of these terms were not mentioned or defined prior to the page etc.
I think it has a lot of examples, [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]at least here[/URL]
Sorry, you need to Log In to post a reply to this thread.