Client exports

Dialogs and pickers

Client exports that ask the player a question or let them pick something on the phone screen.

Each of these opens the phone if it is closed.

#DoPhoneConfirmation

Shows a yes / no question on the phone and gives back the answer.

lua---@param title string up to 60 characters
---@param text string up to 300 characters
---@param icon? string icon name
---@param cb? fun(accepted: boolean)
---@return boolean|nil accepted the answer without `cb`; nil with `cb`
exports['fx-phone']:DoPhoneConfirmation(title, text, icon, cb)
luaif exports['fx-phone']:DoPhoneConfirmation('Sell vehicle', 'Sell your Sultan?', 'car') then
    TriggerServerEvent('my-dealer:sell')
end
  • Without cb the export waits for the answer, so call it from a thread or an event handler.
  • With cb it returns at once and calls cb(accepted) later.
  • No answer within 60 seconds counts as false.
  • Returns false (and calls cb(false)) when the phone has not loaded or the player has no phone item.
  • Several confirmations are shown one after another.

#ShowComponent

Opens a picker and gives back what the player chose.

lua---@class ComponentOptions
---@field type 'contact'|'gallery'|'camera'|'gif'|'emoji'|'color'
---@field title? string heading, up to 60 characters
---@field multiple? boolean lets the player pick several
---@field max? number most items with `multiple`, 1 to 20

---@param opts ComponentOptions
---@param cb? fun(result: any)
---@return any|nil result the choice without `cb`; nil with `cb`, on cancel, or after 120 seconds
exports['fx-phone']:ShowComponent(opts, cb)
lualocal contact = exports['fx-phone']:ShowComponent({ type = 'contact' })
if contact then print(contact.number) end
type The player picks Result
contact A contact { id, number, firstname, lastname, avatar }
gallery A photo or video { id, url, thumbnail, kind }
camera Takes a new photo { id, url, thumbnail, kind }
gif A GIF { id, url, preview, width, height }
emoji An emoji the emoji
color A colour '#RRGGBB'
  • Returns nil for an unknown type or when the phone cannot open.
  • With multiple = true the result is a list.

#SetPopUp

Shows a popup with your own buttons.

lua---@class PopUpButton
---@field title string up to 40 characters (`label` is accepted too)
---@field style? string 'cancel' or 'destructive' (`color = 'red'` also gives a destructive button)
---@field icon? string icon name
---@field cb? function called when pressed (`onPress` is accepted too)

---@param data { title: string, description?: string, buttons?: PopUpButton[] }
---@return string|nil id
exports['fx-phone']:SetPopUp(data)
luaexports['fx-phone']:SetPopUp({
    title = 'Tow request', description = 'A player needs a tow at Pillbox.',
    buttons = { { title = 'Accept', cb = function() acceptTow() end }, { title = 'Ignore', style = 'cancel' } },
})
  • title is cut at 60 characters, description at 300. Up to 8 buttons.
  • Returns nil when data is not a table or the phone cannot open.

#SetContextMenu

Shows a menu of actions.

lua---@param data { title?: string, buttons?: PopUpButton[] }
---@return string|nil id
exports['fx-phone']:SetContextMenu(data)
luaexports['fx-phone']:SetContextMenu({
    title = 'Vehicle',
    buttons = { { title = 'Lock', icon = 'lock', cb = function() lockVehicle() end } },
})
  • Same button shape and limits as SetPopUp.