Commands - tayjay/SCriPt GitHub Wiki
- Aliases:
lua,script - Description: Lua command for executing Lua scripts and commands within the SCriPt environment.
- Alias:
exec,execute - Description: Executes some lua code directly.
- Peremission:
script.execute - Usage:
lua execute <code>
- Alias:
reload,rl - Description: Reloads the Lua scripts in the LabAPI plugin. This is useful for development purposes when you want to test changes without restarting the server.
- Permission:
script.reload - Usage:
lua reload
- Alias:
list,ls - Description: Lists all loaded scripts
- Permission:
script.list - Usage:
lua list
- Alias:
docs,documentation,docgen - Description: Generates documentation for the SCriPt API in the
SCriPt/Docsdirectory. - Permission:
script.docs - Usage:
lua docs
- Description: Loads a script by name from the script folders.
- Permission:
script.enable - Usage:
lua enable <script_name>
- Description: Unloads a currently-loaded script by name.
- Permission:
script.disable - Usage:
lua disable <script_name>
- Description: Shows performance statistics for a loaded script (requires
EnablePerformanceStatsin the config). See Debugging & Diagnostics. - Permission:
script.stats - Usage:
lua stats <script_name>
Script names are the file name without the
.luaextension (the same names shown bylua list).
SCriPt allows you to create custom commands that players can use in-game. These commands can be used to perform any action you would like.
When creating a command, make sure it is inside a module. It can be a shared module with the rest of your code or its own. The command is registered when the module is loaded.
The recommended way is the spec-table form, which uses named fields so you never have to remember argument order:
cmd_module = SCriPt.Mod('MyCommandModule')
cmd_module.command = SCriPt.Command{
type = CommandType.RemoteAdmin, -- Command Type
name = 'mycommand', -- Name
aliases = {'mycmd'}, -- Alternate names
description = 'Description of my command',
permission = 'script.mycommand', -- Permission required
execute = function(args, sender) -- Function to run when called
return {
response = "Hello from my command!",
result = true
}
end
}Only name and execute are required; everything else is optional (type defaults to RemoteAdmin).
The older positional form is also still supported — just be careful with the argument order:
cmd_module.command = SCriPt.Command(
CommandType.RemoteAdmin, -- type
'mycommand', -- name
{'mycmd'}, -- aliases
'Description of my command',
'script.mycommand', -- permission
function(args, sender) return { response = "Hello!", result = true } end
)- Available Command Types:
CommandType.ConsoleCommandType.RemoteAdminCommandType.Client
- Name:
- Any string that doesn't conflict with existing commands.
- Aliases:
- A list of strings that can be used as alternative names for the command.
- Description:
- A string that describes what the command does. Is returned in the help command.
- Permission:
- A string that specifies the permission required to run the command.
- Leave empty if no permission is required.
- Execute:
- Define or reference a function that takes two arguments:
-
args: A table of the arguments passed to the command.args[1]is the first argument after the command name,args[2]the second, and so on. Use#argsfor the count. -
sender: The sender of the command.sender.Playeris thePlayerwho ran it (nil for the server console),sender.Nameis their display name, andsender.Respond(message, success)sends them a reply.
-
- Must return a table with:
-
response: A string that will be sent back to the player. -
result: A boolean indicating whether the command was successful or not.
-
- Define or reference a function that takes two arguments: