Skip to content

Natives & events ​

These are the GTAV Enhanced colshape natives. On Enhanced the runtime provides them. On Legacy the shim defines them as globals and forwards each call to the export of the same name on np_colshape. Write against them the same way on both.

All natives are shared (client and server) unless marked server only. Client and server have separate shapes and ids: a shape created on the server is not visible to client natives, and the other way round.

Creating shapes ​

Native Arguments Returns
CreateColshapeCircle x, y, radius id or -1. A 2D circle with unlimited Z
CreateColshapeSphere x, y, z, radius id or -1
CreateColshapeCylinder x, y, z, radius, height id or -1. z is the centre, height the total height
CreateColshapeCuboid x, y, z, width, depth, height id or -1. Axis aligned and centred. width, depth, height are the total extents along X, Y, Z
CreateColshapeRectangle x, y, z, width, depth, heading id or -1. A centred 2D rectangle with unlimited Z. heading is in radians
CreateColshapePolygon minZ, maxZ, points id or -1. points is a flat list { x1, y1, x2, y2, ... } with at least 3 pairs. Legacy also takes a list of vector2 / vector3 / { x =, y = }

Invalid input returns -1 and creates nothing:

  • a non-number or NaN argument;
  • a radius, height, width or depth of 0 or less;
  • fewer than 3 polygon points, or more than maxPolygonPoints (256);
  • minZ > maxZ;
  • (Legacy) the side already holds maxShapes (4096) shapes.
lua
local zone = CreateColshapeCylinder(441.0, -982.0, 30.7, 3.0, 4.0)  -- 28.7 to 32.7
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,
})

Reading and deleting ​

Native Arguments Returns
DeleteColshape id Nothing. Fires no exit
DoesColshapeExist id boolean
IsColshapeCircle / IsColshapeSphere / IsColshapeCylinder / IsColshapeCuboid / IsColshapeRectangle / IsColshapePolygon id boolean
GetColshapeCircleData id ok, x, y, radius
GetColshapeSphereData id ok, x, y, z, radius
GetColshapeCylinderData id ok, x, y, z, radius, height
GetColshapeCuboidData id ok, x, y, z, width, depth, height
GetColshapeRectangleData id ok, x, y, z, width, depth, heading
GetColshapePolygonData id points, minZ, maxZ. points is a flat list, {} if the id is not a polygon
IsPointInsideColshape id, x, y, z boolean. Geometry only: entity types and dimension are ignored

An invalid id, or a Get*Data call for the wrong shape type, gives:

Call Result
Get*Data false plus zeros
GetColshapePolygonData {}, 0.0, 0.0
Is*, DoesColshapeExist, IsPointInsideColshape, IsColshapeEntityTypeSet false
DeleteColshape, Set* nothing
lua
local ok, x, y, z, radius = GetColshapeSphereData(id)
if ok then
  print(('sphere at %.1f %.1f %.1f, r %.1f'):format(x, y, z, radius))
end

Filters ​

Native Arguments Returns
SetColshapeEntityType id, entityType, enabled Nothing. Turns one entity type on or off for the shape
IsColshapeEntityTypeSet id, entityType boolean
SetColshapeDimension id, dimension Nothing. Server only. Dimension = routing bucket, default 0
GetColshapeDimension id integer. Server only

Every entity type is enabled on a new shape. Turning a type off fires onColshapeExit for the entities of that type that are inside. On the server, an entity in another routing bucket than the shape's dimension is never inside, and moving a shape (or an entity) to another bucket fires the exit.

lua
-- players only, in bucket 3
local id = CreateColshapeSphere(x, y, z, 5.0)
for entityType = 0, 14 do
  SetColshapeEntityType(id, entityType, entityType == 11)
end
SetColshapeDimension(id, 3) -- server only

Events ​

lua
AddEventHandler('onColshapeEnter', function(entity, shapeId) end)
AddEventHandler('onColshapeExit', function(entity, shapeId) end)
Argument
entity An entity handle: a OneSync handle on the server, a script handle on the client. Players arrive as their ped
shapeId The id returned by Create* on the same side
  • Every resource on that side receives every shape's events. Check shapeId, or use npColshape.on, which does it for you.
  • They are local events. On Legacy np_colshape fires them with TriggerEvent and never registers them as net events. Don't register them as net events in your resource either, or clients could fake them.
  • Within one pass every exit fires before every enter.
  • Entities that are already inside a new shape get onColshapeEnter on the first pass after it was created.

Entity types ​

EntityType
Automobile = 0 Bike = 1 Boat = 2 Door = 3
Heli = 4 Object = 5 Ped = 6 Pickup = 7
PickupPlacement = 8 Plane = 9 Submarine = 10 Player = 11
Trailer = 12 Train = 13 GlassPane = 14

A player's ped is Player, never Ped. How Legacy decides the type of an entity is on Behaviour → Typing. The helper has the same table as npColshape.EntityType.

Shape types ​

ShapeType Value
Circle 1
Cuboid 2
Cylinder 3
Polygon 4
Rectangle 5
Sphere 6

The helper has the same table as npColshape.ShapeType.

np_colshape exports ​

On Legacy every native above is also an export of np_colshape with the same name and arguments. On Enhanced those exports forward to the natives. Call the natives, not the exports: the shim already routes them.

Two exports exist only on np_colshape:

Export Side Returns
getStats() both { native, side, shapes, inside, cells, wide, scoped, fast = { ms, entities }, slow = { ms, entities }, checked, tested, enters, exits, errors, deferred }. On Enhanced: { native = true, side }
setShapeScope(id, scope) client Internal, used by the shim for the localPlayer scope. 'localPlayer': only PlayerPedId() is tested against the shape. Anything else: every entity. Returns true if the shape exists. Since 1.1.0
Field
shapes Shapes on this side
inside Entities inside at least one shape
cells, wide Grid cells in use, and shapes on the list every entity is tested against
scoped Shapes with the localPlayer scope. Always 0 on the server. Since 1.1.0
fast, slow Time of the last pass of each loop in ms, and the entities it looked at
checked, tested, enters, exits, errors Running counters: entities checked, exact shape tests, enters and exits fired, errors caught in event handlers and natives
deferred Running counter: entities skipped by adaptive rechecks. Stays 0 while adaptive is off. Since 1.1.0

np_colshape events ​

Event Side
np_colshape:ready both, local Fired after every start of np_colshape on Legacy. npColshape.onReady listens to it
np_colshape:debug server → client Internal: toggles the /colshapes overlay