Events and state

Checks

Veto hooks that let your resource block the phone from opening or block a player action on the server.

A check is a function that can block an action. Add one with the export AddCheck and remove it with RemoveCheck. Both exist on the client and on the server.

lua-- server
local id = exports['fx-phone']:AddCheck('sendMessage', function(src, conversationId, body)
    if Player(src).state.gagged then return false end
end)

exports['fx-phone']:RemoveCheck(id)

#Rules

  • Return false to block. Anything else, including nothing, lets the action through.
  • A check that throws an error never blocks.
  • Every check for an event runs until one blocks.
  • Checks are removed when the resource that added them stops.
  • AddCheck returns the check id, or nil when the event name is not a string or no function is given.

#Events

Event Side Arguments When blocked
openPhone client none The phone stays closed. A string returned as the second value is shown to the player as a notification
sendMessage server src, conversationId, body The action fails with denied
createCall server src, number The call fails with denied
transfer server src, targetIdentifier, amount The transfer fails with denied
buyCrypto server src, coinId, quantity, cost The purchase fails with denied
createDarkchat server src, tag The channel is not created
post server see below The post fails with denied
lua-- client: no phone in jail
exports['fx-phone']:AddCheck('openPhone', function()
    if LocalPlayer.state.inJail then return false, 'Phones are not allowed here.' end
end)

#sendMessage

Runs before a player sends a message in Messages, Wisp, a social app's direct messages or Anon. conversationId is the conversation's id; Anon rooms use 'anon:<room id>', Anon notices 'anon:notes' and Wisp status posts 'wisp:status'.

#transfer

Runs before a bank transfer, before money is sent or requested inside a chat, and before a paid gift in Live.

#post

Runs for several apps, with two argument shapes:

App Arguments
Posts in Chirp, Pixl and Clips src, { app, body, media }
Reposts src, { app, repostOf, media }
Comments src, { app, body, comment = true, postId }
Pixl stories src, { app, story = true, media }
Marketplace src, 'marketplace', title
News src, 'news', title

#What checks do not cover

Checks run for what players do on the phone. The message, bank, crypto and post exports (for example SendMessage, AddTransaction, AddCrypto) act as the system and do not run them. The call exports are the exception: CreateCall and StartVideoCall start the call through the same path as the player, so the createCall check runs for them too.

The export signatures are in Other (client) and Other (server).