Connecting: deferrals, adaptive cards, queues, whitelists and join links
Between the click and the loading screen, the server can hold a player, report progress, ask questions on a card, check a whitelist or put them in a queue. All of it runs through deferrals, and one short link gets the player to that point from anywhere.
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local src = source
deferrals.defer()
Wait(0)
deferrals.update(('Checking your whitelist, %s…'):format(name))
local license = GetPlayerIdentifierByType(src, 'license')
if not license or not IsWhitelisted(license) then
return deferrals.done('Not whitelisted — apply on discord.gg/example')
end
deferrals.handover({ name = name })
deferrals.done()
end)| Call | Does |
|---|---|
deferrals.defer() | Hold the connection (then wait at least one tick) |
deferrals.update(text) | Show a progress message |
deferrals.presentCard(card, cb) | Show an Adaptive Card with inputs and buttons |
deferrals.handover(data) | Pass data to the loading screen |
deferrals.done() / done(reason) | Let them in, or refuse with a reason |
- Make every code path finish in
deferrals.done. A path that does not leaves the player hanging on “connecting”. - A queue keeps players inside deferrals, orders them by priority and join time, and refreshes their position every few seconds.
- A whitelist usually checks for a Discord role through the bot API and caches the answer briefly.
- Build cards at adaptivecards.io and keep to simple 1.x elements.
The value passed to deferrals.handover is what the loading screen later reads from window.nuiHandoverData; the page side is in building the screen.
A single link that opens the client and connects is the most useful thing to put in every post, video and profile. It comes in three forms.
| Where | Use |
|---|---|
| Anywhere | https://cfx.re/join/<code> |
| Website “Play” button | fivem://connect/cfx.re/join/<code> |
| F8 console | connect cfx.re/join/<code> or connect ip:port |
The code is the ID at the end of your page on servers.fivem.net. It is tied to your listing and key — keep the same key when you change hosts.