Zone checks
Radius-based zone exclusion helpers. No framework required. Uses squared-distance comparison — no sqrt per call.
Zone format
Each zone is a table with the following fields:
| Field | Type | Description |
|---|---|---|
| x | number | World X coordinate. |
| y | number | World Y coordinate. |
| z | number | World Z coordinate. |
| radius | number | Exclusion radius in metres. |
| name | string | nil | Optional zone name returned by the check functions. |
IsInsideZone(pos, zones) → boolean, string|nilclient
Returns inside, zoneName. zoneName is nil if not inside any zone.
| Param | Type | Description |
|---|---|---|
| pos | vector3 | table | Position to test — vector3 or {x, y, z}. |
| zones | table | Array of zone tables. |
IsPlayerInsideZone(zones) → boolean, string|nilclient
Convenience wrapper — uses GetEntityCoords(PlayerPedId()) as the position.
| Param | Type | Description |
|---|---|---|
| zones | table | Array of zone tables. |
example
local NO_SPAWN_ZONES = {
{ x = -802.0, y = -1305.0, z = 43.0, radius = 150.0, name = 'Blackwater' },
{ x = 2559.0, y = 438.0, z = 57.0, radius = 200.0, name = 'Annesburg' },
}
-- in a spawn loop thread:
local inside, zoneName = wc:IsPlayerInsideZone(NO_SPAWN_ZONES)
if inside then
print('Player is inside ' .. tostring(zoneName) .. ' — skipping spawn')
end
Real Wild County example — stagecoach mission exclusion zones
wc_stagecoach skips generating delivery missions that start or end inside major towns, keeping the "roadside" feel of the job.
wc_stagecoach/client/main.lua
local inside = wc:IsInsideZone(candidatePos, Config.TownZones)
if inside then return end -- pick a different delivery point
Common mistakes
- Calling
WCLib.IsPlayerInsideZone(...)from another resource — usewc:IsPlayerInsideZone(...)instead. - Rebuilding the zones table every tick inside a hot loop — define it once (module scope or config) and reuse it.
- Forgetting
radiusis required per zone — a zone entry without it errors when squared againstnil.
Troubleshooting
- If a zone never triggers: double check
x/y/zare world coordinates, not a waypoint/map-relative value. - If the wrong zone name comes back when zones overlap: the first matching zone in list order wins — order your list from most to least specific if you have overlapping radii.