args on Chat command

I’m tired from trying lol
[lua]
function DropMoney( ply, text, args )
if(string.sub(text, 1, 4) == “/bla”) then
ply:ChatMessage(“Test”…args)
end
end
[/lua]
What wrong here D:

http://www.facepunch.com/showthread.php?927717-Chat-Commands :3:

Man, finding that was way too hard… we need something like a sticky with a list of useful libraries.

[editline]15th October 2010[/editline]

[lua]require( “chatcommand” )
local function DropMoney( ply, cmd, args )
– Drop money here
end
chatcommand.Add( “dropmoney”, DropMoney )[/lua]

Get out.

You should put it in the chat hook.

I thought his reply was valid?

EDIT:
Oops, rated myself by accident :raise: At least I can own up to doing it.

I hooked it

hook.Add( “PlayerSay”, “DropMoney”, DropMoney );

I just forgot to add this to the code

The point it’s just not working…

:raise:

[editline]15th October 2010[/editline]

You had some errors in your original code. PlayerSay hook doesn’t pass args, only the whole chat message. Also, there’s no function Player.ChatMessage, you probably meant **[Player.ChatPrint

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.ChatPrint)**

Try this
[lua]local function DropMoney( ply, text )
if text:sub( 1, 4 ) == “/bla” then
ply:ChatPrint("Test: " … text:sub( 5 ) )
end
end
hook.Add( “PlayerSay”, “SomeUniqueName”, DropMoney )
[/lua]

Ok and i tryed your thing it’s just not doing nothing lol

And i can see the sub is 5

But if he typing 10 it will drop 1(cause 1 is in the 5)

No?

You have it server-side, right?

With only one argument, it returns from that character to the end of the string.

("/bla 1010"):sub( 5 ) == “1010”

Oh ok thanks i try it

Yea i putted it on init in gm and from what i know init is server-side

You’re missing a parenthesis in your amount declaration, it should be

[lua]local amount = math.floor( tonumber( text:sub( 5 ) ) )[/lua]

yea yea i just edited i can’t belive i missed it

Edit:

just one more thing

When someone typing it

It’s writing the command too example

Bla:Hey
OtherBla:Hey
Bla:/dropmoney 10

understand? it typing the command in chat how i can block it i mean when someone writing it so other people wont see it :S

return “”