Pulse Phone docs

Pulse Phone developer API

Pulse Phone gives other resources a server and client API: read a player's number, send texts, mail and notifications, place calls, react to what happens on the phone, and add apps of your own. Everything on this page is taken from the phone resource of Pulse Phone 1.5.0. The complete list, with every argument, is on Exports and events.

For Pulse Phone 1.5.24 min readUpdated

Where the API lives

The resource is named phone, so every call is exports.phone:.... Wait for the phone before you use it: IsReady() turns true once the database answers and the phone takes requests.

Lua
CreateThread(function()
    while GetResourceState('phone') ~= 'started' or not exports.phone:IsReady() do Wait(500) end
    print('Pulse Phone is ready')
end)

phone_api in the server console prints a short summary of the app API.

Server exports used most

Export What it does
GetPhoneNumber(src) the number of the phone the player holds, or nil until they have loaded
SourceOfNumber(number) the online player with that number, or nil
Notify(src, { title, body, app?, actions? }) a notification on that player's phone, with up to 3 buttons
SendMessage(src, number, text) a text from that player to a number
SendMail(address, sender, subject, body) a mail to an address
Call(src, number, video?) places a call for that player
SetPhoneDisabled(src, bool) switches a player's phone off or on (a jail, a cutscene)
RecordTransaction(number, 'sent' or 'received', amount, party, note?) a statement line in Wallet; it does not move money

Scripts written for another phone call these instead of that phone's exports:

Export What it does
ResolvePhone(target[, cb]) finds a phone by { source }, { number }, { email }, { identifier } or { imei }
DeliverMailTo(target, mail[, cb]) mail to that phone: { sender, subject, body }
SendText(from, to, body[, opts][, cb]) a text from a phone, or from a named service
DispatchAlert(jobs, { title, body, coords? }) an alert to every on-duty member of those jobs; it returns how many it reached

Example: a robbery script alerts the police with a map pin.

Lua
local reached = exports.phone:DispatchAlert({ 'police', 'sheriff' }, {
    title = 'Store robbery',
    body = 'Alarm at the 24/7 on Innocence Blvd.',
    coords = vector3(25.7, -1345.6, 29.5),
})

Server events

Listen with AddEventHandler in a server script. Only the phone raises them; a client cannot fake them.

Event Arguments
phone:numberChanged src, number, oldNumber
phone:callStarted callId, fromNumber, toNumber, fromSrc, toSrc, video
phone:callEnded fromNumber, toNumber, reason, durationMs, fromSrc, toSrc, callId
phone:messageSent fromNumber, toNumber, body
phone:emergencyCall src, service, reason, coords
phone:wallet:transfer fromNumber, toNumber, amount, note
phone:notification:action src, app, notificationId, actionId: a button your Notify offered was pressed

Client exports

Export What it does
Open(), Close(), IsOpen() opens or closes the phone; Open respects every block below
AddOpenCheck(fn) fn() returning false stops the phone opening; removed when your resource stops
SetRestriction(key, mode) a player state of your own: 'block', 'emergency-only' or nil to clear it
SetCarAudio(state) shows your car stereo on Pulse Drive, the car screen
GetPhoneNumber(), IsInCall(), GetBattery() this player's own phone

Example: no phone while a player is in your jail.

Lua
exports.phone:SetRestriction('myjail', 'block')   -- on entering the cell
exports.phone:SetRestriction('myjail', nil)       -- on release

State bags

The server writes these to Player(src).state, with the names other phone resources use, so HUD and dispatch scripts read them unchanged: phoneNumber, phoneOpen, inCall, onCallWith, phoneBattery, phoneDead. Clients read their own as LocalPlayer.state.phoneOpen.

Config examples

The phone's settings are in phone/config/. Three that other scripts depend on:

Lua
Config.Item = {
    required = false,    -- true: the player needs the phone item
    name     = 'phone',
}
Config.Public = {
    numberState = true,  -- publish Player(src).state.phoneNumber
}
Config.Open = {
    blockWhenNuiFocused = true,   -- no phone while another menu holds the cursor
}

Your own apps

exports.phone:RegisterApp({ id, name, colour, icon, page = { kind = 'frame', url = 'ui/index.html' } }) adds an app to the Home Screen and the App Hub. The page runs in its own frame and talks to your server through the phone. Permissions, notifications, languages and the App Hub listing are optional fields. The full guide is Custom apps.

Integration notes

  • Pulse Phone answers the event names of lb-phone, qb-phone and NPWD itself, so scripts that send mail, texts and alerts that way keep working. Scripts that call another phone's exports need one change: exports.phone. See Switching phones.
  • Pass the real source from your own server events. Never take a player id from a client message.
  • Banking, garages, housing and dispatch are connected through the phone's bridges, chosen on start. Your own script can be added as a provider: Advanced integrations.

Frequently asked questions

What is the Pulse Phone resource called?

phone. Every export is exports.phone:Name(...). Keep the folder name, because other scripts and the inventory item hooks call it by that name.

Do scripts made for lb-phone or qb-phone work with Pulse Phone?

Scripts that use those phones' events (mail, texts, notifications, phone number) work without edits. Scripts that call their exports need exports.phone instead.

Can I add my own app to Pulse Phone?

Yes. Register it with RegisterApp from your resource. It appears in the App Hub, and the guide covers pages, permissions and notifications.