st.addCommand — Command Registration (Server)
lua
---@class StCommandParams
---@field name string Argument name (becomes key in args table)
---@field help? string Help text
---@field type? 'number' | 'playerId' | 'string' | 'longString'
---@field optional? boolean
---@class StCommandProperties
---@field help? string
---@field params? StCommandParams[]
---@field restricted? boolean | string | string[] ACE principal(s)
st.addCommand(commandName, properties, callback)
-- commandName: string or string[] (multiple aliases)
-- callback: function(source, args, raw)Examples
lua
-- Simple unrestricted command
st.addCommand('heal', {
help = 'Hel dig selv',
}, function(source, args, raw)
-- heal player
end)
-- Command with typed arguments
st.addCommand('givemoney', {
help = 'Giv penge til en spiller',
params = {
{ name = 'target', type = 'playerId', help = 'Spiller ID' },
{ name = 'amount', type = 'number', help = 'Beløb' },
},
restricted = 'group.admin',
}, function(source, args, raw)
local target = args.target -- already validated as a connected player ID
local amount = args.amount -- already a number
end)
-- Multiple command aliases
st.addCommand({ 'giveitem', 'gi' }, {
help = 'Giv item',
params = {
{ name = 'item', type = 'string' },
{ name = 'count', type = 'number', optional = true },
},
restricted = { 'group.admin', 'group.mod' },
}, function(source, args, raw)
-- handle
end)Chat suggestions are automatically registered for all commands.