Ulysses

General => Developers Corner => Topic started by: JasonMan on February 22, 2016, 04:23:26 AM

Title: How does ULib.sayCmds work?
Post by: JasonMan on February 22, 2016, 04:23:26 AM
I have a code that automatically detects all chat messages that have "!" or "/" as their first character, and redirects them to a command. If a command doesn't exist, it says "blah is not a registered command. For a list of registered commands, please type !commands".
Now, ulx has it's own set of chat commands, so I wanted to just skip the code if the command is registered.
So I did this:

Code: [Select]
function CCheckForChatCommand( ply, text )
local args = string.Split( text, " " )
if table.HasValue( table.GetKeys( ULib.sayCmds ), args[1] ) then return end
--Rest of code
end

But, for some reason, it always returns false.
So I wanted to check it with lua_run and a string I put myself.
(http://i.imgur.com/yHKS6Pk.png)

Why does this not work?
Title: Re: How does ULib.sayCmds work?
Post by: roastchicken on February 22, 2016, 08:10:29 AM
You're splitting the string at every space. If you type !command, string.Split will return { "!command" } (a table with one value, the chat message). If you type !command argument, string.Split will return { "!command", "argument" }. I don't know exactly how ULib.sayCmds is set up, but I assume that its keys (if the keys are the command names) do not contain the exclamation mark at the front. If they do, then I guess you're having another problem.

edit:

After looking at the ULib repo, it looks like ULib.sayCmds's keys are commands and they are the exact same as the command, so if the command is !command then ULib.sayCmds["!command"] should exist. The only reason I could think of for them not matching is trailing or leading spaces. string.Trim() both the command input and the ULib.sayCmds key and see if it works then.
Title: Re: How does ULib.sayCmds work?
Post by: JasonMan on February 22, 2016, 09:05:13 AM
So apparently ULib.sayCmds stores the keys with a space at the end of them ("!armor " and not "!armor"), so that worked.
Thanks