Skip to content

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

lua
local won = exports['sd-computers']:RunHack(source, game, difficulty)
ParameterTypeDescription
sourcenumberThe player's server id
gamestringA minigame key: maze, capture, cipher, snake, firewall, evasion, typing, signal, pipe, breakout
difficultystring?'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

lua
if exports['sd-computers']:RunHack(source, 'maze', 'hard') then
    -- open the door
end

ConsumeHackProof ​

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

lua
local info = exports['sd-computers']:ConsumeHackProof(source, proof, expect)
ParameterTypeDescription
sourcenumberThe player who played it
proofstringWhat StartHack returned on the client
expecttable?{ game?, difficulty? }: insist on that game, and at least that difficulty

Returns { game, difficulty, elapsed } for a good proof, or false.

Example

lua
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))
end

System 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

lua
exports['sd-computers']:AddLog(computer, level, source, message, data)
ParameterTypeDescription
computerstringA computer's id (a location computer, or a placed one: placed_<n>), or '<id>@x,y,z' for one prop of a model computer
levelstring'information', 'warning', 'error', 'success' or 'failure'
sourcestring?The Source column, e.g. your resource's name. Default: the resource calling it
messagestringThe entry (512 characters at most)
datatable?Extra details, shown in the entry's detail pane

Example

lua
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

lua
local result = exports['sd-computers']:SendMail(data)
FieldTypeDescription
tostring | string[]One address, several separated by commas, or a list (20 at most). An address with no @ gets @lsmail.com (Domain)
subjectstring?200 characters at most
bodystring?10,000 characters at most
fromtable?{ name, email }. email with no @ gets the domain. Default: System, no-reply@lsmail.com

Returns { success = boolean, delivered = string[] }: the addresses it reached.

Example

lua
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

lua
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

lua
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

lua
local ok, err = exports['sd-computers']:AddComputer(computer)
FieldTypeDescription
idstringUnique: letters, digits, _ and -, 64 at most. What the other exports, the System Logs and breach targets call it
labelstringIts name, on the target option and in the OS
coordsvector3 | vector4Where it is. A vector4's w is the heading
headingnumber?The heading, when coords is a vector3
propstring?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
worldboolean?true = prop already stands there (part of the map or your MLO): nothing is spawned, and that prop becomes the computer
sizevector3?The target box, when there is no prop. Default vec3(0.8, 0.8, 0.8)
stylestring?'modern', 'retro' or 'mac'. Default Desktop.DefaultStyle
groupstable | string?Job/gang lock: { police = 0, sheriff = 2 } (name = minimum grade), one job name, or a list of names
ownersstring[]?The citizenids that may use it, e.g. a house's owner and keyholders. An empty list lets nobody in
pinstring?A PIN on its lock screen: letters and digits, 16 at most. It never leaves the server
bossstring | boolean?Business Manager: a job name, or true for whatever job the signed-in player has
appsstring[]?Its apps (ids from Desktop.Apps). Default Desktop.DefaultApps
hostnamestring?Its machine name in Command Prompt and the logs. Default: made from label
board, cameras, photos, phoneboolean?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

lua
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-computers

The 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

lua
local ok, err = exports['sd-computers']:UpdateComputer(id, changes)
ParameterTypeDescription
idstringThe computer's id
changestableAny of the AddComputer fields but id

Returns true, or false and why.

Example

lua
exports['sd-computers']:UpdateComputer('house_12_pc', { owners = { 'ABC12345', 'XYZ98765' } })
exports['sd-computers']:UpdateComputer('house_12_pc', { pin = false }) -- no PIN any more

RemoveComputer ​

Take away a computer your resource added. Whoever is using it is signed out.

Syntax

lua
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

lua
local computers = exports['sd-computers']:GetComputers()

Returns a list of:

FieldTypeDescription
idstringThe computer's id (placed_<n> for one from the panel)
labelstringIts name
hostnamestringIts machine name
coordsvector3?A location computer's, a placed computer's or an added computer's position
modelstring | string[]?A model computer's prop model(s)
placedboolean?true = made in the admin panel
propstring?The prop a placed or added computer is
worldboolean?true = a prop the game already had there
resourcestring?The resource that added it with AddComputer

GetComputer ​

One computer, with the same fields as GetComputers.

Syntax

lua
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

lua
local users = exports['sd-computers']:GetComputerUsers(id)
ParameterTypeDescription
idstringA 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

lua
local sent = exports['sd-computers']:OpenComputer(source, id, opts)
ParameterTypeDescription
sourcenumberThe player's server id
idstringAny computer's id
optstable?{ 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

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

lua
local closed = exports['sd-computers']:CloseComputer(target, message)
ParameterTypeDescription
targetnumber | stringA player's server id, or a computer's id (everyone at it; '<id>@x,y,z' for one prop)
messagestring?Shown to them. Left out, it closes without one

Returns how many computers it closed.

Example

lua
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

lua
local id, name = exports['sd-computers']:AddFile(target, file)
ParameterTypeDescription
targetstring | numberA citizenid, or an online player's server id
filetable{ 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

lua
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):

FieldTypeDescription
titlestringThe page's title (120 characters)
kindstring?The paper it is on: 'mail', 'statement' (letterhead), 'logs' (green-bar listing paper). Default 'custom', plain paper
letterheadstring?A letterhead line across the top
subheadstring?A line under the title
fieldstable?{ { label, value } }, up to 24 rows
bodystring?The text (MaxChars, 20,000 by default)
tabletable?{ head = { ... }, rows = { { ... } } }, up to 8 columns and 200 rows
imagestring?A picture address (https://...)
footerstring?A line at the bottom

GetPrinters ​

Syntax

lua
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

lua
local ok, why = exports['sd-computers']:PrintAt(printerId, page, opts)
ParameterTypeDescription
printerIdnumberA printer's id, from GetPrinters
pagetableThe page (above)
optstable?{ 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

lua
local ok, why = exports['sd-computers']:GivePrintout(source, page, opts)
ParameterTypeDescription
sourcenumberThe player's server id
pagetableThe page (above)
optstable?{ copies?, by?, from? }. by defaults to the player's name

Returns true, or false and why: 'disabled', 'bad_page', 'inventory_full' or 'failed'.

Example

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

lua
AddEventHandler('sd-computers:server:breachCompleted', function(source, info)
    -- info = { target = 'fleeca_ledger', computer = 'public_pc', instance = 'public_pc@123,-456,30' }
end)
FieldDescription
info.targetThe target's id
info.computerThe computer's id
info.instanceThe 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.

lua
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)
EventWhen
computerOpenedA player opened a computer: it is at its lock screen
computerSignedInThey got past the lock screen (and its PIN, when it has one)
computerClosedTheir 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.