Scripts and Exports

Let another resource on your server ban, warn and kick through MonoAdmin, and log its commands to Server Logs with one line.

MonoAdmin gives the other resources on your server two exports. createPunishment lets an anticheat or any script ban, warn or kick a player through MonoAdmin, so the punishment shows up in the panel and holds across rejoins like any other. logCommand lets a script record that a player ran a command, for Server Logs. Both are server-side exports that you call from Lua or JavaScript. They are the only two exports meant for other resources.

MonoAdmin has no public API, no API keys and no ACE permissions. These exports and the inbound webhooks are what you can integrate with.

Allow a Script to Punish

By default no resource may punish through MonoAdmin. A script that is not on your list gets a refusal, so a stray or malicious resource cannot ban your players. You name the ones you trust.

  1. Open Settings > Game Settings. You need the Edit Settings permission to change it.
  2. Find Scripts That May Punish: “An anticheat or other script on your server can ban, warn and kick players through MonoAdmin. Name the resources you trust; no resource can until you do.”
  3. Type the resource’s name and press Enter, for example my-anticheat.
  4. Press Save Changes in the bar that appears.

The name has to match the resource’s folder name exactly. It can use letters, digits, dots, dashes and underscores, up to 64 characters, and case counts. You can name up to 16 resources. Saved changes reach a connected server at once.

A resource that is not on the list gets this result, and your server console prints a warning once for that resource:

{ ok = false, code = 'forbidden', message = 'resource my-anticheat may not punish through MonoAdmin; allow it under Settings > Game settings in the panel' }

createPunishment

exports.monoadmin:createPunishment(source, type, reason, durationSeconds, callback)
Argument What it is
source The player’s server ID, as a number from 1 to 65535. The player must be online and tracked by MonoAdmin. If your value is a string, pass tonumber(source).
type 'ban', 'kick' or 'warn'.
reason Text the player will read, 1 to 500 characters. Control characters become spaces, invisible formatting characters are removed and runs of spaces collapse.
durationSeconds For a ban only: how long, in whole seconds. 0, or leaving it out, is permanent. A timed ban lasts at least 60 seconds and at most 10 years; a shorter one is refused by MonoAdmin with bad_request, not bad_duration. For a kick or a warning it must be 0 or left out.
callback Optional. A function that receives the result table.

The result is a plain table, passed to the callback:

{ ok = true, punishment_id = 42 }
{ ok = false, code = 'player_offline' }

Examples

-- A seven day ban, with a callback
exports.monoadmin:createPunishment(source, 'ban', 'Cheating detected by my-anticheat', 7 * 24 * 60 * 60, function(result)
  if not result.ok then
    print(('MonoAdmin did not ban %s: %s'):format(source, result.code))
  end
end)

-- A permanent ban
exports.monoadmin:createPunishment(source, 'ban', 'Blacklisted event triggered', 0)

-- A warning the player has to confirm
exports.monoadmin:createPunishment(source, 'warn', 'Do not use that vehicle model here')

-- A kick
exports.monoadmin:createPunishment(source, 'kick', 'Idle for too long')

What Happens

  • A ban is attributed to the game server and the calling resource, never to a staff member. It uses your project’s Default ban (sticky or not sticky, set in Settings > Overview), is saved to your server’s local copy of the bans and holds even if MonoAdmin is unreachable. An online player is removed with the ban message as soon as the ban reaches your server, and cannot rejoin. See How Bans Are Enforced and Sticky Bans and Linked Accounts.
  • A kick removes the player with “You were kicked from this server.” and your reason, and MonoAdmin records it. If MonoAdmin cannot be asked (the link is down, or the player is not tracked), the player is still removed, and the result tells you why it was not recorded.
  • A warning appears on the player’s screen and must be confirmed before they play on. See Warnings, Mutes and Community Service.

A ban or a warning needs MonoAdmin to record it. Without a link, the call fails and nothing happens to the player.

Result Codes

When ok is false, code says why.

Code Meaning
forbidden The resource is not on your list. message says what to do.
bad_source source is not a whole number from 1 to 65535.
bad_type type is not 'ban', 'kick' or 'warn'.
bad_reason The reason is missing, empty after cleaning, or longer than 500 characters.
bad_duration The duration is not a whole number of seconds, is negative, is too long, or was given for a kick or warning. A timed ban that is too short passes this check and comes back as bad_request instead.
player_offline There is no such player online.
player_not_tracked MonoAdmin does not track that player, for example while the project is over its plan’s player limit.
rate_limited The script is calling too often (see below).
cloud_unavailable Your server is not connected to MonoAdmin.
bad_answer MonoAdmin’s answer could not be read.

Refusals from MonoAdmin itself come back with their own code, for example conflict when the player already has an active ban.

Rate Limits

Each calling resource may make a burst of 10 calls, then one every 6 seconds. On top of that, MonoAdmin limits scripted punishments for the whole project to a burst of 20, then one every 2 seconds, so a script gone wrong cannot ban your whole server in a blink. Anything over the limit is refused with rate_limited.

How They Show in the Panel

  • Punishments and the player’s profile list the punishment as issued by the script, labeled with the resource’s name and your server’s name, for example “my-anticheat (My Server)”. Staff can revoke it like any other. See Punishments.
  • Audit Logs record it with Game server as the actor and the script’s name in the details. See Audit Logs.
  • Server Logs show a scripted kick as “my-anticheat kicked Mara Quinn”, and a refused rejoin as a connection refused at the door. See Server Logs.
  • Staff Activity never counts it for any staff member.

logCommand

exports.monoadmin:logCommand(source, line, side)
Argument What it is
source The server ID of a connected player.
line The whole command line as the player typed it, including its arguments.
side Optional: 'server' or 'client', to say where the command ran.

It returns true when the line was taken and false when it was not, for example because the player is not connected, the line is empty or a limit was reached. It never raises an error.

The line appears under the Commands type in Server Logs as “{player} ran {command}, logged by a script”, with the calling resource’s name. Any resource may call it, and no allow-list applies. If the Commands type is switched off under Settings > Features, nothing is recorded.

RegisterCommand('tow', function(source, args, raw)
  exports.monoadmin:logCommand(source, raw, 'server')
  -- your command
end, false)

Lines are limited: a resource may log up to 100 at once and then 50 a second, and a single player up to 20 at once and then 5 a second. A longer command line is cut. A line goes through MonoAdmin’s redaction of link codes and tokens, but it cannot know your script’s secrets, so do not log commands that take a PIN or password.

To log every command of a resource without editing its code, add shared_script '@monoadmin/logging.lua' to its manifest instead. That is covered, with when not to, in Server Logs.

If You Renamed MonoAdmin’s Folder

If MonoAdmin’s folder has another name, such as admin (see Using Another Folder Name), both exports answer under that name and under monoadmin. exports.admin:createPunishment(...) and exports.monoadmin:createPunishment(...) do the same thing, so scripts written for the usual name work as they are. The calling script is still the one named on the allow-list. The only time exports.monoadmin does not reach your MonoAdmin is when another resource on the server really is called monoadmin.

One thing to know about restarts: FiveM remembers an export the first time a script calls it and forgets it only when a resource of that name stops. When you restart MonoAdmin, a script that already called exports.monoadmin is still holding the old one and gets an error on its next call. Restart that script after MonoAdmin, or restart the server. Calls written with the folder’s own name, exports.admin, do not have this problem.