DirkScripts
Zones
âšī¸ Client & Server Module - Full zone system on client, utility functions available on server
#lib.zones.register
Create a new zone
lualib.zones.register(id, data)
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | String | true | Unique zone reference |
| data | Object | true | Zone options, refer to Data Structure |
#Zone Examples
{% tabs %} {% tab title="cirlce" %}
lualib.zone.register("exampleZone", { type = "circle", pos = vector3(0, 0, 0), radius = 5.0, onEnter = function(data) lib.print("debug", "Entered Zone") end, onExit = function(data) lib.print("debug", "Exited Zone") end, })
{% endtab %}
{% tab title="circle2D" %}
lualib.zone.register("exampleZone", { type = "circle2D", pos = vector2(0, 0), radius = 5.0, onEnter = function(data) lib.print("debug", "Entered Zone") end, onExit = function(data) lib.print("debug", "Exited Zone") end, })
{% endtab %}
{% tab title="poly" %}
lualocal polyPoints = { vector2(0, 0), vector2(10, 10), vector2(20, 20), vector2(0, 30), vector2(-10, 15), } lib.zone.register("exampleZone", { type = "poly", pos = polyPoints, onEnter = function(data) lib.print("debug", "Entered Zone") end, onExit = function(data) lib.print("debug", "Exited Zone") end, })
{% endtab %}
{% tab title="box" %}
lualib.zone.register("exampleZone", { type = "box", pos = vector4(0, 0, 0, 0), size = vector3(0, 0, 0), onEnter = function(data) lib.print("debug", "Entered Zone") end, onExit = function(data) lib.print("debug", "Exited Zone") end, })
{% endtab %}
{% tab title="game_zone" %}
lualib.zone.register("exampleZone", { type = "game_zone", gameZone = "ALTA" onEnter = function(data) lib.print("debug", "Entered Zone") end, onExit = function(data) lib.print("debug", "Exited Zone") end, })
{% endtab %} {% endtabs %}
#lib.zones.get
Get zone information
lualocal zone = lib.zones.get(name)
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | String | true | Unique zone reference |
#lib.zones.delete
Remove a created zone
lualib.zones.delete(name)
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | yes | Unique zone reference |
#lib.zones.destroy
Alias for lib.zones.delete
lualib.zones.destroy(name)
#lib.zones.getCenter
Get the center point of a polygon
lualocal center = lib.zones.getCenter(points)
| Parameter | Type | Required | Description |
|---|---|---|---|
| points | vector3[] | yes | Polygon points |
âšī¸ getCenter and isPointInside are also available server-side.
#lib.zones.isPointInside
Check if a position is inside a polygon
lualocal inside = lib.zones.isPointInside(points, pos, height)
| Parameter | Type | Required | Description |
|---|---|---|---|
| points | vector3[] | yes | Polygon boundary points |
| pos | vector3 | yes | Position to test |
| height | number | no | Height of the polygon |
#lib.zones.isInsideZone
Check whether a position lies inside a zone(s)
lualocal isInside, zoneName = lib.zones.isInsideZone(name, pos)
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | String, Object | true | Unique zone reference(s) |
| pos | Vector3 | true | Position to be checked |
#Data Structure
This is the data structure of a blip and the valid options
lua{ -- Required type = "circle", -- Type of zone: circle, circle2D, poly, box, game_zone -- Not Required onEnter = function(data) -- Callback for entering the zone end, onExit = function(data) -- Callback for exiting the zone end, }
Some zones have different requirements, see below:
{% tabs %} {% tab title="circle" %}
{
pos = vector3(0, 0, 0), -- Position of the zone
radius = 5.0, -- Size of the zone radially from the point
}
{% endtab %}
{% tab title="circle2D" %}
lua{ pos = vector2(0, 0), -- Position of the zone radius = 5.0, -- Size of the zone radially from the point }
{% endtab %}
{% tab title="poly" %}
{
points = { -- Boundy marks for the polyzone
vector2(0, 0),
vector2(2, 1),
vector2(3, 3),
}
}
{% endtab %}
{% tab title="box" %}
lua{ pos = vector4(0,0,0,0), -- Position of the zone, x, y, z, heading size = vector3(0,0,0) -- Size of the zone from the center point }
{% endtab %}
{% tab title="game_zone" %}
lua{ gameZone = "ALTA" }
Game Zones: https://docs.fivem.net/natives/?_0xCD90657D4C30E1CA â {% endtab %} {% endtabs %}
