-- Simple commandChat:RegisterCommand('me', function(source, args, rawCommand) local message = table.concat(args, ' ') local player = Fetch:Source(source) local char = player:GetData('Character') local name = char:GetData('First') .. ' ' .. char:GetData('Last') -- Broadcast to nearby players Chat.Send.System:Single(source, name .. ' ' .. message)end, { help = 'Roleplay action', params = { { name = 'action', help = 'What your character does' } }}, -1)-- Job-restricted commandChat:RegisterCommand('cuff', function(source, args, rawCommand) local targetId = tonumber(args[1]) if not targetId then return end TriggerEvent('mythic-police:server:CuffPlayer', source, targetId)end, { help = 'Cuff a player', params = { { name = 'id', help = 'Target player ID' } }}, 1, { job = 'police', reqDuty = true})
Parameters are the same as RegisterCommand (without job).Example:
Chat:RegisterAdminCommand('heal', function(source, args, rawCommand) local targetId = tonumber(args[1]) or source Callbacks:ClientCallback(targetId, 'Damage:Heal', true) Chat.Send.System:Single(source, 'Player healed')end, { help = 'Heal a player', params = { { name = 'id', help = 'Target player ID (optional)' } }}, -1)
-- When a player goes on duty, refresh their commandsAddEventHandler('mythic-jobs:server:ClockedIn', function(source, characterId, jobName) Chat:Refresh:Commands(source)end)AddEventHandler('mythic-jobs:server:ClockedOut', function(source, characterId, jobName) Chat:Refresh:Commands(source)end)
Validate Command Arguments
Chat:RegisterCommand('give', function(source, args, rawCommand) local targetId = tonumber(args[1]) local item = args[2] local count = tonumber(args[3]) or 1 if not targetId or not item then Chat.Send.System:Single(source, 'Usage: /give [id] [item] [count]') return end -- Process commandend, { help = 'Give item to player', params = { { name = 'id', help = 'Target player ID' }, { name = 'item', help = 'Item name' }, { name = 'count', help = 'Amount (default: 1)' } }}, 2)