Client exports
Other
Client exports for crypto values, key binds, checks and inventory counts.
#GetCryptoWallet
Returns the coins this player holds.
lua---@return { coin: string, symbol: string, amount: number, value: integer }[] wallet
exports['fx-phone']:GetCryptoWallet()
luafor _, entry in ipairs(exports['fx-phone']:GetCryptoWallet()) do print(entry.symbol, entry.amount, entry.value) end
valueis the amount times the current price, rounded down.- The coin list is cached on the client for a short time; the first call asks the server and waits.
#GetCoinValue
Returns the current price of a coin.
lua---@param id string coin id
---@return number|nil price nil for an unknown coin
exports['fx-phone']:GetCoinValue(id)
lualocal price = exports['fx-phone']:GetCoinValue('bitcoin')
#AddKeyBind
Adds a key the player can rebind in the GTA key binding settings.
lua---@class KeyBindOptions
---@field name string letters, digits and `_`
---@field description? string label in the settings, up to 60 characters
---@field key? string default key, for example 'CAPITAL'
---@field onPress? function
---@field onRelease? function
---@param opts KeyBindOptions
---@return { Remove: fun() }|nil bind
exports['fx-phone']:AddKeyBind(opts)
lualocal bind = exports['fx-phone']:AddKeyBind({
name = 'radio_ptt', description = 'Talk on the radio app', key = 'CAPITAL', onPress = function() startTalking() end,
})
- Returns
nilwhenoptsis not a table ornamehas other characters. - The command is registered as
phone_<name>.bind.Remove()switches the key off; the mapping itself stays in the game settings.
#AddCheck
Adds a function that can stop the phone from opening.
lua---@param event 'openPhone'
---@param fn fun(): boolean|nil, string|nil return false to block; the optional text is shown to the player
---@return integer|nil id
exports['fx-phone']:AddCheck(event, fn)
lualocal id = exports['fx-phone']:AddCheck('openPhone', function()
if LocalPlayer.state.inJail then return false, 'Phones are not allowed here.' end
end)
- On the client only
openPhoneruns. The server has more events: see Checks. - A check that throws an error never blocks. Checks are removed when your resource stops.
#RemoveCheck
Removes a check you added.
lua---@param id integer
---@return boolean removed
exports['fx-phone']:RemoveCheck(id)
luaexports['fx-phone']:RemoveCheck(id)
#getQuantity
Returns how many of an item the player carries.
lua---@param item string item name
---@return integer count 0 when `item` is not a string
exports['fx-phone']:getQuantity(item)
lualocal count = exports['fx-phone']:getQuantity('water')
#hasEnoughOfItem
Returns whether the player carries at least that many of an item.
lua---@param item string item name
---@param amount? integer default 1
---@return boolean enough
exports['fx-phone']:hasEnoughOfItem(item, amount)
luaif exports['fx-phone']:hasEnoughOfItem('lockpick', 2) then startLockpick() end