• unknown command: what am i doing wrong?
    5 replies, posted
Below is the code I'm working on. It is in a custom addon under lua\autorun. I've tried it under autorun\server with no effect. I'm not very good with Lua, obviously, and would appreciate anyones help. When I run either of the added console commands, I get "unknown command". [code] function CustomClass() if player:IsUserGroup("CustomUserClass") then game.ConsoleCommand("rp_CustomClass" player:Name()"\n") end end concommand.Add("CustomClass",CustomClass) function checkCustomUserClass(ply) if player:IsUserGroup("CustomUserClass") then ply:ChatPrint("You are an CustomUserClass on the server") else ply:ChatPrint("You are not an CustomUserClass on this server!") end end concommand.Add("info_CustomUserClass", checkCustomUserClass) [/code]
[lua]function CustomClass(player , command , arguments) if player:IsUserGroup("CustomUserClass") then game.ConsoleCommand("rp_CustomClass "..player:Name().."\n") end end concommand.Add("CustomClass",CustomClass) function checkCustomUserClass(ply) if ply:IsUserGroup("CustomUserClass") then ply:ChatPrint("You are an CustomUserClass on the server") else ply:ChatPrint("You are not an CustomUserClass on this server!") end end concommand.Add("info_CustomUserClass", checkCustomUserClass)[/lua] In Lua, like in almost other languages, in order to use a variable in a string you must concatenate it. Lua's concatenation operator is ".." Edit: Offtopic, but using a player's name in game.ConsoleCommand is unadvisable. If they use the name ";sv_cheats 1" then there is a possibility that your script will enable cheats when they change class.
that helps a lot, thanks. I'm getting this error now: attempt to call method 'IsUserGroup' (a nil value) Offtopic: command injection is a nonissue as only alphanumeric chars are allowed in the username.
Hmm, I see no obvious reasons it would do that.. Do you get the error only for the first command? If so maybe it has to do with you trying to overwrite the "player" library.. Try changing it to "ply", it's worth a try! :wink:
Hehe, you rhymed. I think you might want to use Lua_reloadents so you can tweak it.
ok, updated [code] function CustomClass(pl , command , arguments) if pl:IsUserGroup( "dave" ) then game.ConsoleCommand("rp_dave "..pl:Name().."\n") else game.ConsoleCommand("exit") end end concommand.Add("CustomClass", CustomClass) function checkCustomClass(pl) if pl:IsUserGroup( "dave" ) then pl:ChatPrint("You are Dave on the server") else pl:ChatPrint("You are not a Dave on this server!") end end concommand.Add("info_CustomClass", checkCustomClass) [/code] results in: ] info_customclass You are not a Dave on this server! even though when i logon to the server it says: "Hey 'dave' - You're in the 'dave' group on this server." [editline]12:06PM[/editline] figured it out. ulx was causing a conflict.
Sorry, you need to Log In to post a reply to this thread.