Skip to content

Exports & events ​

What other resources may rely on: a heist that cuts a tower, a dispatch that checks whether a phone has service, a script that adds a temporary tower for an event.

Rules that hold for all of it:

  • Server only. Call it as exports.np_cellnet:<name>(...).
  • Tables you get are copies. Changing them changes nothing in np_cellnet.
  • Wait for the resource before the first call: GetResourceState('np_cellnet') == 'started', or the event np_cellnet:server:ready.
  • Exports are trusted server code: getCellRecords and triangulate skip the warrant check the app enforces.

Server exports ​

server

Export Returns Description
getSignal(src) state | nil The player's np_phone network state plus score (0–100). nil while np_cellnet does not track the player
getTowers() { tower, ... } Every tower with its live status (below)
getTower(id) tower | nil One tower
setTowerOnline(id, online, reason?, seconds?) boolean Takes a tower down (reason defaults to 'admin') or brings it up. With seconds it comes back by itself. Written to the np_admin log
addTower(def) true | false, err A runtime tower, not stored. Owner-tracked: removed when your resource stops (below)
removeTower(id) boolean Removes a runtime tower your resource added
isJammed(coords) boolean, jammerId? Is a jammer active at that position?
getCellRecords(number, fromTs, toTs) { rows, imei, imeis, linkedNumbers, number, from, to } Cell records of a number. rows = { { ts, tower, label, x, y, event } }
triangulate(number) { rings, fix, number, at } | nil, err A live fix: fix = { x, y, error }. Errors invalid_number, offline, phone_off, no_towers
getPlan(src) plan | nil { id, name, carrier, priceWeekly, dataGb, usedGb, paidUntil, paid }
addUsage(src, mb) boolean Counts mobile data your resource used. Ignored on Wi-Fi; at most 1024 MB per call
giveSim(src, carrier) boolean A new SIM item of that carrier (without SIM items: switches the account carrier)
useItem The item use export for np_inventory / ox_inventory (server = { export = 'np_cellnet.useItem' })

The network state ​

getSignal returns what np_cellnet pushed to np_phone (np_phone → Network), plus the score:

lua
{ bars = 3, type = 'LTE', carrier = 'Badger', tint = 'green',
  tower = { id = 'LS-07', label = 'Vinewood Hills' }, dbm = -87, load = 41,
  wifi = nil,                 -- { ssid } on a hotspot
  roaming = false, sos = false, jammed = false,
  plan = { name = 'Badger Plus', used = 3.2, limit = 10 },   -- GB
  score = 68 }

Tower ​

lua
{ id = 'LS-07', label = 'Vinewood Hills', carrier = 'badger',   -- 'badger' | 'whiz' | 'tinkle' | 'shared'
  coords = { x = 0.0, y = 800.0, z = 210.0 }, type = 'LTE',     -- '5G' | 'LTE' | '3G' | 'E'
  range = 1700, height = 40, slots = 20, dataSlots = 90, backupPower = 300,
  cabinet = { x = 3.0, y = 2.0, z = 0.0 },                       -- offset from coords
  rural = false, cayo = false, sabotageCooldown = nil,
  online = true, reason = nil, untilTs = nil, backupUntil = nil,
  source = 'config',                                             -- 'config' | 'db' | 'runtime' | 'cow'
  load = 41, calls = 3, users = 37 }

Runtime towers ​

addTower(def) takes the tower fields above; id and coords are required, carrier defaults to 'shared' and the other fields come from Config.TowerDefaults. The tower is live at once, never stored, and removed when your resource stops. Errors: invalid_id, invalid_coords, invalid_carrier, invalid_type, invalid_cabinet, id_taken.

lua
-- a temporary mast for a concert at the Vinewood Bowl
local ok, err = exports.np_cellnet:addTower({
  id = 'EVT-BOWL', label = 'Vinewood Bowl (event)', carrier = 'shared',
  coords = { x = 686.0, y = 577.0, z = 130.0 }, type = '5G', range = 500, slots = 60, dataSlots = 400,
})

-- later
exports.np_cellnet:removeTower('EVT-BOWL')

Examples ​

lua
-- a heist cuts the power plant tower for 15 minutes
exports.np_cellnet:setTowerOnline('BC-04', false, 'power', 15 * 60)

-- is anyone near this bank jammed?
local jammed, jammerId = exports.np_cellnet:isJammed({ x = 150.0, y = -1040.0, z = 29.4 })

-- a drone app that streams video counts its data
exports.np_cellnet:addUsage(src, 25)

For "can this player do X" prefer np_phone's own check, which also knows Wi-Fi Calling and the player's settings: exports.np_phone:canUse(src, 'voice') (np_phone → Network).

Server events ​

server

Local server events (AddEventHandler), fired by np_cellnet:

Event Arguments When
np_cellnet:server:ready – Schema applied, towers loaded
np_cellnet:signal src, state, previous A player's network state changed (after it was pushed to np_phone)
np_cellnet:towerStatus towerId, online, reason A tower went down or came back
np_cellnet:sabotage src, towerId, action action = 'cut' or 'breaker', after the progress finished
np_cellnet:jammer 'placed' | 'removed', { id, coords, radius?, owner?, reason? } reason: 'battery', 'picked_up', 'disabled'
lua
AddEventHandler('np_cellnet:sabotage', function(src, towerId, action)
  -- e.g. raise the wanted level of the saboteur in your own police script
end)

np_cellnet:server:* / np_cellnet:client:* net events are np_cellnet's own transport between client and server. Don't trigger them from other resources.

The CellNet app ​

The app (web/dist/phone.html) runs inside np_phone and calls its RPCs with phone.rpc('<name>', params) through np_phone's pipeline (rate limit, phone item, passcode, app gate), plus a per-player cooldown each:

state, coverage, bestSignal, plans, setPlan, payPlan, fieldTest, ops.alerts, ops.accept, ops.deployCow, ops.upgrade, records.query, records.triangulate, wifi.join.

np_cellnet pushes state (the player's network state changed) and ops (to technicians, when a tower's status changed) with sendAppMessage. The app also gets np_phone's own network SDK event.