Admin Commands Guide

This guide explains how to use admin commands in the RedM admin menu. Commands are registered dynamically and include actions like reviving, kicking, banning, and more. Below, we detail how commands are set up, how to use them, and how to customize them, explained clearly for easy understanding.

Command Setup

The admin menu registers commands from two sources: Config.Commands and ADMINMENU.FUNCTIONS. These commands are executed in-game via chat (e.g., /adminpanel) and provide admin functionality.

Command Registration

The following code registers commands defined in Config.Commands:

AddEventHandler('onResourceStart', function(resourceName)
    if GetCurrentResourceName() ~= resourceName then return end
    for command, data in pairs(Config.Commands) do
        RegisterCommand(command, data.func, false)
        TriggerEvent('chat:addSuggestion', '/' .. command, data.description)
    end
end)
  • What it does: When the resource starts, it registers each command (e.g., adminpanel, report, myreports) from Config.Commands and adds chat suggestions for them.

  • Commands:

    • /adminpanel: Opens the admin panel (requires access_admin_panel permission).

    • /report: Opens the report creation modal.

    • /myreports: Shows your submitted reports.

Dynamic Admin Commands

The CreateAdminCommands function registers commands from ADMINMENU.FUNCTIONS with a c prefix (e.g., /crevive, /ckick):

function CreateAdminCommands()
    for commandName, func in pairs(ADMINMENU.FUNCTIONS) do
        RegisterCommand("c"..commandName, function(source, args)
            local adminSource = source
            if not args[1] then
                TriggerClientEvent('chat:addMessage', adminSource, {
                    color = { 255, 0, 0 },
                    multiline = true,
                    args = { "ERROR", _("admin_command_missing_player", commandName) }
                })
                return
            end
            local targetSource = tonumber(args[1])
            if not targetSource or not GetPlayerName(targetSource) then
                TriggerClientEvent('chat:addMessage', adminSource, {
                    color = { 255, 0, 0 },
                    multiline = true,
                    args = { "ERROR", _("admin_command_player_not_found") }
                })
                return
            }
            local data = {
                player = {
                    source = targetSource,
                    username = ADMINMENU.Players[targetSource] and ADMINMENU.Players[targetSource].DiscordData.username or "Unknown",
                },
                reason = table.concat(args, " ", 2),
                duration = args[2]
            }
            local result = ADMINMENU.FUNCTIONS[commandName](adminSource, data)
            if result and result.message then
                local color = result.success and { 0, 255, 0 } or { 255, 0, 0 }
                TriggerClientEvent('chat:addMessage', adminSource, {
                    color = color,
                    multiline = true,
                    args = { "INFO", result.message }
                })
            end
        end)
    end
    debugPrint("Admin commands successfully created.")
end
CreateAdminCommands()
  • What it does: Creates commands like /crevive, /ckick, etc., based on ADMINMENU.FUNCTIONS. Each command requires a player ID as the first argument and an optional reason or duration.

  • How it works:

    • Checks if the player ID is provided and valid.

    • Executes the corresponding function from ADMINMENU.FUNCTIONS.

    • Sends a success (green) or error (red) message to the admin.

Using Admin Commands

General Command Format

  • Syntax: /c<command> <playerID> [reason/duration]

    • <playerID>: The server ID of the target player (visible in the admin panel or via /getplayers if supported).

    • [reason/duration]: Optional reason for actions like kick or ban, or duration for bans (e.g., 1h, 2d, permanent).

  • Example: /ckick 2 Spamming chat

    • Kicks player with ID 2 for "Spamming chat".

Available Commands

Below are the commands from ADMINMENU.FUNCTIONS, their permissions, and usage examples:

  1. Revive (/crevive)

    • Permission: player.revive

    • Action: Revives a player, restoring their health.

    • Usage: /crevive 2

    • Example Response: "Player revived successfully."

    • Notes: Logs the action with admin and player details.

  2. Kick (/ckick)

    • Permission: player.kick

    • Action: Kicks a player from the server with an optional reason.

    • Usage: /ckick 2 Spamming chat

    • Example Response: "Player kicked successfully."

    • Notes: Logs the kick with the reason.

  3. Ban (/cban)

    • Permissions: player.ban.permanent or player.ban.temporary

    • Action: Bans a player temporarily (e.g., 1h, 2d) or permanently.

    • Usage: /cban 2 1d Cheating

    • Example Response: "Player banned for 1d."

    • Notes:

      • Records ban details (username, reason, duration, etc.) in the bans database table.

      • Severity is set based on reason (e.g., "high" for cheating, "low" for spam).

      • Auto-detects Steam and license identifiers.

  4. Heal (/cheal)

    • Permission: player.heal

    • Action: Heals a player to full health.

    • Usage: /cheal 2

    • Example Response: "Player healed successfully."

    • Notes: Logs the action.

  5. Respawn (/crespawn)

    • Permission: player.respawn

    • Action: Respawns a player at their spawn point.

    • Usage: /crespawn 2

    • Example Response: "Player respawned successfully."

    • Notes: Logs the action.

  6. Kill (/ckill)

    • Permission: player.kill

    • Action: Kills a player.

    • Usage: /ckill 2

    • Example Response: "Player killed successfully."

    • Notes: Logs the action with "high" severity.

  7. Go to Player (/cgotoplayer)

    • Permission: player.teleport.to_player

    • Action: Teleports the admin to the target player’s location.

    • Usage: /cgotoplayer 2

    • Example Response: "Teleported to player successfully."

    • Notes: Logs the teleport action.

  8. Bring (/cbring)

    • Permission: player.teleport.bring

    • Action: Teleports the target player to the admin’s location.

    • Usage: /cbring 2

    • Example Response: "Player brought successfully."

    • Notes: Logs the teleport action.

  9. Freeze (/cfreeze)

    • Permission: player.freeze

    • Action: Toggles freezing/unfreezing a player (prevents movement).

    • Usage: /cfreeze 2

    • Example Response: "Player freeze toggled."

    • Notes:

      • Tracks frozen players in freezeCache.

      • Logs freeze/unfreeze actions.

  10. Clear Weapons (/cclearWeapons)

    • Permission: player.inventory.remove_items

    • Action: Removes all weapons from a player’s inventory.

    • Usage: /cclearWeapons 2

    • Example Response: "Weapons cleared successfully."

    • Notes:

      • Uses vorp_inventory to remove weapons and ammo.

      • Deletes weapon records from the loadout database table.

      • Logs the action with "high" severity.

  11. Clear Items (/cclearItems)

    • Permission: player.inventory.remove_items

    • Action: Removes all items (non-weapons) from a player’s inventory.

    • Usage: /cclearItems 2

    • Example Response: "Items cleared successfully."

    • Notes:

      • Uses vorp_inventory to remove items.

      • Deletes item records from the inventory database table.

      • Logs the action with "high" severity.

  12. Clear All Inventory (/cclearAllInventory)

    • Permission: player.inventory.clear

    • Action: Removes all weapons and items from a player’s inventory.

    • Usage: /cclearAllInventory 2

    • Example Response: "Inventory cleared successfully."

    • Notes:

      • Combines clearWeapons and clearItems functionality.

      • Logs the action with "high" severity.

  13. Warn (/cwarn)

    • Permission: player.warn

    • Action: Issues a warning to a player with an optional reason.

    • Usage: /cwarn 2 Spamming chat

    • Example Response: "Player warned successfully (1 warning)."

    • Notes:

      • Records warnings in the player_warnings database table.

      • Auto-kicks players with 3 or more active warnings.

      • Logs the warning with severity (default: "medium").

  14. Spectate (/cspectate)

    • Permission: player.spectate

    • Action: Allows the admin to spectate a player.

    • Usage: /cspectate 2

    • Example Response: "Now spectating player."

    • Notes: Logs the spectate action.

How to Use Commands

  1. Open Chat: Press T (or your chat key) to open the chat box.

  2. Enter Command: Type the command with the player ID and optional arguments. Example: /ckick 2 Disruptive behavior.

  3. Check Permissions: Ensure you have the required permission (set in Config.Permissions). If not, you’ll see an error like "You do not have permission."

  4. View Feedback: Success messages appear in green; errors appear in red.

Customizing Commands

To add or modify commands:

  1. Add to Config.Commands:

    • Edit config/main.lua to add new commands under Config.Commands.

    • Example:

      ["mycommand"] = {
          description = "Custom command",
          func = function(source, args, rawCommand)
              TriggerClientEvent("chat:addMessage", source, { args = {"Custom", "This is a test!"} })
          end
      }
    • This creates /mycommand with a custom action.

  2. Add to ADMINMENU.FUNCTIONS:

    • Add new functions to ADMINMENU.FUNCTIONS for commands with a c prefix.

    • Example:

      ADMINMENU.FUNCTIONS.customaction = function(source, data)
          if not HasPermission(source, "custom.action") then
              return { success = false, message = "No permission" }
          end
          -- Your custom logic here
          return { success = true, message = "Custom action completed" }
      end
    • This creates /ccustomaction <playerID>.

  3. Update Permissions:

    • Add new permissions to Config.Permissions (e.g., custom.action) for your role.

    • Example: Add "custom.action" to the helper role’s permissions list.

  4. Test Commands:

    • Restart the resource or server to apply changes.

    • Test the command in-game to ensure it works as expected.

Notes

  • Player ID: Find player IDs in the admin panel or via a command like /getplayers (if implemented).

  • Logging: All actions are logged with details (admin, target, reason, severity) for accountability.

  • VORP Core: Commands like revive, heal, and respawn rely on Core.Player methods from VORP Core.

  • Inventory Commands: clearWeapons, clearItems, and clearAllInventory use vorp_inventory and oxmysql. Ensure these dependencies are installed.

  • Ban/Warn Database: Bans and warnings are stored in bans and player_warnings tables. Ensure your database is set up correctly.

  • Localization: Messages use _() for translation (e.g., _("success_kicked_player")). Update your language files for custom messages.

By following this guide, you can use and customize admin commands to manage your RedM server effectively. Always test changes in a development environment first.

Last updated