args on Chat command

I’m tired from trying lol
function DropMoney( ply, text, args )
if(string.sub(text, 1, 4) == “/bla”) then
What wrong here D: :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
chatcommand.Add( “dropmoney”, DropMoney )[/lua]

Get out.

You should put it in the chat hook.

I thought his reply was valid?

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…


[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](**

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

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)


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


just one more thing

When someone typing it

It’s writing the command too example

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 “”