> For the complete documentation index, see [llms.txt](https://viper-development-1.gitbook.io/viperdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://viper-development-1.gitbook.io/viperdocs/viper-scripts/safe-zone/developer-api/server-exports.md).

# Server Exports

Server-side exports for viper-safezones.

All server exports are called on viper-safezones.

```lua
exports["viper-safezones"]:ExportName(...)
```

## Quick reference

| Export                                    | Description                                |
| ----------------------------------------- | ------------------------------------------ |
| [GetAllZones](#getallzones)               | Get every zone loaded on the server        |
| [GetZone](#getzone)                       | Get a single zone by its ID                |
| [IsPointInSafeZone](#ispointinsafezone)   | Check if coordinates fall inside a zone    |
| [GetPlayerZoneId](#getplayerzoneid)       | The ID of the zone a player is standing in |
| [IsPlayerInSafeZone](#isplayerinsafezone) | Whether a player is inside any safe zone   |

***

## Zone data

{% hint style="success" %}

#### GetAllZones

Get every zone loaded on the server.

```lua
---@return Zone[]
local zones = exports["viper-safezones"]:GetAllZones()
```

{% endhint %}

{% hint style="success" %}

#### GetZone

Get a single zone by its ID.

```lua
---@param id number
---@return Zone? # nil if the zone does not exist
local zone = exports["viper-safezones"]:GetZone(id)
```

{% endhint %}

## Checks

{% hint style="success" %}

#### IsPointInSafeZone

Check if coordinates fall inside a zone. Pass an ID to test one specific zone, or leave it out to test every zone. Providing z also checks the zone's height range.

```lua
---@param x number
---@param y number
---@param z? number # Omit for a flat 2D check
---@param id? number # Test only this zone, omit to test all zones
---@return boolean
local inside = exports["viper-safezones"]:IsPointInSafeZone(x, y, z, id)
```

A vector3 can be passed instead, in which case the second argument becomes the optional zone ID.

```lua
---@param coords vector3
---@param id? number
---@return boolean
local inside = exports["viper-safezones"]:IsPointInSafeZone(coords, id)
```

{% endhint %}

{% hint style="success" %}

#### GetPlayerZoneId

Get the ID of the zone a player is standing in, checked from their server-side coordinates. Returns the first match when zones overlap.

```lua
---@param playerId number
---@return number? # nil if the player is not in a zone
local zoneId = exports["viper-safezones"]:GetPlayerZoneId(playerId)
```

{% endhint %}

{% hint style="success" %}

#### IsPlayerInSafeZone

Check if a player is inside any safe zone, from their server-side coordinates.

```lua
---@param playerId number
---@return boolean
local inZone = exports["viper-safezones"]:IsPlayerInSafeZone(playerId)
```

{% endhint %}

## Types

{% hint style="info" %}

#### Zone

```lua
---@class Zone
---@field id number # Database ID of the zone
---@field name string # Zone name shown in the banner
---@field note string # Optional note shown under the name
---@field points { x: number, y: number }[] # Polygon points
---@field minZ number # Bottom of the zone
---@field maxZ number # Top of the zone
---@field settings ZoneSettings
---@field jobs string[] # Whitelisted jobs, these players ignore the restrictions
```

{% endhint %}

{% hint style="info" %}

#### ZoneSettings

```lua
---@class ZoneSettings
---@field disableWeapons boolean
---@field noFists boolean
---@field invincible boolean
---@field speedKmh number # 0 means no vehicle speed limit
```

{% endhint %}

***

### Examples

#### Block an action inside a safe zone

```lua
RegisterNetEvent("myrobbery:start", function()
    local src = source

    if exports["viper-safezones"]:IsPlayerInSafeZone(src) then
        return TriggerClientEvent("myrobbery:notify", src, "You cannot do this in a safe zone.")
    end
end)
```

#### Disable a target system while in a zone

```lua
AddEventHandler("viper-safezones:onEnter", function()
    exports["mytarget"]:disable()
end)

AddEventHandler("viper-safezones:onExit", function(_, _, stillInAnotherZone)
    if not stillInAnotherZone then
        exports["mytarget"]:enable()
    end
end)
```

#### Check a location before spawning something

```lua
local spawn = vector3(215.4, -810.2, 30.7)

if not exports["viper-safezones"]:IsPointInSafeZone(spawn) then
    -- safe to spawn here
end
```

#### React to a speed limit

```lua
AddEventHandler("viper-safezones:onEnter", function(_, zoneName, restrictions)
    if restrictions.speedKmh > 0 then
        print(("%s limits you to %d km/h"):format(zoneName, restrictions.speedKmh))
    end
end)
```
