Small selection of zone related functions to allow developers to create an manage zones throughout the server.
Client Functions
get_all_zones
Retrieve all active zones.
Function
Copy local function get_zones ()
return zones
end
exports ( 'get_zones' , get_zones)
utils.zones.get_zones = get_zones
Example
Copy --- Utils object
local all_zones = utils.zones. get_zones ()
print ( "Zones:" , json. encode (all_zones))
--- Direct export
local all_zones = exports.boii_utils: get_zones ()
add_circle_zone
Add a circular zone with custom options.
Function
Copy local function add_circle_zone ( options )
zones = zones or {}
zones[options.id] = options
TriggerServerEvent ( 'boii_utils:sv:add_zone' , options)
if options.debug then
draw_debug ( 'circle' , options)
end
end
exports ( 'add_circle_zone' , add_circle_zone)
utils.zones.add_circle = add_circle_zone
Example
Copy local circle_zone = {
id = "example_circle" ,
coords = vector3 ( 200.0 , - 800.0 , 30.0 ),
radius = 10.0 ,
debug = true ,
}
--- Utils object
utils.zones. add_circle (circle_zone)
print ( "Circle Zone Added:" , circle_zone.id)
--- Direct export
exports.boii_utils: add_circle_zone (circle_zone)
add_box_zone
Add a box zone with custom dimensions.
Function
Copy local function add_box_zone ( options )
zones = zones or {}
zones[options.id] = options
TriggerServerEvent ( 'boii_utils:sv:add_zone' , options)
if options.debug then
draw_debug ( 'box' , options)
end
end
exports ( 'add_box_zone' , add_box_zone)
utils.zones.add_box = add_box_zone
Example
Copy --- Define box options
local box_zone = {
id = "example_box" ,
coords = vector3 ( 300.0 , - 700.0 , 30.0 ),
width = 5.0 ,
depth = 10.0 ,
height = 3.0 ,
heading = 0.0 ,
debug = true ,
}
--- Utils object
utils.zones. add_box (box_zone)
print ( "Box Zone Added:" , box_zone.id)
--- Direct export
exports.boii_utils: add_box_zone (box_zone)
remove_zone
Remove a zone by its unique identifier.
Function
Copy local function remove_zone ( id )
zones[id] = nil
end
exports ( 'remove_zone' , remove_zone)
utils.zones.remove_zone = remove_zone
Example
Copy --- Specify zone id
local zone_id = "example_circle"
--- Utils object
utils.zones. remove_zone (zone_id)
print ( "Zone Removed:" , zone_id)
--- Direct export
exports.boii_utils: remove_zone (zone_id)
is_in_zone
Determine if a specific point is within any active zone.
Function
Copy local function is_in_zone ( point )
for id, zone in pairs (zones) do
if zone.type == 'circle' then
if # (point - zone.center) <= zone.radius then
return true
end
elseif zone.type == 'box' then
if utils.geometry. is_point_in_oriented_box (point, zone) then
return true
end
end
end
return false
end
exports ( 'is_in_zone' , is_in_zone)
utils.zones.is_in_zone = is_in_zone
Example
Copy --- Retrieve or specify some coords; here we use the player.
local player = GetEntityCoords ( PlayerPedId ())
--- Utils object
local is_inside = utils.zones. is_in_zone (player)
print ( "Player Inside Zone:" , is_inside)
--- Direct export
local is_inside = exports.boii_utils: is_in_zone (player)