Custom rules let you handle things that the built-in detections do not know about. A rule has three parts:
- an event that happens on your server,
- optional conditions that decide whether the rule matches,
- 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#
- Click Create Rule.
- Give it a name (up to 80 characters) and leave Enabled on.
- Under When this event happens, pick an event.
- Under Only if these conditions match, add conditions. Leave it empty to match every occurrence.
- Under Then..., add actions and drag them into the order you want.
- 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#
| Event | Fires when | Can be blocked |
|---|---|---|
playerConnecting | A player is connecting to the server. | Yes |
entityCreating | A ped, vehicle or object is about to be created. | Yes |
entityRemoved | An entity was removed. | No |
giveWeaponEvent | A weapon is given to a ped. | Yes |
removeWeaponEvent | A weapon is removed from a ped. | Yes |
removeAllWeaponsEvent | All weapons are removed from a ped. | Yes |
weaponDamageEvent | A player deals weapon damage. | Yes |
startProjectileEvent | A player launches a projectile. | Yes |
explosionEvent | A player causes an explosion. | Yes |
fireEvent | A player starts a fire. | Yes |
ptfxEvent | A player triggers a particle effect. | Yes |
clearPedTasksEvent | A player clears a ped's tasks. | Yes |
givePedScriptedTaskEvent | A scripted task is given to a ped. | Yes |
startNetworkSyncedSceneEvent | A 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:
| Field | Meaning |
|---|---|
source | The player ID. |
name | The player's name. |
timestamp | When the event happened. |
Event specific fields are written data.<name>:
| Event | Fields |
|---|---|
playerConnecting | data.license, data.license2, data.steam, data.discord, data.fivem, data.xbl, data.ip, data.identifierCount |
entityCreating, entityRemoved | data.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) |
giveWeaponEvent | data.pedId, data.weaponType, data.ammo, data.givenAsPickup, data.givenByScript |
removeWeaponEvent | data.pedId, data.weaponType |
removeAllWeaponsEvent | data.pedId |
weaponDamageEvent | data.weaponType, data.weaponDamage, data.damageType, data.silenced, data.willKill, data.hitComponent, data.isHeadShot |
startProjectileEvent | data.projectileHash, data.weaponHash, data.ownerNetId, data.initialPositionX, data.initialPositionY, data.initialPositionZ |
explosionEvent | data.explosionType, data.damageScale, data.posX, data.posY, data.posZ, data.isAudible, data.isInvisible, data.cameraShake |
fireEvent | data.posX, data.posY, data.posZ, data.weaponHash |
ptfxEvent | data.effectHash, data.assetHash, data.scale, data.entityNetId |
clearPedTasksEvent | data.pedId, data.immediately |
startNetworkSyncedSceneEvent | data.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#
| Operator | Meaning |
|---|---|
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 exist | Check 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.
| Action | What it does |
|---|---|
| Block Event | Cancels 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 Player | Bans 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 Player | Disconnects the player with a reason. |
| Discord Log | Posts 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 Event | Fires 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:
{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
playerConnectingstill 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#
- Event:
entityCreating. - Conditions:
data.entityTypeequals2ANDdata.modelequalsthe model hash from the Asset Explorer. - 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.