So I have an item. The item table has a function inside of it that will run when the entity is used.
That function sends a usermessage to the cl_init, which will draw a little menu asking what the player wants to do with it. The usermessage.Hook looks like this:
usermessage.Hook( "activateitem", function( data ) local dat = data:ReadString() local frame = vgui.Create( "DFrame" ) frame:SetPos( X/2-125, Y/2-75 ) frame:SetSize( 250, 150 ) frame:SetTitle( data:ReadString() ) frame:MakePopup( true ) local take = vgui.Create( "DButton", frame ) take:SetPos( 10, 32 ) take.DoClick = function() RunConsoleCommand( "u_use", data:ReadString() ) end end)
and it works beautifully. To a point… when I try to call the concommand “u_use” using the ‘RunConsoleCommand( “u_use”, data:ReadString() )’ it doesn’t do anything.
Now, the console command looks like this:
concommand.Add( "u_use", function( ply, cmd, args ) print( args ) end)
I removed the rest of the code which I had made into comments so that I could debug this issue. Right now it’s supposed to be printing the first argument sent (in this case it is the “data:ReadString()” that is being sent.)
Also, I am aware that these concommand arguments may only be strings. Not to mention that data:ReadString() is obviously going to be a string. To ensure that data:ReadString() has something in it, I have printed it as the frame title whenever I ran the usermessage hook. It works just fine.
If I remove the argument and modify the concommand to just be called and to then print a string, it works fine. The only part that wont work is when I try to send it the string as an argument from the usermessage. Can these things not be sent through a usermessage? I am doing it elsewhere in my code and it works just fine.
Even better would be if you could educate me on a better way to achieve this. I am aware of Net strings as well but IDK how to run a function using a net string… And even if you can a net string doesn’t carry from clientside into serverside…
Thanks for reading! Hope to get some help on this.
[editline]17th March 2014[/editline]
Alright, so I found the send to server command. When the string is sent to server, how would I be able to run a function with it?