Rule Engine
The rule engine lets you add your own checks on top of the built-in detections, without writing code. A rule says: when this happens, and this is true, do this. For example, block a vehicle model nobody should spawn, or turn away Discord accounts that are only a few days old.
The Example Rules Ship Turned Off
CXA comes with two example rules, block_adder and new_discord_accounts. Both are disabled. Open them, read how they are built, then change them or turn them on.
How It Works
A rule has four parts:
| Part | Panel name | Config key | What it is |
|---|---|---|---|
| Event | When | Event | The game event that starts the check, for example a vehicle being spawned. |
| Condition | Condition | Condition | A short test, for example model == 'adder'. |
| Actions | Then | Actions | What happens when the condition is true, for example block and log. |
| Reason | Reason shown in logs | Reason | The text in logs, kick screens and ban records. |
- When the anticheat starts, CXA reads every enabled rule and translates its condition once. A condition it cannot read is skipped, with a warning in the console.
- CXA only listens to an event when at least one enabled rule uses it. Events nobody uses cost nothing.
- Each time the event happens, CXA checks every enabled rule for that event. Every rule that matches carries out its actions.
- Staff who bypass the anticheat are never matched. For the
playerConnectingevent, only the Bypass Identifiers list counts. See Staff Bypass. - Rules run on top of the built-in detections. They never switch a detection off.
Setting It Up
Step 1 — Open the Rules
Open Configuration → Network & rules → Security rules in the web panel. Each rule is a row you can expand, with an on/off switch on the right.
Step 2 — Add a Rule
Type a name in the field that says "New rule name, e.g. block_tanks" and click Add rule. The name is turned into lowercase, and characters other than a-z, 0-9 and _ become _. It can be up to 32 characters long.
A new rule starts switched off, on the Entity spawned event, with the condition model == 'adder' and the actions Block and Log, so you have an example to edit.
Step 3 — Pick the Event and Write the Condition
Choose the event under When. Then write the condition under Condition. The line below the field lists the fields you can use, for example Fields: model, type, script. If the panel cannot read the condition, the line turns red and explains why, and the rule shows an Error badge.
Step 4 — Choose the Actions and the Reason
Under Then, click one or more of Block, Log, Warn, Kick and Ban. Write a short Reason shown in logs, up to 120 characters. Without a reason, the rule name is used.
Step 5 — Turn It On and Save
Switch the rule on and click Save changes. Your server picks it up within a minute and reloads the anticheat.
Rules in config.lua
In config.lua, and in code you paste into Import code, rules live in Config.Rules. Each rule is a table under its name:
Config.Rules = {
block_lazer = { -- Rule name: a-z, 0-9 and _
Enabled = true, -- false = rule is ignored
Event = 'entityCreating', -- When: one of the five events below
Condition = "model == 'lazer' and script == true", -- Double quotes outside, single quotes inside
Actions = { 'block', 'log' }, -- Then: block, log, warn, kick, ban
Reason = 'Spawned a fighter jet', -- Shown in logs
},
}Import code adds the rules you paste to the ones you already have; it does not delete others. With a license, the rules saved in the panel replace the ones in config.lua.
Events
| Event | Panel name | When it fires | What block does |
|---|---|---|---|
entityCreating | Entity spawned | A player's game creates a networked vehicle, ped or object | The entity is not created. |
explosionEvent | Explosion | A player's game reports an explosion | The explosion is cancelled. |
weaponDamageEvent | Weapon damage | A player's game reports damage to another ped or player | The damage is cancelled. |
chatMessage | Chat message | A player sends a chat message through the standard chat resource | The message is not sent. |
playerConnecting | Player connecting | A player connects to the server | The connection is refused. |
Fields
| Field | Description | Available in |
|---|---|---|
model | The entity's model. Write the name in quotes, for example 'adder'. CXA turns it into the game's hash. | entityCreating |
type | The kind of entity: 1 = ped, 2 = vehicle, 3 = object. | entityCreating |
script | true when a script created the entity, false for traffic and other ambient population. | entityCreating |
type | The explosion type number, the same numbers as in the explosion types list, for example 7 = Car, 37 = ProxMine. | explosionEvent |
damageScale | The damage scale of the explosion. | explosionEvent |
invisible | true when the explosion is invisible. | explosionEvent |
audible | true when the explosion makes a sound. | explosionEvent |
weapon | The weapon. Write the name in quotes, for example 'WEAPON_PISTOL'. CXA turns it into the game's hash. | weaponDamageEvent |
damage | The damage of the hit, as a number. | weaponDamageEvent |
distance | Meters between the shooter and the entity that was hit. 0 when CXA cannot find the target. | weaponDamageEvent |
headshot | true when the hit landed on the head. | weaponDamageEvent |
message | The full text of the chat message. | chatMessage |
name | The player's FiveM name. | playerConnecting |
discordAge | Age of the player's Discord account in days, worked out from the Discord ID. Empty when the player has no Discord identifier. | playerConnecting |
hasDiscord | true when the player has a Discord identifier. | playerConnecting |
hasSteam | true when the player has a Steam identifier. | playerConnecting |
identifiers | How many identifiers the player connects with. | playerConnecting |
Field names are case-sensitive. Write discordAge, not discordage.
Condition Language
Comparisons
| Operator | Meaning | Example |
|---|---|---|
== | Equal | model == 'adder' |
~= or != | Not equal | type ~= 2 |
< | Less than | discordAge < 30 |
<= | Less than or equal | damage <= 0 |
> | Greater than | distance > 300 |
>= | Greater than or equal | damageScale >= 2 |
contains | The text contains this part | message contains 'discord.gg' |
==and~=compare numbers as numbers and everything else as text, ignoring case.name == 'ADMIN'also matchesadmin.<,<=,>and>=only work with numbers. If one side is not a number, the comparison is false. A player without Discord has nodiscordAge, sodiscordAge < 30is false for them.containslooks for a piece of text and ignores case. Write it in lowercase, with a space on both sides.
Values
- Text goes in single or double quotes:
'adder'or"adder". Text without quotes cannot be read. - Numbers are written as they are:
30,1.5. trueandfalseare written without quotes.- For
modelandweapon, write the name. CXA turns it into the game's hash, so the case does not matter:'WEAPON_PISTOL'and'weapon_pistol'are the same. A number hash works too. containsdoes not search inside model or weapon names, because CXA compares hashes, not names. Use==or~=for those fields.- In
config.luathe whole condition is a Lua string. Put double quotes around it and single quotes inside:Condition = "model == 'adder'". In the panel you only type the condition itself.
Combining With and / or
andmeans every part must be true.ormeans at least one part must be true.andis checked beforeor.a or b and cmeansa or (b and c).- Parentheses are not supported. Write
(a or b) and casa and c or b and c. andandorignore case but need a space on both sides.- Quoted text cannot contain the words and or or between spaces, because CXA splits the condition at those words first.
Example: hasDiscord == false or discordAge < 7 matches players without Discord and players whose Discord account is younger than 7 days.
Actions
| Action | Panel button | On in-game events | On playerConnecting |
|---|---|---|---|
block | Block | Cancels the event: the entity, explosion, damage or chat message never happens. | Refuses the player with You cannot join this server: <reason>. |
log | Log | Logs a Security rule detection: Detections channel, the panel's Detections tab, the console and an in-game staff alert. | Writes Security rule matched to the Connections channel. |
warn | Warn | Shows the player an on-screen warning and logs to the Warns channel. | No effect. |
kick | Kick | Removes the player with your reason and logs to the Kicks channel. | Refuses the player like block and logs to the Connections channel. |
ban | Ban | Bans the player permanently, removes them and logs to the Bans channel. | Bans the player permanently, shows the ban screen and logs to the Connections channel. |
- A rule applies only one punishment, the strongest one you picked:
ban, thenkick, thenwarn, thenlog.blockcan be added to any of them. - On in-game events, a rule with only
blockcancels the event silently, without a log. Addlogto see it. - Bans from rules are always permanent. The ban reason is your Reason.
warnshowsAnticheat warning: Security rule. Keep doing it and you will be removed from the server.- With the default Shared detections list, bans from rules are not shared with the CXA network.
Built-In Example Rules
Both rules ship with Enabled = false:
Config.Rules = {
block_adder = {
Enabled = false,
Event = 'entityCreating',
Condition = "model == 'adder'", -- Any adder, also from traffic
Actions = { 'block', 'log' },
Reason = 'Spawned an adder',
},
new_discord_accounts = {
Enabled = false,
Event = 'playerConnecting',
Condition = 'discordAge < 30', -- Discord account younger than 30 days
Actions = { 'block', 'log' },
Reason = 'Discord account younger than 30 days',
},
}block_adder matches every adder, including ones from traffic. Add and script == true before you use it, as in the first example below.
Examples
Block a Vehicle Model
Stop players from spawning a fighter jet with a script, while traffic stays untouched.
- When: Entity spawned
- Condition:
model == 'lazer' and script == true - Then: Block, Log
block_lazer = {
Enabled = true,
Event = 'entityCreating',
Condition = "model == 'lazer' and script == true", -- Only script spawns, not traffic
Actions = { 'block', 'log' },
Reason = 'Spawned a fighter jet',
},Reject New Discord Accounts
Turn away Discord accounts younger than 7 days. The second rule also refuses players who have no Discord at all.
young_discord = {
Enabled = true,
Event = 'playerConnecting',
Condition = 'discordAge < 7', -- Players without Discord pass this one
Actions = { 'block', 'log' },
Reason = 'Discord account younger than 7 days',
},
discord_required = {
Enabled = true,
Event = 'playerConnecting',
Condition = 'hasDiscord == false or discordAge < 7', -- No Discord, or too new
Actions = { 'block', 'log' },
Reason = 'Discord missing or younger than 7 days',
},Refused players see You cannot join this server: Discord account younger than 7 days.
Log a Weapon
Write a log entry when someone hits a target with a heavy sniper from more than 300 meters, without blocking anything.
log_long_sniper = {
Enabled = true,
Event = 'weaponDamageEvent',
Condition = "weapon == 'WEAPON_HEAVYSNIPER' and distance > 300", -- Distance in meters
Actions = { 'log' },
Reason = 'Heavy sniper hit from over 300 m',
},Block Invite Links in Chat
Stop chat messages with Discord invites and warn the sender.
no_invites = {
Enabled = true,
Event = 'chatMessage',
Condition = "message contains 'discord.gg/'", -- Not case-sensitive
Actions = { 'block', 'warn' },
Reason = 'Posted a Discord invite',
},Panel Validation Messages
The panel checks every rule while you type and again when you save or import code. You cannot save a rule it cannot read.
| Message | What it means |
|---|---|
Write a condition. | The condition is empty. |
Cannot read "...". | One part of the condition could not be read: text without quotes, a missing value, a misspelled operator or a parenthesis. The quoted part shows where. |
"..." is not a field of this event. | The field does not exist for the chosen event, or its case is different. |
Unknown event. | The event is not one of the five supported events. |
Rule ...: pick at least one action. | The rule has no action selected. |
Rule name "..." may only use a-z, 0-9 and _. | Imported code uses a rule name with other characters. |
Maximum 50 rules. | Your server has reached the rule limit. |
For rules written in config.lua, the console shows a yellow warning instead and skips the rule:
[CXA] Security rule block_lazer has an invalid condition near: model == lazerLimits and Performance
| Limit | Value |
|---|---|
| Rules per server | 50 |
| Rule name | a-z, 0-9 and _, up to 32 characters |
| Condition | Up to 300 characters |
| Reason | Up to 120 characters |
- Conditions are translated once when the anticheat starts, not on every event.
- CXA only listens to events that at least one enabled rule uses.
- Entity spawned and Weapon damage fire very often on a full server, and every enabled rule on them is checked each time. Keep these rules few and their conditions short.
- All rules share one detection name,
SecurityRule. After alogorwarnfor a player, furtherlogorwarnmatches for the same player are skipped for the Detection cooldown (Config.Logs.DetectionCooldown, default 10 seconds). Blocking still happens every time.
Recommendations
Recommended:
- Start a new rule with Log only. Check the logs for a few days, then add Block, Kick or Ban.
- Add
script == trueto Entity spawned rules, so traffic is never matched. - Write a clear Reason. Players see it on kick screens and in ban records.
- Use
hasDiscord == false or ...when a Discord rule should also cover players without Discord.
Avoid:
- Ban on a rule you have not tested. Rule bans are permanent.
- Rules that repeat a built-in detection, such as blacklisted vehicles or chat words. Use the detection and its own settings instead.
- Many rules on Weapon damage. That event fires on every hit.
Related Features
Join Screening
playerConnectingrules run while players connect, next to the built-in join checks.- See Join Screening.
Entity Control
- The entity blacklists already block listed vehicles, peds and objects. Rules add conditions the lists cannot express.
- See Entity Control.
Explosion Control
- Explosion types and their numbers are listed there.
- See Explosion Control.
Detections & Punishments
- Rule punishments work like detection punishments, under the detection name Security rule.
- See Detections & Punishments.
Bypass & Pause Exports
PauseDetection(src, 'SecurityRule', seconds)pauses rule punishments for one player. Blocking still happens.- See Bypass & Pause Exports.
Config Editor
- Import code is the fastest way to add several rules at once.
- See Config Editor.
Limitations
- Conditions support no parentheses, and quoted text cannot contain the words and or or between spaces.
- Only the fields in the table above are available.
- Bans from rules are permanent; there is no duration setting.
- On
playerConnecting,warnhas no effect, and logs go to Discord only. They do not appear in the panel's Detections tab. - Chat message rules only see messages sent through the
chatMessageevent of the standardchatresource. - Rules never take screenshots.
Common Problems
The Rule Shows "Error" in the Panel
What you see: The rule has a red Error badge and you cannot save.
How to fix it:
- Read the red line under Condition. It names the part that is wrong.
- Put text in quotes, check the field names in the hint line and remove parentheses.
The Console Says "Security rule ... has an invalid condition near"
What you see: On start, the console prints [CXA] Security rule <name> has an invalid condition near: <text>.
How to fix it:
- The condition comes from
config.luaand was skipped. Fix the part shown afternear:. - Paste the rule into Import code in the panel; the validation messages show exactly what is wrong.
My Rule Never Matches
What you see: The rule is on, but nothing is ever blocked or logged.
How to fix it:
- Check that the rule is switched on and saved, and wait a minute for the server to reload.
- Test with a staff member who does not bypass the anticheat. Bypassed players are never matched.
- Add Log to the actions. A rule with only Block cancels silently.
- For
<and>checks, make sure the field is a number for that player.discordAgeis empty for players without Discord.
Players Without Discord Still Get In
What you see: A discordAge < 30 rule refuses young accounts, but players with no Discord join freely.
How to fix it:
- Write
hasDiscord == false or discordAge < 30.
Traffic Vehicles Are Blocked Too
What you see: A model rule also blocks that car when it appears in traffic, and logs the player whose game spawned it.
How to fix it:
- Add
and script == trueto the condition.
Only the First Match Is Logged
What you see: A player triggers a rule several times in a row, but only one log appears.
How to fix it:
- This is the Detection cooldown. Logs and warnings of the same player are skipped for
Config.Logs.DetectionCooldownseconds. Lower it in Configuration → Logs → Logging if you need every entry.
Common Condition Mistakes
-- ❌ Text without quotes cannot be read
Condition = "model == adder"
-- ✅ Put names and text in quotes
Condition = "model == 'adder'"
-- ❌ Field names are case-sensitive
Condition = "discordage < 30"
-- ✅ Write the field exactly as listed
Condition = "discordAge < 30"
-- ❌ "contains" does not search inside model names
Condition = "model contains 'police'"
-- ✅ Compare each model with ==
Condition = "model == 'police' or model == 'police2'"
-- ❌ Parentheses are not supported
Condition = "(type == 2 or type == 3) and script == true"
-- ✅ Repeat the shared part in each group
Condition = "type == 2 and script == true or type == 3 and script == true"
-- ❌ " and " inside quoted text splits the condition
Condition = "message contains 'cash and items'"
-- ✅ Check each word on its own
Condition = "message contains 'cash' and message contains 'items'"
-- ❌ "contains" must be lowercase
Condition = "message CONTAINS 'cheat'"
-- ✅ Write operators in lowercase
Condition = "message contains 'cheat'"© 2026 CodeXart Studios · CXA Anticheat