Chat Commands

[lua]
AddChatCommand(“x”, “x”)
[/lua]

Dosent work? What will?

Also, How can I make something print in the players chat?

It obviously dosn’t work because this is GLua not DarkRP.

That’s not a default command.

[lua]local chatcommands = {};

function AddChatCommand(name, func)
chatcommands[name] = func;
end

hook.Add(“PlayerSay”, “ChatCommand”, function(ply, text)
local tab = string.Explode(" “, text);
local cmd = table.remove(tab, 1);
if cmd then
for name, func in pairs(chatcommands) do
if (”/"…name:lower()) == cmd:lower() then
func(ply, cmd, tab);
break;
end
end
return “”;
end
end);

AddChatCommand(“kick”, function(ply, cmd, args) – Example usage. (use like concommand.Add)
if ply:IsAdmin() and args[1] then
for _, p in ipairs(player.GetAll()) do
if p:Nick():find(args[1]) then
p:Kick();
return ;
end
end
end
end);[/lua]

Here is a simple chat command script, use it like concommands.

When you run that script you cannot use chat.

http://www.wegame.com/watch/cant/

Here’s what I use in my RP script.

[lua]

local prefix = “!”
chatcommand = {}
chatcommand.Commands = {}

function chatcommand.Add( command, func )

chatcommand.Commands[prefix .. command] = func

end

function chatcommand.Remove( command )

chatcommand.Commands[prefix .. command] = nil

end

function chatcommand.PlayerSay( ply, text, teamchat )

local cmd = string.Explode( " ", text )
	
local tr = ply:GetEyeTrace()
if( tr.Entity:IsPlayer() ) then

	text = string.gsub( text, "!picker", tr.Entity:Nick() )

end
	
for K, V in pairs( chatcommand.Commands ) do

	if( string.lower(cmd[1]) == K ) then
		
		local cmd = string.gsub( text, cmd[1] .. " ", "" )
		local args = string.Explode( " ", cmd )
	
		chatcommand.Commands[K]( ply, K, args )
		return false
		
	end
	
end

return text

end
hook.Add( “PlayerSay”, “ChatCommandPlayerSay1010123”, chatcommand.PlayerSay );

– Works like this:

local function TheTime( ply, cmd, args )

ply:ChatPrint( "The current time is: " .. os.date( "%H:%M:%S" ) );

end
chatcommand.Add( “thetime”, TheTime );
– You don’t need to add the prefix, just the command itself.
[/lua]