• Chat Commands lua simple help?
    12 replies, posted
[CODE]hook.Add( "OnPlayerChat", "pointrange", function( ply, text, team ) if (string.sub(text, 1, 11) == "/pointrange") then ply:PrintMessage( HUD_PRINTTALK, "1st Point:" ) return true end end)[/CODE] I have been coding for a while now, and everytime I try too make something new with something involving ply or player meta data it says: attempt to concatenate a userdata value! I used too always make commands, and use them too printmessage? but wtf, its not working anymore? Like WTF, is facepunch removing lua code? because I want too type /pointrange and get sent a message telling me: 1st point: [editline]19th July 2016[/editline] Any ideas? [editline]19th July 2016[/editline] `New Error: bad argument #1 to 'sub' (string expected, got userdata btw IVE NEVER had these errors before ever in coding!
-snip- I'm actually retarded
[QUOTE=Thane;50737910]It's "txt" not "text".[/QUOTE] Ìm still getting the error, and on Gmod Lua Wiki it says: Text!
Are you running it client side?
[QUOTE=Nick78111;50737943]Are you running it client side?[/QUOTE] Its off my server, I can put it in a client folder
-snip- [editline]19th July 2016[/editline] OnPlayerChat is a client hook. Won't work on the server.
[QUOTE=Thane;50737948]-snip- [editline]19th July 2016[/editline] OnPlayerChat is a client hook. Won't work on the server.[/QUOTE] Oh ok, then its screwed... and that dont work? this time 0 errors
Just do this. To hell with string.sub() [code] if txt == "/pointrange" then //do shit end [/code]
[QUOTE=Thane;50737961]Just do this. To hell with string.sub() [code] if txt == "/pointrange" then //do shit end [/code][/QUOTE] Can you show me that, inside of a hook so I know what im doing..
You can put it in lua/autorun/client on your server and it should work.
[CODE]hook.Add( "OnPlayerChat", "pointrange", function( ply, text, team ) if (string.sub(text, 1, 4) == "/ptr") then PrintMessage( HUD_PRINTTALK, "1st Point:" .. ply:NearestPoint( GetClosestPoint[1] ) ) return true end end)[/CODE] [ERROR] lua/autorun/client/debug.lua:141: attempt to concatenate a userdata value 1. v - lua/autorun/client/debug.lua:141 2. unknown - lua/includes/modules/hook.lua:84
I just tested [code] hook.Add( "OnPlayerChat", "pointrange", function( ply, text, team ) if text == "/pointrange" then ply:PrintMessage( HUD_PRINTTALK, "1st Point:" ) return true end end) [/code] and it works with no errors...
[code] hook.Add("OnPlayerChat", "PointRange", function (ply, txt, team) if txt = "/pointrange" then ply:PrintMessage(HUD_PRINTTALK, "1st Point:" .. ply:NearestPoint(GetClosestPoint[1])) return true end end) [/code] untested so idk. And are you sure that the error has to do with the snippet you gave us? ninja'd Just read the error and it has to do with [code]ply:NearestPoint(GetClosestPoint[1]))[/code] You're trying to put userdata into a string.. Doesn't work.
Sorry, you need to Log In to post a reply to this thread.