Skip to content

Server-side API

The resource’s server script keeps a live link to the radio server. It’s on by default and needs nothing beyond the normal setup: it uses meridian_secret to prove it belongs to your radio system (the secret itself is never sent), and the address of meridian_url with /game added (wss://example/ws becomes wss://example/ws/game).

set meridian_server_api "false" # turn the link off (radios keep working, but the server stops checking their signal)
set meridian_game_url "wss://example.com/ws/game" # only if the address can't be worked out from meridian_url

The server console shows linked to the radio server once it’s up. If it can’t link, it says why (usually a secret that doesn’t match the radio server’s) and keeps retrying.

if exports.meridian:isLinked() then
for _, unit in ipairs(exports.meridian:getUnits()) do
print(unit.alias, unit.talkgroupId, unit.player)
end
end
Export Returns
isLinked() Whether the link to the radio server is up
getTalkgroups() Every talkgroup: { id, name, alias, priority, patchId }, where priority is whether it has priority traffic and patchId is the patch it’s in (or nil)
getUnits() Every connected radio (see below)
getUnit(unitId) One radio, or nil
getUnitByPlayer(playerId) A player’s radio if it’s connected, or nil
getUnitIdForPlayer(playerId) The unit ID of the player’s radio: the one it last connected as, otherwise the player’s own (it’s fixed per player)
getCalls() Calls in progress: { callId, talkgroupId, unitId, alias, emergency, startedAt, fromConsole, player }
getEmergencies() Active emergencies: { unitId, alias, talkgroupId, acknowledgedBy, since, player }
getPriority() Talkgroups with priority traffic: { talkgroupId, by, since }
getPatches() Patched talkgroups: { patchId, talkgroupIds, by, since }

A radio (unit) is { unitId, alias, agencies, talkgroupId, siteId, bars, inhibited, player }. player is the player’s server ID, or nil for a radio that isn’t a player on this server. Times are milliseconds since the epoch. While the link is down these return the last known state; check isLinked().

Meridian reports where every player’s radio is, for the dispatch live map, the signal check and radio speakers. A radio with no player behind it (an AI patrol unit your script connects, for example) has no position until you give it one:

-- Every couple of seconds while the AI unit is out
local coords = GetEntityCoords(patrolCar)
exports.meridian:setUnitPosition(unitId, coords.x, coords.y, coords.z)

setUnitPosition(unitId, x, y, z) returns true when stored. A position is forgotten 10 seconds after the last call, so keep calling it; setUnitPosition(unitId, nil) forgets it straight away. Up to 256 units at once. The position is used like a player’s: the unit shows on the live map, its signal is capped by the towers near it, and with radio speakers on, players near it hear the calls it receives.

These work without the radio server link, on the radio a player is holding. Each returns { ok = true, message } or { ok = false, error }, and the radio reconnects with its new identity if it’s on.

Export Effect
setRadioName(playerId, name) Name the player’s radio, like /radioname; nil, "" or "-" clears it. Refused when meridian_alias leaves out custom
programRadio(playerId, unitId?) Program the radio item the player holds for them, like /radioprogram: their unit ID (or unitId), channels and name. Only for radio items that keep their identity (frameworks guide)
-- A department menu sets the radio's name when a character clocks in
local result = exports.meridian:setRadioName(source, "EMS " .. badge)
if not result.ok then print(result.error) end

setRadioBattery(playerId, percent) sets the charge (0–100) of the player’s handheld when the community uses radio batteries, for example from a charger or a medic bag. It returns false for an unknown player.

These are local server events.

Event Arguments
meridian:linkChanged linked
meridian:unitConnected unit
meridian:unitDisconnected unit
meridian:unitTalkgroupChanged unit, previousTalkgroupId
meridian:unitInhibited unit, inhibited
meridian:callStarted call
meridian:callEnded call
meridian:emergencyRaised emergency
meridian:emergencyAcknowledged emergency
meridian:emergencyCleared emergency
meridian:priorityStarted priority
meridian:priorityEnded priority
meridian:patchCreated patch
meridian:patchChanged patch (talkgroups joined or left it)
meridian:patchEnded patch

An emergency that moves to another talkgroup is cleared, then raised again. After the link drops and comes back, events describe what changed in the meantime.

-- Panic blip for everyone on duty when an emergency is raised
AddEventHandler("meridian:emergencyRaised", function(e)
if not e.player then return end
local coords = GetEntityCoords(GetPlayerPed(e.player))
TriggerClientEvent("my-cad:panicBlip", -1, e.alias, coords)
end)
Export Effect
acknowledgeEmergency(unitId, by?, cb?) Acknowledge a radio’s emergency; radios show who acknowledged it
clearEmergency(unitId, by?, cb?) Clear a radio’s emergency
raiseEmergency(unitId, talkgroupId?, by?, cb?) Raise an emergency for a radio (a panic button in your script), on talkgroupId or its selected talkgroup
setInhibited(unitId, inhibited, by?, cb?) Disable or re-enable a radio
setTalkgroup(unitId, talkgroupId, by?, cb?) Move a radio to a talkgroup in its codeplug
alertUnits(unitIds, tone, by?, cb?) Play an alert tone on a list of radios
alertTalkgroup(talkgroupId, tone, by?, cb?) Play an alert tone on every radio selected to a talkgroup
getAlertTones() { { id, name, agencies } }: the alert tones, built-in first, then your community’s own. agencies is empty for a tone every radio gets
setPriority(talkgroupId, on, by?, cb?) Turn priority traffic on or off for a talkgroup
patchTalkgroups(talkgroupIds, by?, cb?) Patch talkgroups together (at least two, counting any patch they’re already in, which merges)
unpatchTalkgroups(talkgroupIds, by?, cb?) Take talkgroups out of their patches; a patch left with one talkgroup ends

Tones are "alert" (three long beeps), "priority" (a hi-lo warble) and "page" (two short beeps), or the ID of one of your community’s own alert tones (from getAlertTones()). The "priority" tone plays once; for the repeating priority traffic beep, use setPriority.

A tone kept for some agencies plays only on radios in them. alertUnits fails with no_permission if none of the radios fit; an unknown tone fails with no_tone. Your own tones need an up-to-date radio server: an older one refuses them with bad_request.

Patching or unpatching cuts off calls in progress on those talkgroups. Patching a single talkgroup fails with bad_request, as does patching against a radio server too old to support it.

by is who took the action, for example the CAD user’s name (up to 48 characters). It’s shown on radios for acknowledgements and recorded in the audit log; without it the action shows as “Game server”. The audit log also records which resource called the export.

Each action returns true if it was sent, or false if the arguments are invalid or the link is down. To learn the outcome, pass a callback: it’s called with ok, error, message, where error is one of unit_offline, no_emergency, no_talkgroup, no_permission, unknown_talkgroup, no_tone, inhibited, out_of_range, bad_request, rate_limited, not_linked or timeout.

local unitId = exports.meridian:getUnitIdForPlayer(source)
exports.meridian:setTalkgroup(unitId, 501, "CAD: " .. dispatcherName, function(ok, err)
if not ok then print("couldn't move the radio: " .. err) end
end)
exports.meridian:alertTalkgroup(101, "priority", "Dispatch")
-- A pursuit starts: keep the talkgroup clear until it's over
exports.meridian:setPriority(101, true, "CAD: " .. dispatcherName)
-- Police and fire at the same scene: patch their talkgroups, and unpatch when it's over
exports.meridian:patchTalkgroups({ 101, 301 }, "CAD: " .. dispatcherName)
exports.meridian:unpatchTalkgroups({ 101, 301 })
Export Effect
getSpeakers() { speakers: [{ id, name, groups }], groups: [{ id, name }], tones: [{ id, name }] }: the system’s world speakers, groups and tones (the built-in speaker tones and every alert tone)
toneSpeakers(tone, speakerIds, groupIds?, by?, cb?) Sound a tone on speakers

tone is a tone ID: a built-in one ("alert", "attention", "hilo", "warble", "whoop", "page") or any of your alert tones. speakerIds and groupIds are each an ID or a list of IDs; give either or both (pass nil for the one you don’t need). The tone plays on every speaker named or in a named group, for the players near them.

Besides the errors above, the callback can get no_speakers (none of the IDs match a speaker) or no_tone (no tone with that ID).

exports.meridian:toneSpeakers("hilo", nil, { "st1", "st3" }, "CAD: " .. dispatcherName, function(ok, err)
if not ok then print("couldn't tone out: " .. err) end
end)

getPhoneLines() returns the numbers players can call and text dispatch on: { id, number, name, texting } for each line, or an empty list when phone calls are off (in System → Phone, or with meridian_phone set to off).

These exports are only available to server scripts. Players can’t reach them; if you expose them through your own net events or commands, check the player is allowed to use them first.