-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.lua
26 lines (22 loc) · 943 Bytes
/
cmd.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cmd = { client_commands = { }, server_commands = { }, chat_commands = { } };
function cmd.register(type, command, handler)
cmd[type.."_commands"][command] = {command, handler}
end
function string.split(s, delimiter)
result = {};
if s == nil then return result end
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
engine_callback.register('pfnClientCommand', function (E, args, text)
if cmd.client_commands[args[1]] then cmd.client_commands[args[1]][2](E, args, text) end
if args[1] == "say" then
local chat_args = string.split(args[2], ' ');
if cmd.chat_commands[chat_args[1]] then return cmd.chat_commands[chat_args[1]][2](E, chat_args, text) end
end
end)
engine_callback.register('pfnServerCommand', function (args, text)
return cmd.server_commands[args[1]] and cmd.server_commands[args[1]][2](args, text);
end)