Command Palette

Search for a command to run...

Custom rules

React to in-game events with your own conditions and actions, without writing code.

Custom rules let you handle things that the built-in detections do not know about. A rule has three parts:

  1. an event that happens on your server,
  2. optional conditions that decide whether the rule matches,
  3. one or more actions that run in order when it does.

For example: when a vehicle model you do not allow is about to be created, block it and post a message to your staff channel.

Rules live on the Rules page. You need the Custom Rules permission, and because rules can ban players and fire server events, give it to very few people. Rules run on your server, so they work even while the dashboard is closed.

Create a rule#

  1. Click Create Rule.
  2. Give it a name (up to 80 characters) and leave Enabled on.
  3. Under When this event happens, pick an event.
  4. Under Only if these conditions match, add conditions. Leave it empty to match every occurrence.
  5. Under Then..., add actions and drag them into the order you want.
  6. Click Save rule. The rule is sent to your server immediately.

A live preview shows the condition as an expression while you build it. Each rule shows how often it was triggered and when last, and can be switched on and off, edited, duplicated or deleted.

The list of events comes from your server. When you open the dialog while the server is offline you see the last known list, and an event that your resource version does not support is marked Unsupported by this server version, so that rule will not run.

Events#

EventFires whenCan be blocked
playerConnectingA player is connecting to the server.Yes
entityCreatingA ped, vehicle or object is about to be created.Yes
entityRemovedAn entity was removed.No
giveWeaponEventA weapon is given to a ped.Yes
removeWeaponEventA weapon is removed from a ped.Yes
removeAllWeaponsEventAll weapons are removed from a ped.Yes
weaponDamageEventA player deals weapon damage.Yes
startProjectileEventA player launches a projectile.Yes
explosionEventA player causes an explosion.Yes
fireEventA player starts a fire.Yes
ptfxEventA player triggers a particle effect.Yes
clearPedTasksEventA player clears a ped's tasks.Yes
givePedScriptedTaskEventA scripted task is given to a ped.Yes
startNetworkSyncedSceneEventA player starts a networked synced scene.Yes

An event that can be blocked can be cancelled by a rule before the game applies it.

Conditions#

A condition compares a field of the event with a value.

Fields#

Every event has three base fields:

FieldMeaning
sourceThe player ID.
nameThe player's name.
timestampWhen the event happened.

Event specific fields are written data.<name>:

EventFields
playerConnectingdata.license, data.license2, data.steam, data.discord, data.fivem, data.xbl, data.ip, data.identifierCount
entityCreating, entityRemoveddata.entityType (1 ped, 2 vehicle, 3 object), data.model, data.populationType (1 to 5 ambient, 0 unknown, 6 permanent, 7 mission, which means script spawned)
giveWeaponEventdata.pedId, data.weaponType, data.ammo, data.givenAsPickup, data.givenByScript
removeWeaponEventdata.pedId, data.weaponType
removeAllWeaponsEventdata.pedId
weaponDamageEventdata.weaponType, data.weaponDamage, data.damageType, data.silenced, data.willKill, data.hitComponent, data.isHeadShot
startProjectileEventdata.projectileHash, data.weaponHash, data.ownerNetId, data.initialPositionX, data.initialPositionY, data.initialPositionZ
explosionEventdata.explosionType, data.damageScale, data.posX, data.posY, data.posZ, data.isAudible, data.isInvisible, data.cameraShake
fireEventdata.posX, data.posY, data.posZ, data.weaponHash
ptfxEventdata.effectHash, data.assetHash, data.scale, data.entityNetId
clearPedTasksEventdata.pedId, data.immediately
startNetworkSyncedSceneEventdata.pedCount, data.animPartialHash, data.cameraAnimHash, data.attachEntityBone, data.hasAttachEntity, data.rate

Pick Custom field... to type any other field, for example data.myField. Any simple value of the event can be read, so a field that a newer FiveM version adds works too. A field may be up to four levels deep, like data.a.b.

Use the Events page to see real events and their raw data, and the Asset Explorer to find the model hashes you need for data.model.

Operators#

OperatorMeaning
equals (==), not equal to (!=)Compare for equality.
greater than (>), greater or equal (>=), less than (<), less or equal (<=)Compare numbers. The value must be a number.
not equal (Lua) (~=)Lua's own not-equal.
exists, does not existCheck that a field is present. These take no value.

Join conditions with AND or OR. AND is evaluated before OR. A rule can have up to 20 conditions.

Actions#

A rule can have up to 10 actions, run in order.

ActionWhat it does
Block EventCancels the event so it never happens. Only for events that can be blocked, and at most one per rule. For playerConnecting it refuses the connection with Connection blocked by a custom rule.
Ban PlayerBans the player permanently with the reason you give. Shown as Custom Rule: <rule name> in the ban list. For playerConnecting the connection is refused at once, without video evidence.
Kick PlayerDisconnects the player with a reason.
Discord LogPosts a message to a Discord webhook. The URL must be a Discord webhook. The message is optional, and without it a default embed is sent.
Trigger EventFires an event. Server scope fires it on the server. Client scope sends it to the player who caused the event, so it needs an event with a player. Give a name with letters, numbers and : . _ - and an optional JSON payload.

Reasons are limited to 200 characters, a Discord message to 1500 and a payload to 2000.

Placeholders#

In reasons, Discord messages and trigger payloads you can use these placeholders, which are replaced when the rule fires:

Output
{source}  {name}  {event}  {rule}  {timestamp}  {data.x}

For example, a ban reason of Spawned blocked model {data.model} becomes Spawned blocked model -1281684762.

What to expect at runtime#

  • Whitelisted admins are not punished. When txAdmin Whitelist is on, admins are never banned or kicked by a rule. See Permissions and whitelisting.
  • A player is punished at most once every 15 seconds by rules. Further ban or kick actions in that window are skipped as player was punished moments ago.
  • Webhooks are rate limited. A rule posts to Discord at most 5 times per 10 seconds, so an event that fires constantly cannot flood your channel. Mentions are always disabled.
  • Rules are checked strictly. A rule with any invalid part is dropped as a whole instead of running with a condition missing, because a missing condition could make a ban rule match far more than you meant.
  • Dev Mode applies. While Dev Mode is on, kick and ban actions are only logged. Block actions on events other than playerConnecting still cancel the event.
  • The console tells you. A matched rule prints a line like "Block restricted vehicles" matched entityCreating from Player [12] -> block, discord, at most every 3 seconds per rule and player.

Limits per server: 100 rules, 20 conditions and 10 actions per rule.

Example: block a vehicle model#

  1. Event: entityCreating.
  2. Conditions: data.entityType equals 2 AND data.model equals the model hash from the Asset Explorer.
  3. Actions: Block Event, then Discord Log with the message {name} [{source}] tried to spawn a blocked vehicle ({data.model}).

Test it with Dev Mode first. The console shows when it matches and what it would do.