finding a second word

[lua]
function chatconsole( player, strText)
if (string.sub(strText, 1, 4) == “/con”) then
player:ConCommand(string.sub( strText, 5 ))
end
end
hook.Add( “OnPlayerChat”, “Chatconsole”, chatconsole )
[/lua]

Ok so basicly when I want to do something like say hi but currently it wont run the command unless its only one word like status is there anyway to find a new word start or just a method to do what i want

A very handy tool for this is called **[String.Explode

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=String.Explode)**. String.Explode breaks up a string into an array of substrings based on what you want to separate them by. For example, if you did


PrintTable( string.Explode( "o", "I love Gmod!" ) )

It would print:


1 = "I l"
2 = "ve Gm"
3 = "d!"

In this case, you want to use a space, or " " as the separator.

I really don’t get why garry put the arguments of string.Explode in that order.

I feel the same way about GiveAmmo.

Garry forgot it should be func(object , arguments)

[lua]
function chatconsole( player, strText)
if (string.sub(strText, 1, 4) == “/con”) then
player:ConCommand(string.Explode(" ", string.sub( strText, 5 )))
end
end
hook.Add( “OnPlayerChat”, “Chatconsole”, chatconsole )
[/lua]
No errors just dont seems to work

[lua]function chatconsole(ply, strText)
local tab = string.Explode(" ", strText)
if tab[1] == “/con” then
ply:ConCommand(table.concat(tab, 2, #tab))
end
end
hook.Add( “OnPlayerChat”, “Chatconsole”, chatconsole )[/lua]

Why are you doing it on OnPlayerChat, do you want it to be clientside?

  1. You’re overriding the player library.
  2. OnPlayerChat is a clientside hook
  3. pl:ConCommand has an annoying tendency to result in “Server_Cannot_Execute” flag (Or whatever it is) stopping the command from running.

I want it to be clientside

As long as he is not using the player library in that function he should be fine, but still it’s not a good way to do it.