Skip to content

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.

text
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 canOpen or canSendMail throws 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 canOpen and canSendMail; keep them fast.
  • Restart frontier_mailbox after 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.

lua
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
end
Hooks.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.stageWhenExtra fields
'seal'The paper is sealed
'post'It is posted at a countercost, money, items, station
'bird'A bird telegram is sentcost, 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.

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

lua
function Hooks.mailSent(mail)
end
Hooks.mailDelivered(mail)

A telegram arrived: it waits at the post office, or its bird has landed near the addressee. mail is the short record.

lua
function Hooks.mailDelivered(mail)
end
Hooks.mailRead(source, mail)

The addressee opened a telegram for the first time. mail is the short record.

lua
function Hooks.mailRead(source, mail)
end
Hooks.parcelCollected(source, parcel)

The addressee took the items of a parcel. parcel = {id, items = {{name, label, amount}, ...}}.

lua
function Hooks.parcelCollected(source, parcel)
end
Hooks.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.

lua
function Hooks.moneyClaimed(source, money)
end

The mail record ​

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

Frontier Forge — RedM documentation for VORP.