Redirect chat command

I trying to redirect chat command to another without losing the entered text.

My example:

[LUA]
function Redirect( ply, text)
if (string.sub(text, 1, 4) == “//”) then
hook.Run(“PlayerSay”, ply, "/ooc "… string.sub( text, 5 ));
return “”;
end
end
hook.Add( “PlayerSay”, “Redirect”, Redirect )
[/LUA]

My way doesn’t work for me, please help to find a solution

I guess you could do something like this:



function Redirect( ply, text)
    if (string.sub(text, 1, 2) == "//") then
        ply:ConCommand("say" , "/ooc "..text)
        return "";
    end
end
hook.Add( "PlayerSay", "Redirect", Redirect )


on line 2 you should use string.sub(text, 1, 2) instead of 1, 4 since you are only looking for two characters. Also I changed the hook.run line to use the “say” console command instead.