Frontier Wire — Editable Files (Server)
bridge/hooks/server.lua is not escrowed: write your own rules there. Every function is optional; delete one and the postal service skips it.
resources/[frontier-forge]/frontier_mailbox/
bridge/
hooks/
server.lua ← this page
client.lua ← Editable Files (Client)Edit the functions that are already in the file; each one exists once. Back the file up before you install an update, because an update replaces it.
Not editing the resource?
Other resources do not need this file. The same moments are raised as server events, and the server exports cover lookups and sending.
Rules
- Returning nothing counts as allowed.
- If
canOpenorcanSendMailthrows an error, the action is refused and the error is printed to the server console. A broken rule is noticed instead of letting everything through. - The player waits for
canOpenandcanSendMail; keep them fast. - Restart
frontier_mailboxafter editing the file.
Hooks.canOpen(source, screen)
A player is about to open a postal screen. screen: 'player' (post office counter), 'compose' (telegram paper item), 'bird' (carrier bird item) or 'admin' (admin desk).
Return false, 'reason' to keep it closed; the reason is shown to the player.
Example: players must step down from a wagon before using the post office counter.
File: frontier_mailbox/bridge/hooks/server.lua. Replace the existing Hooks.canOpen function with this one.
function Hooks.canOpen(source, screen)
if screen == 'player' and GetVehiclePedIsIn(GetPlayerPed(source), false) ~= 0 then
return false, 'Step down from the wagon first.'
end
return true
endHooks.canSendMail(source, mail)
The player pressed Seal, Post or Send. Runs after the postal service's own checks and before anything is charged, taken or stored. Return false, 'reason' to refuse; the reason is shown to the player.
It runs up to three times in a telegram's life:
mail.stage | When | Extra fields |
|---|---|---|
'seal' | The paper is sealed | |
'post' | It is posted at a counter | cost, money, items, station |
'bird' | A bird telegram is sent | cost, money, items |
Example: no telegrams while dead, a word filter, and a cash limit for everyone except bankers.
File: frontier_mailbox/bridge/hooks/server.lua. Replace the existing Hooks.canSendMail function with this one; do not add a second copy.
local Core = exports.vorp_core:GetCore()
function Hooks.canSendMail(source, mail)
local user = Core.getUser(source)
if user and user.getUsedCharacter.isdead then return false, 'You cannot send telegrams while dead.' end
if mail.body:lower():find('badword', 1, true) then return false, 'The postmaster refuses this telegram.' end
if mail.stage == 'post' and mail.money and mail.money.amount > 100 and mail.sender.job ~= 'banker' then
return false, 'Only a banker may send more than $100.'
end
return true
endHooks.mailSent(mail)
A telegram was paid for and is on its way (stage 'post', 'bird' or 'script'). mail.deliveryIn is the number of seconds until it arrives.
function Hooks.mailSent(mail)
endHooks.mailDelivered(mail)
A telegram arrived: it waits at the post office, or its bird has landed near the addressee. mail is the short record.
function Hooks.mailDelivered(mail)
endHooks.mailRead(source, mail)
The addressee opened a telegram for the first time. mail is the short record.
function Hooks.mailRead(source, mail)
endHooks.parcelCollected(source, parcel)
The addressee took the items of a parcel. parcel = {id, items = {{name, label, amount}, ...}}.
function Hooks.parcelCollected(source, parcel)
endHooks.moneyClaimed(source, money)
Somebody took the cash out of a telegram. money = {id, amount, sealed, addressee}; addressee is false when an unsealed letter was opened by another character.
function Hooks.moneyClaimed(source, money)
endThe mail record
mail = {
id = 'FW-123', -- not yet known in canSendMail
stage = 'post', -- 'seal', 'post', 'bird' or 'script' (exports SendMail)
method = 'post', -- 'post' or 'bird'
sender = {source, name, address, identifier, characterId, job, grade},
recipient = {name, address, identifier, characterId, online, source},
subject = '...', body = '...', words = 42,
cost = 1.50, -- postage and parcel fee
money = {amount = 10, sealed = true},
items = {{name = 'bread', label = 'Bread', amount = 2}},
station = {id = 'ST-1', name = 'Valentine Post Office', town = 'Valentine'},
deliveryIn = 120, -- seconds, in mailSent
}mailDelivered and mailRead carry a short record: {id, method, subject, sender = {name, address}, recipient = {name, address, online, source}}.
