Commands

MSK.RegisterCommand

Parameters commandName - string or table - The Command callback - function - Function to execute properties - boolean or table - Data Properties

Description Parameter: properties

  • allowConsole - boolean - Allow to execute in server console - Optional, default: true

  • showSuggestion - boolean - Show chat suggestion - Optional, default: true

  • restricted - boolean or string or table - Restrict Command to specific groups with ace permission

  • help - string - Chat suggestion

  • params - table - Paramter for the command

Parameter: params

  • name - string - name of the argument

  • type - string - type of the argument - number, string, playerId, any, player - player is only returning the playerData for ESX or QBCore

  • help - string - chat suggestion of the argument

  • optional - boolean? - Is the Argment optional? Has to be the last argument! - Optional, default: false

MSK.RegisterCommand(commandName, callback, properties)

-- Example 1
MSK.RegisterCommand('testCommand', function(source, args, raw)    
    local targetId, time, reason = args.playerId, args.time, args.reason
    
    if not reason then 
        reason = 'Unknown reason'
    end
    
    print(('Player with ID %s was banned by Player %s for Reason %s until %s'):format(playerId, source, reason, time))
end, {
    allowConsole = true,
    showSuggestion = true,
    restricted = {'superadmin', 'admin'},
    help = 'This is a Test Command',
    params = {
        {name = "playerId", type = 'playerId', help = "Target players server id"},
        {name = "time", type = 'string', help = "Ban Time"},
        {name = "reason", type = 'string', help = "Ban Reason", optional = true},
    }
})

-- Example 2 -> Framwork based (Only ESX and QBCore)
MSK.RegisterCommand('testCommand', function(Player, args, raw)    
    local Target = args.player
    
    -- ESX
    print(Player.source) -- PlayerId of the Executer
    print(Target.source) -- PlayerId of the Arguments playerId
    
    -- QBCore
    print(Player.PlayerData.source) -- PlayerId of the Executer
    print(Target.PlayerData.source) -- PlayerId of the Arguments playerId
end, {
    allowConsole = true,
    showSuggestion = true,
    returnPlayer = true, -- Return the Frameworks PlayerData
    restricted = {'superadmin', 'admin'},
    help = 'This is a Test Command',
    params = {
        {name = "player", type = 'player', help = "random argument"},
    }
})

-- As an Export:
exports.msk_core:RegisterCommand(commandName, callback, properties)

Last updated