np_colshape
The GTAV Enhanced colshape natives on FiveM Legacy. Same names, same arguments, same returns, same enter and exit events. Write against the natives once and the code runs on both. On Enhanced the resource switches itself off.
- Version
- 1.1.0
- Status
- Specs pass against stubbed natives, not yet run on a live server
- Runtimes
- FiveM Legacy: the engine. GTAV Enhanced: idle, the natives are built in
- Frameworks
- None needed
- Dependencies
- None. OneSync for server shapes
- Admin
- np_admin optional, no ACE
- Limits
- 4096 shapes per side and 256 polygon points by default
- UI
- None, no NUI to build
A ped crossing a shape
- Enters:
onColshapeEnter(entity, shapeId)on the next pass, within 100 ms on the client and 200 ms on the server. - Inside: its position is in the shape, boundary included. Only entities inside a shape are tracked at all.
- Leaves:
onColshapeExit, also when it streams out, drops or changes bucket. Exits fire before enters.
local stash = CreateColshapeSphere(441.0, -982.0, 30.7, 5.0)
SetColshapeEntityType(stash, 6, false) -- no NPCs
AddEventHandler('onColshapeEnter', function(entity, shapeId)
if shapeId == stash then
-- entity is inside
end
end)np_colshape has no UI. The diagram shows three of the six shape types and one ped crossing a polygon, not to scale.
What's in it
The colshape API of GTAV Enhanced, rebuilt for FiveM Legacy, and a small helper on top that works the same on both. One engine instead of the distance loops every resource ran on its own.
The same API on both
- Every colshape native with the Enhanced names, arguments and return values.
- A resource written against the natives runs unchanged on Legacy and on Enhanced.
Idle on Enhanced
- The shim checks the feature, not the version: does
DoesColshapeExistwork? - With the real natives it defines nothing, and the resource logs once and stays idle.
Six shapes
- Circle, sphere, cylinder, cuboid, rotated rectangle and polygon with Z limits.
- Concave and self-intersecting polygons (even-odd), up to 256 points.
Enter and exit events
onColshapeEnterandonColshapeExitas local events on the side that owns the shape.- Entities already inside a new shape get their enter. A handler that errors never stops the loop.
Filters and dimensions
- 15 entity types per shape, from cars and boats to peds and players.
- Server shapes live in a routing bucket; other buckets never count.
Cheap to run
- A 64 m grid: each entity is tested only against the shapes of its own cell.
- One position read per entity; type and bucket only near a shape. Player-only shapes read the players, not the ped pool.
- Pools nobody asks for are never read. With no shapes, the loops wake once a second.
The npColshape helper
- One definition table: degrees, named entity groups, PolyZone-style boxes.
- Enter and exit handlers per shape with player ids, and who is inside.
Restarts and ownership
- Shapes belong to the resource that created them and go when it stops.
npColshape.onReadybuilds them again after a restart of np_colshape.
Debug overlay
/colshapesdraws client shapes in green and server shapes in blue, with the nearest listed.- Gated through np_admin, live settings, no ACE.
A closer look
Legacy and Enhanced
Two parts: the np_colshape resource is the engine, and a small shim that each resource vendors as bridge/np_colshape.lua defines the natives where they are missing.
| GTAV Enhanced | FiveM Legacy | |
|---|---|---|
| Colshape natives | The real ones; the shim defines nothing | Defined by the shim, forwarded to np_colshape |
| Enter and exit events | Fired by the runtime | Fired by np_colshape on the same side |
| np_colshape resource | Idle, its exports forward to the natives | The engine |
| npColshape helper | On top of the natives | On top of the shim, same behaviour |
- Moving to Enhanced: no code changes. Keep the shim;
ensure np_colshapecan stay. - Never a dependency: without np_colshape on Legacy, every
Create*returns-1with one warning, and your fallback runs. - Never throws: a failing native or export is logged once and returns what an invalid id returns.
- Client and server have their own shapes, ids and events. Nothing syncs, as with the natives.
The npColshape helper
A small layer over the natives that the np_* resources use. It checks every field itself, so a bad definition never reaches a native.
-- server: who is in the yard
npColshape.onReady(function()
local yard = npColshape.create({
type = 'box', coords = vector3(441.0, -982.0, 30.7),
size = vector3(8.0, 6.0, 4.0), rotation = 90.0, -- degrees
entityTypes = 'players',
})
npColshape.on(yard, {
players = true,
enter = function(ped, id, src) inYard[src] = true end,
exit = function(ped, id, src) inYard[src] = nil end,
})
end)| Member | What it does |
|---|---|
| create(def) | All six shapes plus box, degrees, groups like 'players' or 'vehicles'. Returns -1, reason on a bad field |
| on, off | Enter and exit per shape; players adds the source, localPlayer keeps only you. Exit still arrives after a drop |
| isEntityIn, entitiesIn | Who is inside, kept from the events |
| available, onReady | Pick colshapes or your fallback; build shapes again after a restart |
| describe, delete, debug | Read a shape back, delete it with its handlers, draw outlines |
The engine on Legacy
Where the Enhanced docs are silent, np_colshape makes a choice and documents it. On Enhanced the runtime decides.
| Side | Peds and vehicles | Objects and pickups |
|---|---|---|
| Client | Every 100 ms, streamed entities | Every 500 ms |
| Server | Every 200 ms, every OneSync entity | Every 500 ms (objects) |
| Idle | Once a second, doing nothing | |
- Inside is the entity's position, not its bounding box. The boundary counts.
- Cylinder and cuboid
zis the centre. Rectangle headings are radians, like GTA's. - Deleting a shape, or its owner stopping, fires no events.
- A fast car can cross a thin shape between two passes. Use a deeper shape or a shorter interval.
- 1.1 reads each entity's position first and types it only near a shape. In the bundled benchmark a server pass with 500 player-only shapes went from 3428 to 275 natives.
- Adaptive rechecks (opt-in, off by default): far-off non-player entities are checked less often, so something faster than 60 m/s can enter up to 2 s late.
Not verified in-game
Version 1.1.0 has never run on a live server. The specs pass against stubbed natives, on a Legacy and a fake Enhanced runtime; nothing has been checked in game.
- Server entity typing, especially that player peds report
Player. - Client pickups from the game pool, and the vehicle type native.
- Several return values and vector lists across exports.
- That Enhanced fires the events locally with
(entity, shapeId), and that the feature probe returns a boolean there. - The cost of the server loop with many OneSync entities and shapes.
- That server entity natives throw (or read zero) for a deleted entity, and that the player lists give the same player peds as the ped pool.
Set it up
Installation
No database, no NUI build, no framework.
- Put the folder in your resources as
np_colshape. - Start it before the resources that use colshapes. On Enhanced you can leave it in:
ensure np_colshape - In each resource, copy
lib/colshape.luabyte-identical tobridge/np_colshape.luaand load it as the first shared script. Nodependenciesentry. - Optional: np_admin for the
np_colshape.debugnode and live settings. - Intervals, slice sizes, grid and limits are in
shared/config.lua, all of them also in np_admin. - Check the specs if you change it:
luac -pon every file, thenlua tests/*_spec.lua.
Used by the np_* resources
Sixteen np_* resources use colshapes while np_colshape (or Enhanced) is there, and their own distance checks when it isn't. None of them requires it.
| Resource | What moves onto colshapes |
|---|---|
| np_banking | Enter and exit of its interaction points |
| np_cctv | Enter and exit of its interaction points |
| np_cellnet | Dead and weak zones as polygons, jammers and Wi-Fi hotspots as spheres, on the server |
| np_clothing | Enter and exit of its interaction points |
| np_darts | Pub and board presence on the server, in the board's routing bucket |
| np_drugs | Enter and exit of its world points |
| np_environmental | Its interaction points and the hazard zones of scenes |
| np_farming | World points, and the truffle forest zones on the server |
| Resource | What moves onto colshapes |
|---|---|
| np_fishing | Enter and exit of its interaction points |
| np_fuel | Enter and exit of its interaction points and of its stations |
| np_gangs | Turf polygons on the client and the server, and its interaction points |
| np_mechanic | The workshop zones and its interaction points |
| np_prison | World points, the area around each facility and the zones of alternative sentences |
| np_shops | Enter and exit of its world points |
| np_surveillance | Enter and exit of its interaction points |
| np_vending | Enter and exit of the machine points |
Natives
The Enhanced colshape natives, shared on client and server unless marked. On Legacy each is also an np_colshape export of the same name.
local lot = CreateColshapeRectangle(215.0, -810.0, 30.7, 40.0, 25.0, math.rad(70.0))
local yard = CreateColshapePolygon(20.0, 60.0, {
100.0, 200.0, 140.0, 200.0, 140.0, 260.0, 100.0, 240.0,
})
SetColshapeDimension(yard, 3) -- server only: routing bucket
local ok, x, y, z, radius = GetColshapeSphereData(stash)
print(IsPointInsideColshape(lot, 215.0, -810.0, 30.7))
AddEventHandler('onColshapeExit', function(entity, shapeId) end)
DeleteColshape(lot) -- no exit event| Group | Natives |
|---|---|
| Create | CreateColshapeCircle, Sphere, Cylinder, Cuboid, Rectangle, Polygon: an id or -1 |
| Read | DoesColshapeExist, IsColshape*, GetColshape*Data, IsPointInsideColshape |
| Filter | SetColshapeEntityType, IsColshapeEntityTypeSet; server only SetColshapeDimension, GetColshapeDimension |
| Events | onColshapeEnter, onColshapeExit with (entity, shapeId) |
| np_colshape | getStats(), np_colshape:ready |
Questions
Has it run on a live server?
Not yet. Version 1.1.0 is covered by plain-Lua specs that load the real scripts against stubbed natives, on a Legacy and a fake Enhanced runtime. Nothing has been checked in game: not the natives, not the events, not the performance with real player counts. Expect fixes in the first versions.
Do I need it on GTAV Enhanced?
No. Enhanced has the natives built in, and the shim in each resource uses them directly. You can leave np_colshape in server.cfg: it logs once and stays idle.
What happens without it on Legacy?
Every Create* returns -1 with one warning, and npColshape.available() is false. The np_* resources fall back to their own distance checks, so nothing breaks.
Is this something players see?
No. It has no UI. Players notice it only as prompts and zones that react the same way in every resource, and as fewer loops running on their client.
Can I move PolyZone or ox_lib zones over?
Yes. The helper's box type follows the PolyZone and ox_lib box: heading in degrees, Z limits from the height. Polygons and spheres map one to one.
Does it use ACE permissions?
No. /colshapes is gated by the np_admin node np_colshape.debug. Without np_admin, the console, identifiers in np_admin_fallback and ESX groups in np_admin_fallback_groups.
Works well with

Write against the natives once. Run on Legacy and Enhanced.
The natives, the helper, adopting it in a resource and every config option are in the docs.