> For the complete documentation index, see [llms.txt](https://mad-development.gitbook.io/mad-development/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mad-development.gitbook.io/mad-development/script-guides/safe-events.md).

# Safe Events

This script protects your server from cheaters who use LUA executers to abuse events that you have unprotected, it has been tested on servers with +300 players and I can guarantee that it works well, it uses fivem's native DropPlayer so if your log system is prepared for it you will receive the logs automatically.

## Client-Side

{% hint style="info" %}
You need to change the TriggerServerEvent of the events you want to secure, like the example below.
{% endhint %}

### Before:

```lua
TriggerServerEvent("testevent:server", "arg1", "arg2")
```

### After:

This must be called on the top of client file like the core object

<pre class="language-lua"><code class="lang-lua"><strong>local token = exports.mad_safeevents:getToken()
</strong></code></pre>

This is called to replace the TriggerServerEvent

```lua
exports.mad_safeevents:ExecuteServerEvent("testevent:server", token, "arg1", "arg2")
```

## Server-Side

{% hint style="info" %}
You need to edit your server event to get ready to handle the event safer
{% endhint %}

You need to place this on top of your server event, this export return true or false and drop the player if needed

```lua
if not exports.mad_safeevents:verifyToken(src, token, "testevent:server") then 
        return print("player: "..src.." just got dropped") 
end
```

Example:

You need to receive the token and args (args are optional)

```lua
RegisterServerEvent("testevent:server", function(token, args)
    local src = source
    local x, y = table.unpack(args)
    print(x, y)
    --this will print "arg1" and "arg2"
    if not exports.mad_safeevents:verifyToken(src, token, "testevent:server") then 
        return print("player: "..src.." just got dropped") 
    end
 
 
 
     --Do what ever you want to do
end)

```

## Config (server-side)

```lua
Config = {}

--Make sure that those events dont exist in your server, they are fake just to make cheater execute them and get dropped

Config.FakeServerEvents = {  
    "banking:server:addmoney",
    "hunting:server:addmoney",
    "police:server:addmoney",

}

--Message that the cheater will get when gets droped, remember that if your log system its prepered to handle DropPlayer function you will get the log of it

Config.DropPlayerMessage = "U have been dropped cheater :)"
Config.InvalidTokenMessage = "You dont remember your token lil bro?"


-- You must register here the events that you want to be safe

Config.SafeEvents = {
    ['namevent'] = {
        checkdimension = true,      --almost always true, only set to false if you are triggering a event that the player can be in a diferent dimension
        checkcoords = vec3(200.0, 100.0, 41.0),       --coords where the player should be or false
        maxdist = 100       --maximum distance that player can be from the coords above
    },

    ['test'] = {
        checkdimension = true,      --almost always true, only set to false if you are triggering a event that the player can be in a diferent dimension
        checkcoords = vec3(200.0, 100.0, 41.0),       --coords where the player should be or false
        maxdist = 100       --maximum distance that player can be from the coords above
    },

    ['testevent:server'] = {
        checkdimension = true,      --almost always true, only set to false if you are triggering a event that the player can be in a diferent dimension
        checkcoords = false,       --coords where the player should be or false
        maxdist = 10       --maximum distance that player can be from the coords above
    },
}

```

## Dependacies

* ox\_lib
* ESX or QBCORE or QBOX
