Sleepless

GridExports

Client Exports

Last updated on

Call these with exports.sleepless_grid. The shared helpers on this page also exist on the server.

Cell ids look like cell_12_-3.


RegisterCellHandler

Registers callbacks for cells this client starts or stops streaming.

exports.sleepless_grid:RegisterCellHandler(onLoad, onUnload)

Parameters

ParameterTypeDescription
onLoadfun(cellId: string, bucket: number)?Called when streaming starts for a cell
onUnloadfun(cellId: string, bucket: number)?Called when streaming stops for a cell

bucket is the routing bucket the cell was loaded in. Handlers are removed when the calling resource stops.


getActiveCells

Returns the cells this client is streaming.

local cells = exports.sleepless_grid:getActiveCells()

Returns

TypeDescription
table<string, true>Cell id keys for the current subscription

refreshCells

On the next tick, runs load callbacks again for cells the player is still streaming. Cells that are no longer nearby unload in the same pass.

exports.sleepless_grid:refreshCells()

getRoutingBucket

Returns the routing bucket this client is streaming, and the sleepless_routing name when one is set.

local bucket, bucketName = exports.sleepless_grid:getRoutingBucket()

Returns

TypeDescription
numberStreaming bucket
string | nilRegistered bucket name

getCurrentBufferSize

Returns the buffer radius currently applied on this client, after the speed shrink.

local buffer = exports.sleepless_grid:getCurrentBufferSize()

Returns

TypeDescription
number0 while shrunk, otherwise config.bufferSize

getCellIdFromCoords

local cellId = exports.sleepless_grid:getCellIdFromCoords(coords)
ParameterTypeDescription
coordsvector3World position

Returns the cell id string.


getCellCenter

local center = exports.sleepless_grid:getCellCenter(cellId)

cellId may be a cell id or a vector3. Returns the center of that cell at z = 0, or nil when the id cannot be parsed.


parseCellId

local x, y = exports.sleepless_grid:parseCellId(cellId)

Returns the integer cell coordinates, or nil when the string is not a cell id.


getNearbyCells

local cellIds = exports.sleepless_grid:getNearbyCells(cellX, cellY, buffer)
ParameterTypeDescription
cellXintegerCell X
cellYintegerCell Y
bufferinteger?Ring count. Defaults to config.bufferSize

getBufferSize

Returns the configured buffer, before speed shrinking.

local buffer = exports.sleepless_grid:getBufferSize()

On this page