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.
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.
| Export | Side | Purpose |
|---|---|---|
Open | Client | Opens the camera list |
Close | Client | Closes the viewer and the list |
IsOpen | Client | Is the list or a camera open |
GetViewingCamera | Client | Id of the camera being watched |
SetCameraOnline | Server | Switches a camera on or off |
DestroyCamera | Server | Takes a camera offline as damaged |
IsCameraOnline | Server | Is a camera online |
GetViewers | Server | Players 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.
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.
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.
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.
local id = exports["hype-camera"]:GetViewingCamera() -- "pacific_lobby" or nilServer 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.
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.
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.
if exports["hype-camera"]:IsCameraOnline("vangelico_1") then
-- the jewelry store is being watched
endProp
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.
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.
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.
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| Value | Meaning |
|---|---|
true | Switched off with SetCameraOnline, the admin command or online = false |
number | Shot or destroyed, os.time at which it comes back |
Online cameras are not in the table.
Commands
| Command | Who | Purpose |
|---|---|---|
Command (off by default) | Allowed players | Opens the camera list, set a name such as "cameras" |
/camerastatus [id] [state] | group.admin | 1 = online, 0 = offline. The name is set in AdminCommand |
/camerapos | Everyone, Debug | Copies the position of your current view as a camera entry |
/camerastatus pacific_vault 0Bridge 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.
| Export | Side | Purpose |
|---|---|---|
GetCharacterInfo(playerId) | Server | Name, birth date, gender, nationality, phone, identifier and job label |
GetPlayerJob(playerId) | Server | Job name, label, grade and duty, used by the access check |
GetPlayer(playerId) | Server | Framework player object |
GetPlayers() | Server | Server ids of every loaded player |
GetCharacterName(playerId, split?) | Server | Character name, or first and last name with split |
GetPlayerIdentifier(playerId) | Server | citizenid on QB/QBox, identifier on ESX |
GetPlayerCallsign(playerId) | Server | Callsign from the player metadata, nil when there is none |
GetPlayerData() | Client | Framework player data of the local player |
GetPlayerJob() | Client | Job of the local player |
GetFrameworkObject() | Both | The bridge table of the current side |
AddSphereZone(name, coords, radius, options) | Client | Creates a zone through ox_target or qb-target |
RemoveZone(name) | Client | Removes 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.
exports["hype-camera"]:SendNotify("Security Cameras", "Camera feed restored.", 5000, "success")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.
local notify = exports["hype-camera"]:GetModules("Notify")
notify.SendNotify(source, "Security Cameras", "Hello!", 5000, "success")Prop
Type