BodycamNewFree

Bodycam: Exports & Events

Read and control bodycams, open the viewer and listen to stream events from your own resources.

v1.0.0Open sourceFreeQBox · QBCore · ESX

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.

ExportSidePurpose
IsBodycamOnClientIs the local player's bodycam recording
OpenClientOpens the feed list
CloseClientCloses the viewer and the list
IsOpenClientIs the viewer open
GetViewingStreamClientId of the feed being watched
bodycamClientox_inventory item use, not called by hand
IsBodycamActiveServerIs a player's bodycam recording
SetBodycamServerTurns a player's bodycam on or off
GetStreamsServerEvery active stream
GetViewersServerPlayers 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.

client.lua
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.

client.lua
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).

client.lua
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.

client.lua
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.

client.lua
local id = exports["hype-bodycam"]:GetViewingStream() -- "b14", "d2188" or nil

bodycam

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.

server.lua
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.

server.lua
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.

server.lua
local streams = exports["hype-bodycam"]:GetStreams()

for id, stream in pairs(streams) do
    print(id, stream.type, stream.name, stream.serial)
end

Read 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.

server.lua
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.

server.lua
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.

server.lua
AddEventHandler('hype-bodycam:server:streamStopped', function(stream, reason)
    print(('%s stopped recording: %s'):format(stream.name, reason))
end)
reasonMeaning
offTurned off by hand
invalidThe player lost the item or went off duty
droppedThe player left the server
exportTurned off with SetBodycam
vehicleThe vehicle is gone or wrecked
lightsNo 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.

client.lua
local streams = GlobalState["hype-bodycam:streams"]

On this page