Server Exports
Hacking
RunHack
Run a hacking minigame on a player from the server and get a verified result. The simplest way to put a hack in front of something: the server asks the player's client to play, and redeems the proof itself.
Syntax
local won = exports['sd-computers']:RunHack(source, game, difficulty)| Parameter | Type | Description |
|---|---|---|
source | number | The player's server id |
game | string | A minigame key: maze, capture, cipher, snake, firewall, evasion, typing, signal, pipe, breakout |
difficulty | string? | 'easy', 'medium' or 'hard'. Default DefaultDifficulty ('medium') |
Yields until the player wins, loses or quits. Returns true only for a verified win at that game and difficulty, and false straight away if that player already has a hack window open. A run is not tied to a place, so check where the player is yourself. See Hacks in Your Scripts for the ways to put a hack into a robbery.
Example
if exports['sd-computers']:RunHack(source, 'maze', 'hard') then
-- open the door
endConsumeHackProof
Redeem the proof a client got from StartHack. One-shot: a proof works once, only for the player who played it, and expires after ProofTTL (120 seconds).
Syntax
local info = exports['sd-computers']:ConsumeHackProof(source, proof, expect)| Parameter | Type | Description |
|---|---|---|
source | number | The player who played it |
proof | string | What StartHack returned on the client |
expect | table? | { game?, difficulty? }: insist on that game, and at least that difficulty |
Returns { game, difficulty, elapsed } for a good proof, or false.
Example
local info = exports['sd-computers']:ConsumeHackProof(source, proof, { game = 'pipe', difficulty = 'medium' })
if info then
print(('won %s on %s in %.1fs'):format(info.game, info.difficulty, info.elapsed))
endSystem Logs
AddLog
Write an entry to a computer's System Logs (Event Viewer), e.g. a door script logging "Vault door opened" to the security office's PC.
Syntax
exports['sd-computers']:AddLog(computer, level, source, message, data)| Parameter | Type | Description |
|---|---|---|
computer | string | A computer's id (a location computer, or a placed one: placed_<n>), or '<id>@x,y,z' for one prop of a model computer |
level | string | 'information', 'warning', 'error', 'success' or 'failure' |
source | string? | The Source column, e.g. your resource's name. Default: the resource calling it |
message | string | The entry (512 characters at most) |
data | table? | Extra details, shown in the entry's detail pane |
Example
exports['sd-computers']:AddLog('mrpd_frontdesk', 'warning', 'sd-doors', 'Evidence locker opened', { by = 'Officer Hale' })Mail
While the sd-phone link has Mail on, these work on the phone's mailboxes (the ones players actually read) instead of the built-in ones.
SendMail
Send a system or NPC mail: job offers, statements, heist intel. No sent copy is kept and nothing bounces.
Syntax
local result = exports['sd-computers']:SendMail(data)| Field | Type | Description |
|---|---|---|
to | string | string[] | One address, several separated by commas, or a list (20 at most). An address with no @ gets @lsmail.com (Domain) |
subject | string? | 200 characters at most |
body | string? | 10,000 characters at most |
from | table? | { name, email }. email with no @ gets the domain. Default: System, no-reply@lsmail.com |
Returns { success = boolean, delivered = string[] }: the addresses it reached.
Example
exports['sd-computers']:SendMail({
to = 'jessica.hale@lsmail.com',
subject = 'Shift starts',
body = 'See you at 8.',
from = { name = 'LSPD HR', email = 'hr' },
})MailAddressExists
Syntax
local exists = exports['sd-computers']:MailAddressExists(email)Returns true when the address exists.
GetMailAddresses
The addresses a character is signed into, e.g. to mail them a reward.
Syntax
local addresses = exports['sd-computers']:GetMailAddresses(citizenid)Returns a list of addresses (string[]).
Computers
AddComputer
Add a computer from your resource: a desk in a player's house, a laptop a heist leaves on a table, a terminal in your MLO. It is a computer like any other, with the "Use Computer" option, the screen on its prop, System Logs, a PIN, a job lock, the Business Manager, and breach targets keyed by its id.
Syntax
local ok, err = exports['sd-computers']:AddComputer(computer)| Field | Type | Description |
|---|---|---|
id | string | Unique: letters, digits, _ and -, 64 at most. What the other exports, the System Logs and breach targets call it |
label | string | Its name, on the target option and in the OS |
coords | vector3 | vector4 | Where it is. A vector4's w is the heading |
heading | number? | The heading, when coords is a vector3 |
prop | string? | A prop model to stand there, e.g. 'prop_laptop_01a'. Left out, the computer is a target box at coords, like a location computer, and its screen is the monitor standing in that box |
world | boolean? | true = prop already stands there (part of the map or your MLO): nothing is spawned, and that prop becomes the computer |
size | vector3? | The target box, when there is no prop. Default vec3(0.8, 0.8, 0.8) |
style | string? | 'modern', 'retro' or 'mac'. Default Desktop.DefaultStyle |
groups | table | string? | Job/gang lock: { police = 0, sheriff = 2 } (name = minimum grade), one job name, or a list of names |
owners | string[]? | The citizenids that may use it, e.g. a house's owner and keyholders. An empty list lets nobody in |
pin | string? | A PIN on its lock screen: letters and digits, 16 at most. It never leaves the server |
boss | string | boolean? | Business Manager: a job name, or true for whatever job the signed-in player has |
apps | string[]? | Its apps (ids from Desktop.Apps). Default Desktop.DefaultApps |
hostname | string? | Its machine name in Command Prompt and the logs. Default: made from label |
board, cameras, photos, phone | boolean? | false turns that off on it, as in computers.lua |
Returns true, or false and why. A refusal is printed in the server console too.
The server checks reach, groups, owners and the PIN when it opens and on every action, as for any computer. With both groups and owners set, a player has to pass both. groups also hides the target option from everyone else; owners does not, so anyone can try it and is told "Access denied".
Calling it again with the same id replaces your computer. Whoever is using it is asked to open it again if it moved or its apps changed. The computer belongs to your resource: only your resource can change or remove it, and it goes away when your resource stops. It is kept in memory, not in the database, so add your computers when your resource starts and on sd-computers:ready, because a restart of sd-computers forgets them. Do not put dependency 'sd-computers' in your manifest: see Custom Apps > When to register.
Example
local function addComputers()
for _, house in pairs(Houses) do
if house.computer then
exports['sd-computers']:AddComputer({
id = ('house_%s_pc'):format(house.id),
label = 'Home Office',
coords = house.computer.coords, -- vector4
prop = 'prop_laptop_01a',
style = 'mac',
owners = house.keyholders, -- citizenids
pin = house.computer.pin,
})
end
end
end
AddEventHandler('sd-computers:ready', addComputers) -- sd-computers (re)started after you
CreateThread(addComputers) -- you started after sd-computersThe admin panel lists these computers as Script, with the resource that added them. It can go to them, but not change them.
UpdateComputer
Change part of a computer your resource added: a new keyholder, another spot, a new PIN. Only the fields you pass change, and false clears an optional one. Taking a player off owners closes the computer on them at their next action.
Syntax
local ok, err = exports['sd-computers']:UpdateComputer(id, changes)| Parameter | Type | Description |
|---|---|---|
id | string | The computer's id |
changes | table | Any of the AddComputer fields but id |
Returns true, or false and why.
Example
exports['sd-computers']:UpdateComputer('house_12_pc', { owners = { 'ABC12345', 'XYZ98765' } })
exports['sd-computers']:UpdateComputer('house_12_pc', { pin = false }) -- no PIN any moreRemoveComputer
Take away a computer your resource added. Whoever is using it is signed out.
Syntax
local ok, err = exports['sd-computers']:RemoveComputer(id)Returns true, or false and why.
GetComputers
Every computer: the ones from the config, the ones made in the admin panel and the ones resources added. A config computer an admin removed in the panel is left out.
Syntax
local computers = exports['sd-computers']:GetComputers()Returns a list of:
| Field | Type | Description |
|---|---|---|
id | string | The computer's id (placed_<n> for one from the panel) |
label | string | Its name |
hostname | string | Its machine name |
coords | vector3? | A location computer's, a placed computer's or an added computer's position |
model | string | string[]? | A model computer's prop model(s) |
placed | boolean? | true = made in the admin panel |
prop | string? | The prop a placed or added computer is |
world | boolean? | true = a prop the game already had there |
resource | string? | The resource that added it with AddComputer |
GetComputer
One computer, with the same fields as GetComputers.
Syntax
local computer = exports['sd-computers']:GetComputer(id)Returns the computer, or nil for an unknown id or one an admin removed in the panel.
GetComputerUsers
Who is at a computer right now, signed in or still at its lock screen.
Syntax
local users = exports['sd-computers']:GetComputerUsers(id)| Parameter | Type | Description |
|---|---|---|
id | string | A computer's id. For a model computer that is every prop of it; '<id>@x,y,z' is one prop |
Returns a list of { source, citizenid, name, instance, signedIn }.
OpenComputer
Open a computer for a player from the server: a laptop item's use, a scripted scene. It is the client OpenComputer, asked of that player's client, so the server still checks reach, the job lock, owners and the PIN as it does at the desk.
Syntax
local sent = exports['sd-computers']:OpenComputer(source, id, opts)| Parameter | Type | Description |
|---|---|---|
source | number | The player's server id |
id | string | Any computer's id |
opts | table? | { coords?, style? }. coords: a model computer's prop (default: where the player stands). style: 'modern', 'retro' or 'mac' for this open |
Returns true once it is sent, false for an unknown player or computer. computerOpened fires when it has opened.
Example
-- a laptop item: the business laptop opens where the player stands
exports['sd-computers']:OpenComputer(source, 'business_laptop', { style = 'retro' })CloseComputer
Close a player's computer, or everyone's at one computer: a house locked, a player cuffed. Each is signed out and logged off as if they shut it down.
Syntax
local closed = exports['sd-computers']:CloseComputer(target, message)| Parameter | Type | Description |
|---|---|---|
target | number | string | A player's server id, or a computer's id (everyone at it; '<id>@x,y,z' for one prop) |
message | string? | Shown to them. Left out, it closes without one |
Returns how many computers it closed.
Example
exports['sd-computers']:CloseComputer('house_12_pc', 'The house was locked.')Files
AddFile
Put a plain-text document into a character's Files: heist intel, a report, a letter. It is there on every computer they sign into.
Syntax
local id, name = exports['sd-computers']:AddFile(target, file)| Parameter | Type | Description |
|---|---|---|
target | string | number | A citizenid, or an online player's server id |
file | table | { name?, body }. A name already in use gets a number after it (Intel (2)); none is Untitled. body is cut at MaxBody (20,000 characters) |
Returns the document's id and the name it was saved under, or false and why: 'no_character', 'bad_file', 'full' (MaxFiles, 100 documents) or 'failed'.
Example
exports['sd-computers']:AddFile(source, {
name = 'Pacific Standard - floor plan',
body = 'Vault: basement, east stairwell.\nGuard change: 02:00.',
})Printing
A page is a table. Only title is required, plus something under it (body, fields, table or image):
| Field | Type | Description |
|---|---|---|
title | string | The page's title (120 characters) |
kind | string? | The paper it is on: 'mail', 'statement' (letterhead), 'logs' (green-bar listing paper). Default 'custom', plain paper |
letterhead | string? | A letterhead line across the top |
subhead | string? | A line under the title |
fields | table? | { { label, value } }, up to 24 rows |
body | string? | The text (MaxChars, 20,000 by default) |
table | table? | { head = { ... }, rows = { { ... } } }, up to 8 columns and 200 rows |
image | string? | A picture address (https://...) |
footer | string? | A line at the bottom |
GetPrinters
Syntax
local printers = exports['sd-computers']:GetPrinters()Returns { id, label, coords }[], every printer, by id.
PrintAt
Print a page at a printer. It waits in the tray like any other print.
Syntax
local ok, why = exports['sd-computers']:PrintAt(printerId, page, opts)| Parameter | Type | Description |
|---|---|---|
printerId | number | A printer's id, from GetPrinters |
page | table | The page (above) |
opts | table? | { copies?, by?, from?, citizenid? }: how many, and who and which machine the tooltip says printed it |
Returns true, or false and why: 'disabled', 'no_printer', 'bad_page', 'tray_full' or 'failed'.
GivePrintout
Put a printed page straight into a player's inventory, with no printer in between.
Syntax
local ok, why = exports['sd-computers']:GivePrintout(source, page, opts)| Parameter | Type | Description |
|---|---|---|
source | number | The player's server id |
page | table | The page (above) |
opts | table? | { copies?, by?, from? }. by defaults to the player's name |
Returns true, or false and why: 'disabled', 'bad_page', 'inventory_full' or 'failed'.
Example
exports['sd-computers']:GivePrintout(source, {
title = 'Vehicle Release',
letterhead = 'Los Santos Police Department',
fields = {
{ label = 'Plate', value = '46EEK572' },
{ label = 'Released to', value = 'Jessica Hale' },
},
body = 'This vehicle may be collected from the Mission Row impound lot.',
footer = 'Form LSPD-114',
}, { by = 'Officer Hale', from = 'Records' })Custom Apps
Registering your own programs on the desktop and talking to them: AddCustomApp, RemoveCustomApp, GetCustomApps, SendAppMessage, NotifyApp, SetAppBadge, OpenApp, CloseApp, GetAppUsers, HasApp, GetComputerSession and RefreshApps, and the sd-computers:ready event to register on. They have a page of their own: Custom Apps.
Events
breachCompleted
Fired on the server after every successful breach, once the reward is paid. Each target can also name an event of its own (reward.event), fired with the same arguments.
AddEventHandler('sd-computers:server:breachCompleted', function(source, info)
-- info = { target = 'fleeca_ledger', computer = 'public_pc', instance = 'public_pc@123,-456,30' }
end)| Field | Description |
|---|---|
info.target | The target's id |
info.computer | The computer's id |
info.instance | The exact computer: for a model computer, '<id>@x,y,z' of the prop |
Computer events
Fired on the server as players use computers: for a quest step, a log of your own, an anti-cheat check.
AddEventHandler('sd-computers:server:computerOpened', function(source, info) end)
AddEventHandler('sd-computers:server:computerSignedIn', function(source, info) end)
AddEventHandler('sd-computers:server:computerClosed', function(source, info) end)| Event | When |
|---|---|
computerOpened | A player opened a computer: it is at its lock screen |
computerSignedIn | They got past the lock screen (and its PIN, when it has one) |
computerClosed | Their session ended, however: shut down, walked away, closed by a script, left the server |
info is { computer, instance, citizenid }: the computer's id, the exact computer ('<id>@x,y,z' for a prop of a model computer) and the player's citizenid.
These are server events: listen with AddEventHandler, not RegisterNetEvent, so a client cannot fake them.
