Events and state
State bags
The player and global state bags fx-phone sets, who writes them and what they hold.
fx-phone publishes a few values in state bags so other resources can read them without an export call.
#Player state bags
Read them with Player(src).state.<name> on the server, or LocalPlayer.state.<name> and Player(serverId).state.<name> on the client.
| Bag | Set by | Value |
|---|---|---|
fxphone |
client, replicated | { open = boolean, number = string }. Removed when the resource stops |
fxphone_call |
client, replicated | The current call, or nil. See below |
fxphone_number |
server | The player's phone number |
fxphone_power |
client, replicated | { battery = 0..100, signal = 0..4 } |
fxphone_flash |
client, replicated | The flashlight: true / false from the flashlight switch; the camera also writes its flash state here while it is open |
fxphone_prop |
client, replicated | Network id of the phone prop in the player's hand, or nil |
fxphone_kit |
server | The case and accessories on the phone, as returned by GetPhoneKit. Every client nearby dresses the prop with it |
fxphone_arm |
client, replicated | Hand position data used to draw the phone arm for nearby players. Internal |
The call in fxphone_call is { id, number, name, direction = 'incoming' | 'outgoing', state, startedAt, anonymous, speaker }.
lua-- server: is the player on the phone right now?
local call = Player(src).state.fxphone_call
if call and call.state == 'active' then
-- in a call
end
lua-- client: react when another player's phone opens or closes
AddStateBagChangeHandler('fxphone', nil, function(bagName, _, value)
local player = GetPlayerFromStateBagName(bagName)
if player ~= 0 and value then print(GetPlayerServerId(player), value.open) end
end)
#Global state
| Bag | Set by | Value |
|---|---|---|
GlobalState.fxphone_lens |
server | Camera and hold tuning saved by an admin, sent to every client. Internal |
#Trust
The bags marked "client, replicated" are written by the player's own client. Do not use them for anything that must be trusted, such as a payment or a permission. For those, ask the server exports: GetPhoneNumber, IsInCall, GetPhoneKit. See All exports.