Sites Zone
Class representing a 2D polygon zone with optional top/bottom bounding planes. Used for defining areas (parking zones, restricted areas, etc.) within the sites system.
Class representing a 2D polygon zone with optional top/bottom bounding planes. Used for defining areas (parking zones, restricted areas, etc.) within the sites system.
Constructor
local Zone = require('gameplay/sites/zone')
local zone = Zone(sites, name, forceId)Methods
| Method | Signature | Returns | Description |
|---|---|---|---|
addVertex | (pos, index) | nil | Add vertex to polygon |
removeVertex | (index) | nil | Remove vertex by index |
processVertices | () | nil | Recompute AABB, center, linked list |
containsPoint2D | (point) | bool | Point-in-polygon test with plane check |
containsVehicle | (veh, basic) | bool | Check if vehicle is inside zone |
autoPlanes | (ignoreTop, ignoreBot) | nil | Auto-generate bounding planes |
changedPlanes | () | nil | Reprocess after plane change |
validPlanes | () | bool | Check plane normals are correct |
pointBetweenPlanes | (point) | bool | Check point is between top/bot planes |
rayIntersectsZone | (rayPos, rayDir) | number | Ray-zone intersection distance |
zoneArea | () | number | Compute polygon area (shoelace formula) |
makeHighResolutionFence | (maxStep) | nil | Subdivide edges for terrain-following |
drawDebug | (drawMode, clr, height, down, nearCam, drawDist) | nil | Draw fence visualization |
drawMinimap | (td) | nil | Draw zone outline on minimap |
onSerialize / onDeserialized | - | - | JSON persistence |
Key Fields
| Field | Type | Description |
|---|---|---|
vertices | array | {pos, index, next, prev, radius} linked list |
center | vec3 | Computed centroid |
aabb | table | Axis-aligned bounding box |
top / bot | table | {pos, normal, active} bounding planes |
customFields | CustomFields | Tags and typed fields |
fenceDown / fenceHeight | number | Fence drawing extents |
How It Works
Point-in-Polygon (containsPoint2D)
- AABB quick-reject test
- Plane bounds check (if active)
- Ray-casting algorithm counting edge crossings
Bounding Planes
Optional top/bottom planes constrain the zone vertically. Plane normals must point up (top) and down (bot). autoPlanes() generates them ±5 units from vertex extremes.
Fence Drawing
Draws triangulated fence panels between vertices. Supports plane-aware height and distance-based alpha fade.
local zone = Zone(parentSites, "Parking Area")
zone:addVertex(vec3(0, 0, 0))
zone:addVertex(vec3(10, 0, 0))
zone:addVertex(vec3(10, 10, 0))
zone:addVertex(vec3(0, 10, 0))
zone:autoPlanes()
-- Check containment
if zone:containsPoint2D(playerPos) then
print("Player is in zone:", zone.name)
end
-- Area
print("Zone area:", zone:zoneArea(), "sq meters")Dependencies
gameplay/sites/customFields- custom field systemcore_camera- distance cullingcore_terrain- terrain height for high-res fencesui_apps_minimap_utils- minimap coordinate conversion
| Function | Signature | Returns | Description |
|---|---|---|---|
M.init | (sites, name, forceId) | nil | init |
M.vertexPlaneIntersection | (vertex, plane) | nil | vertexPlaneIntersection |
M.aabbCheck | (point) | nil | aabbCheck |
M.drawPlane | (plane, clrF) | nil | drawPlane |
M.drawFence | (from, to, clrI, down, up, usePlanes, nearCam, drawDistance, shapeAlpha) | nil | drawFence |
See Also
- Sites Custom Fields - Related reference
- Sites Location - Related reference
- Sites Parking Spot - Related reference
- Gameplay Systems Guide - Guide
Sites Manager
Extension that manages loading, caching, and lifecycle of `*.sites.json` files across all levels. Provides utility functions for finding sites files and best parking spots.
J-Turn Detection
Reference for `gameplay_statisticModules_watchJturn`, a statistic submodule that detects J-turn maneuvers (reversing at speed, then spinning 180° to drive forward).