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) fromConfig.Commandsand adds chat suggestions for them.Commands:
/adminpanel: Opens the admin panel (requiresaccess_admin_panelpermission)./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 onADMINMENU.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/getplayersif supported).[reason/duration]: Optional reason for actions like kick or ban, or duration for bans (e.g.,1h,2d,permanent).
Example:
/ckick 2 Spamming chatKicks player with ID 2 for "Spamming chat".
Available Commands
Below are the commands from ADMINMENU.FUNCTIONS, their permissions, and usage examples:
Revive (
/crevive)Permission:
player.reviveAction: Revives a player, restoring their health.
Usage:
/crevive 2Example Response: "Player revived successfully."
Notes: Logs the action with admin and player details.
Kick (
/ckick)Permission:
player.kickAction: Kicks a player from the server with an optional reason.
Usage:
/ckick 2 Spamming chatExample Response: "Player kicked successfully."
Notes: Logs the kick with the reason.
Ban (
/cban)Permissions:
player.ban.permanentorplayer.ban.temporaryAction: Bans a player temporarily (e.g.,
1h,2d) or permanently.Usage:
/cban 2 1d CheatingExample Response: "Player banned for 1d."
Notes:
Records ban details (username, reason, duration, etc.) in the
bansdatabase table.Severity is set based on reason (e.g., "high" for cheating, "low" for spam).
Auto-detects Steam and license identifiers.
Heal (
/cheal)Permission:
player.healAction: Heals a player to full health.
Usage:
/cheal 2Example Response: "Player healed successfully."
Notes: Logs the action.
Respawn (
/crespawn)Permission:
player.respawnAction: Respawns a player at their spawn point.
Usage:
/crespawn 2Example Response: "Player respawned successfully."
Notes: Logs the action.
Kill (
/ckill)Permission:
player.killAction: Kills a player.
Usage:
/ckill 2Example Response: "Player killed successfully."
Notes: Logs the action with "high" severity.
Go to Player (
/cgotoplayer)Permission:
player.teleport.to_playerAction: Teleports the admin to the target player’s location.
Usage:
/cgotoplayer 2Example Response: "Teleported to player successfully."
Notes: Logs the teleport action.
Bring (
/cbring)Permission:
player.teleport.bringAction: Teleports the target player to the admin’s location.
Usage:
/cbring 2Example Response: "Player brought successfully."
Notes: Logs the teleport action.
Freeze (
/cfreeze)Permission:
player.freezeAction: Toggles freezing/unfreezing a player (prevents movement).
Usage:
/cfreeze 2Example Response: "Player freeze toggled."
Notes:
Tracks frozen players in
freezeCache.Logs freeze/unfreeze actions.
Clear Weapons (
/cclearWeapons)Permission:
player.inventory.remove_itemsAction: Removes all weapons from a player’s inventory.
Usage:
/cclearWeapons 2Example Response: "Weapons cleared successfully."
Notes:
Uses
vorp_inventoryto remove weapons and ammo.Deletes weapon records from the
loadoutdatabase table.Logs the action with "high" severity.
Clear Items (
/cclearItems)Permission:
player.inventory.remove_itemsAction: Removes all items (non-weapons) from a player’s inventory.
Usage:
/cclearItems 2Example Response: "Items cleared successfully."
Notes:
Uses
vorp_inventoryto remove items.Deletes item records from the
inventorydatabase table.Logs the action with "high" severity.
Clear All Inventory (
/cclearAllInventory)Permission:
player.inventory.clearAction: Removes all weapons and items from a player’s inventory.
Usage:
/cclearAllInventory 2Example Response: "Inventory cleared successfully."
Notes:
Combines
clearWeaponsandclearItemsfunctionality.Logs the action with "high" severity.
Warn (
/cwarn)Permission:
player.warnAction: Issues a warning to a player with an optional reason.
Usage:
/cwarn 2 Spamming chatExample Response: "Player warned successfully (1 warning)."
Notes:
Records warnings in the
player_warningsdatabase table.Auto-kicks players with 3 or more active warnings.
Logs the warning with severity (default: "medium").
Spectate (
/cspectate)Permission:
player.spectateAction: Allows the admin to spectate a player.
Usage:
/cspectate 2Example Response: "Now spectating player."
Notes: Logs the spectate action.
How to Use Commands
Open Chat: Press
T(or your chat key) to open the chat box.Enter Command: Type the command with the player ID and optional arguments. Example:
/ckick 2 Disruptive behavior.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."View Feedback: Success messages appear in green; errors appear in red.
Customizing Commands
To add or modify commands:
Add to
Config.Commands:Edit
config/main.luato add new commands underConfig.Commands.Example:
["mycommand"] = { description = "Custom command", func = function(source, args, rawCommand) TriggerClientEvent("chat:addMessage", source, { args = {"Custom", "This is a test!"} }) end }This creates
/mycommandwith a custom action.
Add to
ADMINMENU.FUNCTIONS:Add new functions to
ADMINMENU.FUNCTIONSfor commands with acprefix.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" } endThis creates
/ccustomaction <playerID>.
Update Permissions:
Add new permissions to
Config.Permissions(e.g.,custom.action) for your role.Example: Add
"custom.action"to thehelperrole’s permissions list.
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, andrespawnrely onCore.Playermethods from VORP Core.Inventory Commands:
clearWeapons,clearItems, andclearAllInventoryusevorp_inventoryandoxmysql. Ensure these dependencies are installed.Ban/Warn Database: Bans and warnings are stored in
bansandplayer_warningstables. 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