Skip to content

Events, state bags & NUI ​

Public events ​

Event Side Arguments Notes
np_flightradar:aircraftAdded server local netId, kind An aircraft entered the registry ('heli' or 'plane')
np_flightradar:aircraftRemoved server local netId An aircraft left the registry (deleted, despawned, or found missing)
np_flightradar:emergency server local netId, squawk, info An aircraft switched into 7500 / 7600 / 7700. See below
np_flightradar:contactsUpdated client local contacts After every radar update. Same shape as GetContacts
np_flightradar:proximity client local level, netId TCAS state changed. See below

All of these are local events (TriggerEvent), so only scripts on the same side can listen with AddEventHandler. They are not net events.

np_flightradar:emergency ​

lua
AddEventHandler('np_flightradar:emergency', function(netId, squawk, info)
  -- info = { callsign, kind, reason, by, coords = { x, y, z } }
  exports.my_dispatch:CreateCall('aviation', ('%s squawks %s'):format(info.callsign, squawk), info.coords)
end)
Field Description
callsign Resolved callsign
kind 'heli' or 'plane'
reason Config.Emergency.codes[squawk]: 'hijack', 'radio' or 'emergency' by default
by Server id of the player who set the squawk, nil for SetTransponder
coords { x, y, z } at the time of the change

Fired once per switch into an emergency squawk, before the job notifications and the Discord log.

np_flightradar:proximity ​

lua
AddEventHandler('np_flightradar:proximity', function(level, netId)
  -- level: 'TA' | 'RA' | 'clear'; netId: the worst intruder, nil for 'clear'
end)

Fired when the level or the worst intruder changes, and on every check (500 ms) while an RA is active, so the climb / descend text stays current. See Using the radar → TCAS.

Commands ​

Command Description
/radar Panel: open → mouse focus (in a vehicle) → close. Key mapping, default F6
/squawk <code> Set the squawk
/transponder [on|off] Switch the transponder, or toggle
/callsign [text] Set or reset the callsign

Names come from Config.Commands. See Using the radar → Commands and keys.

State bags ​

Bag On Written by Value
np_fr_xpdr aircraft entity np_flightradar, server only (replicated) { on, squawk, callsign }
vehicleCallsign aircraft entity np_manufacturing (read only here) string
helicam_cam aircraft entity np_helicam (read only here) { on = bool, … }

Clients never write np_fr_xpdr. They send np_flightradar:setTransponder and the server writes the bag. The server keeps its own copy and only publishes the bag, so a value a client writes to an entity it owns is ignored. An aircraft without the bag uses Config.Transponder.defaultOn and defaultSquawk. The bag lives on the entity, so a respawned aircraft starts with the defaults again.

Network protocol ​

Internal net events, documented for debugging. Don't trigger them from other resources.

Event Direction Payload
np_flightradar:hello client → server – . Asks for the access summary (start, spawn, job change). Throttled to once per 2 s
np_flightradar:access server → client { modes = { [mode] = true }, best }. UI hints only
np_flightradar:subscribe client → server mode, reqId. mode is a mode name or 'auto'
np_flightradar:unsubscribe client → server –
np_flightradar:subscribed server → client { mode, range, primary, reqId }
np_flightradar:denied server → client { mode, reqId }
np_flightradar:revoked server → client reason ('access_lost')
np_flightradar:contacts server → client { t, c = { { id, x, y, z, h, s, vs } … } }
np_flightradar:meta server → client { [netId] = { kind, model, callsign, squawk, org, flags } }
np_flightradar:setTransponder client → server { on?, squawk?, callsign? }
np_flightradar:notify server → client Notification data, shown through np_hud / ox_lib / the feed
np_flightradar:useScanner server → client – . Framework usable-item fallback
np_flightradar:openRadar server → client mode. np_admin staff tool Open admin flight radar. The client then subscribes as usual
  • Subscriptions are rate-limited to one change per 250 ms per player. Requests inside the window are coalesced (latest wins) and still answered, so the client always gets subscribed or denied for its latest reqId.
  • Contacts are integers only: x, y, z in metres, h the GTA heading in degrees, s (ground speed) and vs (vertical speed) in m/s × 10. This is the full set every tick; the client removes anything missing.
  • Meta is sent per subscriber only when an aircraft is new to them or its static data changed. Primary radar contacts get { kind, flags = { xpdrOff = true } } and nothing else.
  • setTransponder only forwards the three known keys. The server checks the seat (pilot, or seat 0 when allowed), validates and cleans the values, and rate-limits per player (Config.Transponder.rate).

Performance ​

  • Nothing runs while nobody is subscribed. The broadcast thread exists only while there is at least one subscriber. Seat detection uses CEventNetworkPlayerEnteredVehicle and only watches the seat at 1 Hz while you sit in an aircraft.
  • The registry is kept current by entityCreated / entityRemoved. GetAllVehicles runs at start and in a 30 s safety re-sync.
  • Each tick builds one snapshot (O(aircraft)), then filters it per subscriber (O(aircraft) each).
  • Access is cached per player for 30 s and dropped on job, duty or load events. Pilot licences are cached for 60 s and refreshed off-thread. Discord roles are cached and refreshed in a thread.
  • The client runs at most one blip lerp thread (only while coordinate blips exist), pushes NUI updates at most at 2 Hz and only while the panel is open, and runs the TCAS check at 2 Hz only while you are the pilot.

NUI contract ​

The panel is html/index.html (ui_page). Lua sends SendNUIMessage with a field action; the page answers through RegisterNUICallback. Every callback replies { ok = true }.

Message (action) Data
open mode, focus (bool), locale (the merged locale table), config = { ranges, range, units, canTransponder }
close –
focus on
contacts self = { x, y, z, heading, inAircraft }, range, contacts (see below)
transponder state = { on, squawk, callsign, canEdit } or nil
alert level ('TA', 'RA', 'clear'), text, id (netId)
Callback Body
close –
focus { on }
setRange { range } in metres, 0 = unlimited. Capped at the granted range
setFilter { heli, plane, emergencyOnly }
transponder { on?, squawk?, callsign? }. Forwarded to the server like the commands
select { id }. Sets a GPS waypoint to the contact

Contact shape ​

Field Description
id Network id
kind 'heli' or 'plane'
callsign, model Callsign and the model's display name. Missing for primary radar contacts
squawk 4 digits, nil when the transponder is off
x, y, z, alt Position in metres. alt = z
heading Compass degrees (0 = north, clockwise)
speed, vs Ground speed and vertical speed in m/s
dist, bearing Horizontal distance (m) and compass bearing from you
flags { emergency, xpdrOff, unlicensed, camera, org }. emergency is the squawk or nil, org one of police, ems, fire, military or nil
threat 'TA', 'RA' or nil

Distances are metres and speeds m/s. The page converts to the configured units.

Phone app ​

html/phone.html runs inside np_phone and loads the np_phone SDK from https://cfx-nui-np_phone/web/dist/sdk/np-phone.js. It gets the same contacts payload through sendAppMessage('flightradar', 'contacts', payload), plus mode, and { contacts = {}, denied = true } when the phone mode is denied. Set waypoint posts select to this resource. The phone payload carries no locale table, so the app ships its own English and German strings.

Locale keys ​

The panel receives the merged locale table as open.locale. Panel keys (English in locales/en.lua, German in locales/de.lua):

title, contacts, range, range_unlimited, filters, filter_heli, filter_plane, filter_emergency, transponder, squawk, callsign, on, off, apply, close, focus, no_contacts, unidentified, unlicensed, camera, xpdr_off, emergency, kind_heli, kind_plane, model, altitude, speed, heading, vertical_speed, distance, bearing, set_waypoint, waypoint_set, sq_7500, sq_7600, sq_7700, org_police, org_ems, org_fire, org_military, ta, ra, ta_title, ra_title, ta_text, ra_climb, ra_descend, ra_turn, clear_text, mode_air, mode_ground, mode_station, mode_item, mode_phone, mode_admin, unit_ft, unit_kt, unit_fpm, unit_nm, unit_m, unit_kmh, unit_ms, unit_km, squawk_hint, callsign_hint

The same files hold the game texts (notifications, commands, radial labels). Missing keys fall back to English, then to the key itself.