Skip to content

Commit

Permalink
Sort commands and privs alphabetically in '/help'.
Browse files Browse the repository at this point in the history
Also make a stray variable local.
  • Loading branch information
kaeza authored and ShadowNinja committed May 24, 2014
1 parent 882e12f commit f0a9e7d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions builtin/game/chatcommands.lua
Expand Up @@ -56,24 +56,37 @@ core.register_chatcommand("help", {
end
if param == "" then
local msg = ""
cmds = {}
local cmds = {}
for cmd, def in pairs(core.chatcommands) do
if core.check_player_privs(name, def.privs) then
table.insert(cmds, cmd)
end
end
table.sort(cmds)
core.chat_send_player(name, "Available commands: "..table.concat(cmds, " "))
core.chat_send_player(name, "Use '/help <cmd>' to get more information, or '/help all' to list everything.")
elseif param == "all" then
core.chat_send_player(name, "Available commands:")
local cmds = {}
for cmd, def in pairs(core.chatcommands) do
if core.check_player_privs(name, def.privs) then
core.chat_send_player(name, format_help_line(cmd, def))
table.insert(cmds, cmd)
end
end
table.sort(cmds)
core.chat_send_player(name, "Available commands:")
for _, cmd in ipairs(cmds) do
local def = core.chatcommands[cmd]
core.chat_send_player(name, format_help_line(cmd, def))
end
elseif param == "privs" then
core.chat_send_player(name, "Available privileges:")
local privs = {}
for priv, def in pairs(core.registered_privileges) do
table.insert(privs, priv)
end
table.sort(privs)
core.chat_send_player(name, "Available privileges:")
for _, priv in ipairs(privs) do
local def = core.registered_privileges[priv]
core.chat_send_player(name, priv..": "..def.description)
end
else
Expand Down

0 comments on commit f0a9e7d

Please sign in to comment.