GetCommandHandlers: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 26: | Line 26: | ||
for _, subtable in pairs( getCommandHandlers() ) do | for _, subtable in pairs( getCommandHandlers() ) do | ||
local commandName = subtable[1] | local commandName = subtable[1] | ||
local | local res = subtable[2] | ||
if not commandsList[ | if not commandsList[res] then | ||
commandsList[ | commandsList[res] = {} | ||
end | end | ||
table.insert(commandsList[ | table.insert(commandsList[res], commandName) | ||
end | end | ||
for | for res, commands in pairs(commandsList) do | ||
local | local resName = getresInfo(res, "name") or getresName(res) | ||
outputChatBox("== ".. | outputChatBox("== "..resName.. " ==") | ||
for _, command in pairs(commands) do | for _, command in pairs(commands) do | ||
Revision as of 13:28, 9 October 2016
This function is used to retrieve a list of all the registered command handlers of a given resource (or of all resources).
Syntax
Click to collapse [-]
Servertable getElementsByType ( [ resource theResource ] )
Optional Arguments
- theResource: The resource from which you wish to retrieve all command handlers. Or leave it empty to retrieve command handlers of all resources.
Returns
Returns a table containing all the commands of the given resource or a table with subtables containing the command and theResource pointer ( { "command", theResource } )
Example
Click to collapse [-]
ServerThis simple example add a command to output list of all commands in the chat.
addCommandHandler("commands",
function()
local commandsList = {}
for _, subtable in pairs( getCommandHandlers() ) do
local commandName = subtable[1]
local res = subtable[2]
if not commandsList[res] then
commandsList[res] = {}
end
table.insert(commandsList[res], commandName)
end
for res, commands in pairs(commandsList) do
local resName = getresInfo(res, "name") or getresName(res)
outputChatBox("== "..resName.. " ==")
for _, command in pairs(commands) do
outputChatBox("/"..command)
end
end
end
)
See Also
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown