CameraNewFree

Camera: Exports & Events

Open the camera viewer, switch cameras on and off, take them down during a robbery and listen for shot cameras from your own resources.

v1.0.0Open sourceFreeQBox · QBCore · ESX

Resource name

Exports are called through the resource name, so keep the folder named hype-camera. Because the name contains a hyphen, call exports as exports["hype-camera"] rather than exports.hype-camera.

ExportSidePurpose
OpenClientOpens the camera list
CloseClientCloses the viewer and the list
IsOpenClientIs the list or a camera open
GetViewingCameraClientId of the camera being watched
SetCameraOnlineServerSwitches a camera on or off
DestroyCameraServerTakes a camera offline as damaged
IsCameraOnlineServerIs a camera online
GetViewersServerPlayers watching a camera

Camera ids

Every camera is addressed by its id from config/cameras.lua, e.g. pacific_vault, fleeca_legion or vangelico_1.

Client exports

Open

Opens the camera 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 Access first; without access the player gets an error notification and nothing opens.

client.lua
exports["hype-camera"]:Open()

Release the NUI focus first

Nothing opens while the pause menu is open, while the cameras are already open, or while another resource holds the NUI focus. Close your tablet or call SetNuiFocus(false, false) before calling Open.

Close

Closes the viewer and the list: destroys the camera, removes the picture filter, restores the radar and removes the viewer on the server. Call it when you have to pull a player out of the cameras (cuffs, a cutscene, another menu opening). While a camera is watched, death and ragdoll already close the viewer on their own.

client.lua
exports["hype-camera"]:Close()

IsOpen

Returns true while the camera list or a camera is on screen. Check it before opening your own menus to avoid overlaps.

client.lua
local open = exports["hype-camera"]:IsOpen()

GetViewingCamera

Returns the id of the camera being watched, or nil while only the list is open or nothing is watched.

client.lua
local id = exports["hype-camera"]:GetViewingCamera() -- "pacific_lobby" or nil

Server exports

SetCameraOnline

Switches a camera online or offline, for example to cut the cameras during a robbery. Players watching it see SIGNAL LOST and the list shows it as offline. A camera switched off this way stays off until you switch it on again. Switching a damaged camera on brings it back right away.

server.lua
exports["hype-camera"]:SetCameraOnline("pacific_vault", false)

Prop

Type

Returns boolean: false when the camera id does not exist.

DestroyCamera

Takes a camera offline as damaged, the same as if it was shot. Players watching it see DAMAGED with a countdown, nearby players see the sparks (with Destroy.effects), and the cameraDestroyed event is triggered. It comes back on its own when the time is up. This export works even when Destroy.enabled is false.

server.lua
exports["hype-camera"]:DestroyCamera("fleeca_legion", 300)

Prop

Type

Returns boolean: false when the camera id does not exist or the camera is already offline.

IsCameraOnline

Returns true when the camera exists and is neither switched off nor damaged.

server.lua
if exports["hype-camera"]:IsCameraOnline("vangelico_1") then
    -- the jewelry store is being watched
end

Prop

Type

GetViewers

Returns the server ids of players watching cameras. With an id, only the viewers of that camera; without one, everyone watching any camera. Players looking at the list only are not counted.

server.lua
local all = exports["hype-camera"]:GetViewers()
local watchers = exports["hype-camera"]:GetViewers("pacific_vault")

Prop

Type

Returns number[]: a list of player server ids.

Events

hype-camera:server:cameraDestroyed

Triggered on the server when a camera is shot or taken down with DestroyCamera. Use it to alert dispatch or write a log.

server.lua
AddEventHandler('hype-camera:server:cameraDestroyed', function(id, source, coords, label)
    print(('%s was shot by %s at %s'):format(label, source or 'script', coords))
end)

Prop

Type

Server only

This is a local server event. Never trigger it from the client. The other hype-camera:* events and callbacks are internal and validated on the server; do not call them yourself.

State bag

The server shares the offline cameras through a global state bag, so both sides can read the same list. It is read only.

client.lua
local offline = GlobalState["hype-camera:offline"] or {}

for id, value in pairs(offline) do
    if value == true then
        print(id, 'switched off')
    else
        print(id, 'damaged, back at', value) -- os.time
    end
end
ValueMeaning
trueSwitched off with SetCameraOnline, the admin command or online = false
numberShot or destroyed, os.time at which it comes back

Online cameras are not in the table.

Commands

CommandWhoPurpose
Command (off by default)Allowed playersOpens the camera list, set a name such as "cameras"
/camerastatus [id] [state]group.admin1 = online, 0 = offline. The name is set in AdminCommand
/cameraposEveryone, DebugCopies the position of your current view as a camera entry
/camerastatus pacific_vault 0

Bridge exports

The framework bridges in frameworks/ and the modules in modules/ are open source. If your character system is customized, change how the script reads players there. Face recognition reads its data from GetCharacterInfo.

main.lua
main.lua
ExportSidePurpose
GetCharacterInfo(playerId)ServerName, birth date, gender, nationality, phone, identifier and job label
GetPlayerJob(playerId)ServerJob name, label, grade and duty, used by the access check
GetPlayer(playerId)ServerFramework player object
GetPlayers()ServerServer ids of every loaded player
GetCharacterName(playerId, split?)ServerCharacter name, or first and last name with split
GetPlayerIdentifier(playerId)Servercitizenid on QB/QBox, identifier on ESX
GetPlayerCallsign(playerId)ServerCallsign from the player metadata, nil when there is none
GetPlayerData()ClientFramework player data of the local player
GetPlayerJob()ClientJob of the local player
GetFrameworkObject()BothThe bridge table of the current side
AddSphereZone(name, coords, radius, options)ClientCreates a zone through ox_target or qb-target
RemoveZone(name)ClientRemoves a zone created with AddSphereZone

SendNotify

Shows a notification with the resource set in Notifications (okokNotify, ps-ui or ox_lib). On the server, the first argument is the player; pass -1 to notify everyone.

client.lua
exports["hype-camera"]:SendNotify("Security Cameras", "Camera feed restored.", 5000, "success")
server.lua
exports["hype-camera"]:SendNotify(source, "Security Cameras", "The bank cameras are down!", 5000, "error")

Prop

Type

GetModules

Returns the module table of the side it is called on. With a name, only that module: "Notify" on both sides, "Target" on the client.

server.lua
local notify = exports["hype-camera"]:GetModules("Notify")
notify.SendNotify(source, "Security Cameras", "Hello!", 5000, "success")

Prop

Type

On this page