NX Spawn Selector

Developer API

Exports for other multicharacter scripts or custom spawn flows.

NX Spawn Selector is opened through client exports. The esx_multicharacter hook uses them, and you can use them too if you run a different multicharacter script or your own spawn flow.

open

Opens the selector and calls back with the chosen spawn point.

client.lua
exports['nx-spawnselector']:open({
    isNew = false,                  -- true for a brand-new character
    coords = lastCoords,            -- { x, y, z, heading } for Last Location, or nil
    job = 'police',                 -- ESX job name, used for job-locked spawns
}, function(coords)
    if coords then
        -- coords = { x = ..., y = ..., z = ..., heading = ... }
    else
        -- couldn't open: spawn the player normally
    end
end)
isNewboolean
Whether this is a brand-new character. New characters never get Last Location.
coordstable | nil
Where the character logged out, used for Last Location. Needs x, y, z and optionally heading.
jobstring | nil
The character's ESX job name, used to filter job-locked locations.
callbackfunction(coords)
Called once with { x, y, z, heading } when the player spawns, or nil if the selector couldn't open (UI not loaded, no locations, already open, or an error).

Always handle nil

If the callback gets nil, spawn the player at their normal spot. Otherwise they'll be left on a black screen.

What the selector does and doesn't do

  • It fades to black, shows a local preview copy of the character, and handles its own camera and UI.
  • It does not move or spawn the real player. Your code does that with the coords it gets back.
  • The real player ped is frozen and hidden while the selector is open. Unfreeze it when you spawn the player.
  • The screen is left faded out when the callback runs, so fade in after you've spawned the player.

shouldOpen

client.lua
local show = exports['nx-spawnselector']:shouldOpen(isNew)

Returns true unless the character is new and Config.NewCharacters is false. Use it to respect the server's config before opening.

isOpen

client.lua
if exports['nx-spawnselector']:isOpen() then
    -- e.g. don't show your HUD yet
end

Returns true while the selector is on screen.

Example: waiting for a result

To use it inline, wrap the callback in a promise, like the multicharacter hook does:

client.lua
local function pickSpawn(isNew, lastCoords, job)
    if GetResourceState('nx-spawnselector') ~= 'started' then return nil end
    if not exports['nx-spawnselector']:shouldOpen(isNew) then return nil end

    local p = promise.new()
    exports['nx-spawnselector']:open({ isNew = isNew, coords = lastCoords, job = job }, function(coords)
        p:resolve(coords)
    end)
    return Citizen.Await(p)
end

local spawn = pickSpawn(isNew, lastCoords, job) or defaultSpawn