Phone API
Reach a player's phone from your resource with exports.whip_phone. New to the phone? Read Phone System first; to add an app, Phone apps.
If your resource runs without the phone, check GetResourceState('whip_phone') == 'started' before a call.
Server
A notification on the player's phone. It peeks up from the corner while the phone is put away, and a tap opens the app it names.
| n field | Type | Description |
|---|---|---|
| title, text | string | What it says |
| app | string? | The app it's from: its icon, and what a tap opens. An unknown id shows a bell |
| kind | string? | 'chat' (the default), 'command' (it needs them), 'success', 'error', 'warning' or 'call'. Only 'call' gets through Do Not Disturb |
| args | table? | Handed to that app's open when it's tapped |
| sound | boolean? | false: quiet. Otherwise it plays the SIM's notification sound, unless Do Not Disturb is on |
true, or false when n isn't a tableexports.whip_phone:Notify(source, {
app = 'mycars', title = 'My Cars', text = 'Your Sultan was towed', kind = 'warning',
})
GetItemCount(source, 'phone') first if a player without one shouldn't see it.Runs on[event](app, data) in that app on the player's phone, so your app updates without asking.
| Param | Type | Description |
|---|---|---|
| source | number | The player |
| app | string | The app's id |
| event | string | The name of one of its on handlers |
| data | any | What the handler gets |
trueexports.whip_phone:Push(source, 'mycars', 'changed', { id = vehicleId }) -- runs on.changed
Takes the player's phone out, as F3 does, or puts it away. It opens only with a phone on them; without one they're told "You need a phone".
| Param | Type | Description |
|---|---|---|
| source | number | The player |
| mode | string? | 'phone' (folded, the default) or 'tablet' |
trueClient
Takes this player's phone out or puts it away, as the server's do, and says whether it's in use. IsOpen is true while the player is using it (it has the focus).
GetState: 'hidden', 'peek' (notifications showing), 'phone' or 'tablet'if exports.whip_phone:GetState() == 'tablet' then return end -- it covers the screen's middle
Adds your resource's app to the phone, or takes it away. It goes by itself when your resource stops; register it again when whip_phone restarts (Whip.registerWith does both). See Phone apps.
| def field | Type | Description |
|---|---|---|
| id | string | Lowercase letters, digits, _ or -, up to 32 characters |
| script | string | The app's file in your resource, listed in its files {} (default 'html/module.js') |
| ns | string? | What its requests start with (default your resource's name): app.request('list') asks <ns>:list |
true, or false, why: a bad id, 'that id is a built-in module', or 'the phone app "mycars" belongs to other_res'. UnregisterModule takes only your ownOpens the phone unfolded to a tablet, held to one app, and waits for its answer: no home screen, no folding, no other app, and every game control held off. The app answers with app.done(result); putting the phone away, or Back the app doesn't take, gives up. Afterwards the phone goes back to how it was. Call it from a thread. IsHeld says whether one is running.
| Param | Type | Description |
|---|---|---|
| id | string | The app |
| args | table? | What its open(app, args) gets |
result table; { passed = false, why = 'cancelled' } when given up; or nil, why when it can't start: 'busy', 'dead', 'no app', 'not ready'CreateThread(function()
local result, why = exports.whip_phone:RunApp('mycars', { pick = true })
if not result then return print('the phone could not open: ' .. why) end
if result.why == 'cancelled' then return end -- put away
print('they picked car ' .. tostring(result.id)) -- the app called app.done({ id = ... })
end)
Events#
| Event | Side | Args | When |
|---|---|---|---|
whip_phone:client:opened | Client | open (boolean) | The player took the phone up or let it go. Not for something in their hands: the phone plays Config.Emotes itself, and a second animation fights it |
whip_phone:client:state | Client | 'hidden', 'peek', 'phone' or 'tablet' | What the phone shows changed |