Frontier Wire — Server Exports & Events
Everything here is for other resources. Mail sent through the API costs nothing and takes no item; it is a trusted, server-side call.
- The exports never throw. A lookup returns
nilplus a reason;SendMailreturnsok = falsepluserror. - They wait for the database, so call them from a thread or an event handler.
- Player rate limits do not apply to exports. When sending to many characters, pace the calls (for example 20 per second).
Naming a mailbox: the target
Every export that needs a character accepts a target:
| Target | Example | Meaning |
|---|---|---|
| Server id | 12 or '12' | The character that player is using now. Creates the mailbox if they have none yet |
| Mailbox address | 'FW-000123' | Works for online and offline characters |
| Account identifier | 'steam:110000112345678', 'license:abc...' | VORP identifier or licence. For an online player also discord:, fivem: and other identifier types |
| Table | {source = 12}, {address = 'FW-000123'}, {identifier = 'steam:...', characterId = '7'}, {characterId = '7'}, {license = 'license:...'} | The explicit form |
- A number, or a string of digits only, is always a server id. Pass a character id as
{characterId = ...}. - An account with several characters resolves to the one in the world now. If none is online, pass
characterIdtoo, or useGetMailboxes. - An offline character has a mailbox only after they were in the world once with this resource running.
Exports
GetMailbox(target)
local mailbox, reason = exports.frontier_mailbox:GetMailbox(target)Returns {address, name, identifier, characterId, online, source} or nil, reason. source is the server id while that character is in the world.
GetMailboxAddress(target)
local address, reason = exports.frontier_mailbox:GetMailboxAddress(target) -- 'FW-000123' or nil, reasonGetMailboxes(identifier)
local list = exports.frontier_mailbox:GetMailboxes('steam:110000112345678')Every character mailbox of an account.
GetUnreadCount(target)
local unread, reason = exports.frontier_mailbox:GetUnreadCount(target) -- number or nil, reasonGetMail(id)
local mail, reason = exports.frontier_mailbox:GetMail('FW-123')Returns the whole telegram:
{id, from, fromAddress, to, toAddress, subject, body, method, status, read, date, fee, signature, seal, office, parcel, money}| Field | Meaning |
|---|---|
status | 'in-transit' or 'delivered' |
parcel | {items = {{name, label, amount}}, count, weight, state} |
money | {amount, sealed, state} |
state | 'waiting' until taken |
office | true for mail sent by a script from an office that is not a mailbox |
SendMail(mail)
local result = exports.frontier_mailbox:SendMail({
to = target, -- required
body = 'Text of the letter', -- required, up to 14000 characters
subject = 'Subject', -- default 'Telegram' (up to 100 characters)
from = 'Valentine Bank', -- the office it comes from; or {name = , address = }
sender = target, -- instead of from: the telegram comes from that character
method = 'post', -- 'post' (default) or 'bird'
delay = 0, -- seconds on the way
signed = true, -- false leaves the letter unsigned
seal = {name = 'Valentine Bank', color = '#27344f', emblem = 'coin', official = true},
money = 25.50, -- or {amount = 25.50, sealed = true}
items = {{name = 'bread', amount = 2}},
})
-- result = {ok = true, id = 'FW-123', address = 'FW-000123', method = 'post', deliveryIn = 0}
-- or {ok = false, error = 'reason'}| Field | Default when missing | Notes |
|---|---|---|
to | required | Any target |
body | required | No word limit for scripts |
subject | 'Telegram' | |
from | name 'Frontier Wire', address <prefix>-OFFICE | An office is not a mailbox: the reader shows no Reply button |
sender | not used | When set, from is ignored and the telegram can be answered |
method | 'post' | 'post' waits at every post office. 'bird' brings a bird to the addressee; it becomes 'post' when birds are turned off |
delay | 0 (post), flight time (bird) | 0 to 2592000 seconds |
signed | true | Signed with the sender's name |
seal | no seal | color default #7a2f25, emblem default wire, official default true |
money | none | Created for the telegram; nobody is charged. sealed default true (only the addressee takes it) |
items | none | 1 to 20 different items, created for the telegram. Unknown item names are refused. Only the addressee collects |
Emblems: wire, feather, bird, station, mail, star, cross, scales, coin, book, lock and your own from Config.Emblems.
A telegram is stored in one transaction and delivered by the same worker as player mail, within about a second of its time. The addressee gets the usual arrival notice, unread count and, for a bird, the bird.
Other server exports
| Export | Returns |
|---|---|
GetBridge(kind) | The selected adapter: 'framework', 'inventory' or 'notify' |
GetPerformanceStats() | {active, pageActive, peak, accepted, rejected} since the resource started |
GetUncertainOperations(page) | Interrupted operations, 25 per page |
ResolveUncertainOperation(id, outcome, note) | Same as the console command telegramresolve |
Server events
The same moments the server hooks see are raised as local server events, so another resource needs no edit of this one. Listen with AddEventHandler; a client cannot fake them. Do not use RegisterNetEvent for them.
| Event | Arguments |
|---|---|
frontier_mailbox:mailSent | mail |
frontier_mailbox:mailDelivered | mail (short record) |
frontier_mailbox:mailRead | source, mail (short record) |
frontier_mailbox:parcelCollected | source, {id, items} |
frontier_mailbox:moneyClaimed | source, {id, amount, sealed, addressee} |
The short record is {id, method, subject, sender = {name, address}, recipient = {name, address, online, source}}. Events never carry the letter text; use GetMail(mail.id) when you need it.
Where to put this code
All examples on this page are server-side Lua and go in Frontier Wire's own open hooks file:
resources/[frontier-forge]/frontier_mailbox/
bridge/
hooks/
server.lua ← paste the examples at the bottom of this file- Paste below the existing
Hooksfunctions. Where an example uses a hook (Hooks.mailDelivered,Hooks.mailRead, ...), replace the empty function already in the file instead of adding a second one. - The file is loaded by Frontier Wire itself, so nothing else is needed: no new resource, no
server.cfgline. Restartfrontier_mailboxafter saving. - Never paste into
frontier_mailbox/server/orfrontier_mailbox/client/: those files are escrowed. - An update replaces
bridge/hooks/server.lua. Back it up before installing an update and copy your code back afterwards.
Examples
A welcome letter with a gift, the first time a character loads
File: frontier_mailbox/bridge/hooks/server.lua, at the bottom.
-- Welcome letter with $5 and two bread, sent once per character.
AddEventHandler('vorp:SelectedCharacter', function(source)
SetTimeout(5000, function()
local mailbox = exports.frontier_mailbox:GetMailbox(source)
if not mailbox then return end
if GetResourceKvpInt('welcomed:' .. mailbox.address) == 1 then return end
local result = exports.frontier_mailbox:SendMail({
to = source,
from = 'Mayor of Valentine',
subject = 'Welcome to town',
body = 'Dear ' .. mailbox.name .. ',\n\nwelcome. A little something to start with is enclosed.',
money = 5,
items = {{name = 'bread', amount = 2}},
})
if result.ok then SetResourceKvpInt('welcomed:' .. mailbox.address, 1) else print(result.error) end
end)
end)bread must exist in your VORP items table. The "already welcomed" mark is kept per mailbox address in the resource's KVP store.
Tell the addressee in a notice when a telegram arrives
File: frontier_mailbox/bridge/hooks/server.lua. Replace the empty Hooks.mailDelivered function with this one.
function Hooks.mailDelivered(mail)
if not mail.recipient.online then return end
-- vorp:TipRight is VORP's own notice (vorp_core/client/notifications.lua)
TriggerClientEvent('vorp:TipRight', mail.recipient.source, 'A telegram from ' .. mail.sender.name .. ' has arrived', 5000)
endPrint in the console when a summons is read
File: frontier_mailbox/bridge/hooks/server.lua. Replace the empty Hooks.mailRead function with this one.
function Hooks.mailRead(source, mail)
if mail.sender.address == 'SDPD' then
print(mail.recipient.name .. ' has read their summons')
end
endA letter from one character to another, as if they wrote it
File: frontier_mailbox/bridge/hooks/server.lua, at the bottom. /remind <text> sends the player's own character a reminder letter that can be answered.
RegisterCommand('remind', function(source, args)
if source == 0 then return end
exports.frontier_mailbox:SendMail({
to = source,
sender = source,
subject = 'Reminder',
body = table.concat(args, ' '),
})
end, false)Find a mailbox from the server console
File: frontier_mailbox/bridge/hooks/server.lua, at the bottom. Type mailbox 12 (a server id), mailbox FW-000123 or mailbox steam:... in the server console. The true makes it a restricted command, so players cannot use it.
RegisterCommand('mailbox', function(source, args)
local mailbox, reason = exports.frontier_mailbox:GetMailbox(args[1])
print(mailbox and (mailbox.name .. ': ' .. mailbox.address) or reason)
end, true)VORP paychecks by carrier bird
VORP pays job wages in vorp_paycheck, not in vorp_core. It adds the money straight to the character's pocket every minute (for example $0.20 a minute for a rank 0 sheriff, set in vorp_paycheck/config.lua). A bird every minute would bury players in telegrams, so the change below saves the wages up and sends one sealed telegram by bird every 60 paid minutes.
File and lines to replace
resources/[VORP]/vorp_paycheck/
server/
main.lua ← replace function Paycheck:Pay (lines 30-41) and Paycheck:Destroy (lines 58-61)vorp_paycheck is VORP's own open resource and the only place wages are paid. Back the file up first; a vorp_paycheck update replaces it.
Original (vorp_paycheck/server/main.lua, lines 30-41):
function Paycheck:Pay()
local isInSession <const> = Player(self.source).state.IsInSession
if not isInSession then return end
if self.IsOnDuty and not paycheck[self.source] then return end
local user <const> = Core.getUser(self.source)
if not user then return end
local character <const> = user.getUsedCharacter
character.addCurrency(0, self.amount)
endReplace with:
local WAGE_LETTER_MINUTES <const> = 60 -- one wage telegram per this many paid minutes
-- Sends the saved-up wages as one sealed telegram by carrier bird.
function Paycheck:SendWages()
local wages <const> = math.floor((self.owed or 0) * 100 + 0.5) / 100
self.owed, self.minutes = 0, 0
if wages < 0.01 or not self.mailbox then return end
local result <const> = exports.frontier_mailbox:SendMail({
to = self.mailbox,
from = 'Paymaster',
subject = 'Your wages',
body = ('Enclosed are your wages: $%.2f.'):format(wages),
method = 'bird',
money = {amount = wages, sealed = true},
})
if result.ok then return end
print(('[vorp_paycheck] wage telegram failed (%s), paying directly'):format(result.error))
local user <const> = Core.getUser(self.source)
if user then user.getUsedCharacter.addCurrency(0, wages) end
end
function Paycheck:Pay()
local isInSession <const> = Player(self.source).state.IsInSession
if not isInSession then return end
if self.IsOnDuty and not paycheck[self.source] then return end
local user <const> = Core.getUser(self.source)
if not user then return end
local character <const> = user.getUsedCharacter
-- Frontier Wire not running: pay into the pocket as VORP normally does.
if GetResourceState('frontier_mailbox') ~= 'started' then
return character.addCurrency(0, self.amount)
end
-- Remember the character, so wages still arrive after a logout (they wait at the post office).
self.mailbox = {identifier = character.identifier, characterId = tostring(character.charIdentifier)}
self.owed = (self.owed or 0) + self.amount
self.minutes = (self.minutes or 0) + 1
if self.minutes >= WAGE_LETTER_MINUTES then self:SendWages() end
endOriginal (vorp_paycheck/server/main.lua, lines 58-61):
function Paycheck:Destroy()
self.paused = true
self = nil
endReplace with (sends what was earned so far when the player leaves or loses the job, so no wages are lost):
function Paycheck:Destroy()
self.paused = true
if (self.owed or 0) > 0 then
CreateThread(function() self:SendWages() end)
end
endThen restart vorp_paycheck.
How it behaves
| Situation | Result |
|---|---|
| On duty for 60 minutes | One bird arrives with the sum of those 60 minutes, sealed: only that character can take the cash |
| Player logs out, switches character or loses the job | The wages earned so far are sent at once; an offline character finds them at any post office |
| Frontier Wire stopped, or sending fails | The wages are paid into the pocket as before, so nothing is lost |
Group pay (Config.Groups) | Uses the same Pay function, so it also arrives by bird |
- Change
WAGE_LETTER_MINUTESfor more or fewer telegrams (for example30). - To send wages to the post office instead of by bird, change
method = 'bird'tomethod = 'post'. - Add a wax seal to the letter with
seal = {name = 'Paymaster', color = '#27344f', emblem = 'coin'}. - Frontier Wire carries cash (dollars) only. Like the original
vorp_paycheck, this pays in dollars.
