Bodycam: Exports & Events
Read and control bodycams, open the viewer and listen to stream events from your own resources.
Resource name
The resource must be named hype-bodycam. Because the name contains a hyphen, call exports as
exports["hype-bodycam"] rather than exports.hype-bodycam.
| Export | Side | Purpose |
|---|---|---|
IsBodycamOn | Client | Is the local player's bodycam recording |
Open | Client | Opens the feed list |
Close | Client | Closes the viewer and the list |
IsOpen | Client | Is the viewer open |
GetViewingStream | Client | Id of the feed being watched |
bodycam | Client | ox_inventory item use, not called by hand |
IsBodycamActive | Server | Is a player's bodycam recording |
SetBodycam | Server | Turns a player's bodycam on or off |
GetStreams | Server | Every active stream |
GetViewers | Server | Players watching a stream |
Stream ids
Every feed has a string id. Bodycams use b<server id> (e.g. b14), dashcams use d<netId> (e.g. d2188).
Client exports
IsBodycamOn
Returns true while the local player's own bodycam is recording. The state comes from the server, so the client keeps
no value of its own. Useful for a "recording" icon on a HUD, or to block an action while the camera is on.
local recording = exports["hype-bodycam"]:IsBodycamOn()Open
Opens the feed list. It is not tied to a terminal, so the viewer stays open even if the player walks away. That makes
it the right choice for your own tablet, phone or MDT. The server checks ViewAccess first; without access the player
gets an error notification and nothing opens.
exports["hype-bodycam"]:Open()Close
Closes the viewer and the list: destroys the camera, restores the HUD and radar, unfreezes the player and removes the viewer on the server. Call it when you have to pull a player out of the camera (death, cuffs, a cutscene, another menu opening).
exports["hype-bodycam"]:Close()IsOpen
Returns true while the feed list or a live feed is on screen. Check it before opening your own menus to avoid
overlaps.
local open = exports["hype-bodycam"]:IsOpen()GetViewingStream
Returns the id of the feed being watched, or nil while only the list is open or nothing is watched.
local id = exports["hype-bodycam"]:GetViewingStream() -- "b14", "d2188" or nilbodycam
The export ox_inventory calls on item use, declared as client.export = "hype-bodycam.bodycam" in data/items.lua.
Other inventories go through the framework usable item instead; both paths end in the same toggle.
Do not call it yourself
To switch a camera from code, use the server export SetBodycam.
Server exports
IsBodycamActive
Returns true while the given player's bodycam is recording. This is the real server state, safe to use for logs,
fines, investigations or "cannot do this with the camera off" checks.
local recording = exports["hype-bodycam"]:IsBodycamActive(source)Prop
Type
SetBodycam
Turns a player's bodycam on or off from code. Turning it on follows the normal rules: the player must carry the item
and be in an allowed job (and on duty if required). If not, or if the camera is already on, it returns false and
nothing changes. Turning it off always works and is logged with the reason "export". Starting plays the normal start
beep and also starts the dashcam if the player is in a vehicle.
local ok = exports["hype-bodycam"]:SetBodycam(source, true)Prop
Type
Returns boolean: true when the change was made, false when starting was refused.
GetStreams
Returns every active stream in a table keyed by stream id. Handy for admin panels, live statistics or Discord logs.
local streams = exports["hype-bodycam"]:GetStreams()
for id, stream in pairs(streams) do
print(id, stream.type, stream.name, stream.serial)
endRead only
The table returned is the script's own table, not a copy. Read from it, never change it.
Each stream has these fields:
Prop
Type
GetViewers
Returns the server ids of players watching feeds. With an id, only the viewers of that feed; without one, everyone watching any feed.
local all = exports["hype-bodycam"]:GetViewers()
local watchers = exports["hype-bodycam"]:GetViewers("b14")Prop
Type
Returns number[]: a list of player server ids.
Events
hype-bodycam:server:streamStarted
Triggered on the server when a stream starts. stream has the fields listed under GetStreams.
AddEventHandler('hype-bodycam:server:streamStarted', function(stream)
print(('%s started recording (%s, %s)'):format(stream.name, stream.type, stream.trigger))
end)hype-bodycam:server:streamStopped
Triggered on the server when a stream ends.
AddEventHandler('hype-bodycam:server:streamStopped', function(stream, reason)
print(('%s stopped recording: %s'):format(stream.name, reason))
end)reason | Meaning |
|---|---|
off | Turned off by hand |
invalid | The player lost the item or went off duty |
dropped | The player left the server |
export | Turned off with SetBodycam |
vehicle | The vehicle is gone or wrecked |
lights | No recording officer left in the vehicle and the lights are off |
owner_* | The bodycam of the stream owner turned off |
Server only
These are local server events. Never trigger them from the client.
State bag
The server shares the stream list through a global state bag, so clients can read the same list. Its structure matches
GetStreams and it is read only.
local streams = GlobalState["hype-bodycam:streams"]