> For the complete documentation index, see [llms.txt](https://tefox-scripts.gitbook.io/tefox-scripts-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tefox-scripts.gitbook.io/tefox-scripts-docs/tefox-scripts-documentation/tefox_spawnselector/installation.md). Agents can also search and read this documentation through its [MCP server](https://tefox-scripts.gitbook.io/tefox-scripts-docs/~gitbook/mcp).

# Installation

**1. Add the resource**

Drop the <mark style="color:yellow;">`tefox_spawnselector`</mark> folder into your resources directory.

**2. Add dependencies to&#x20;**<mark style="color:$info;">**`server.cfg`**</mark>

```lua
ensure tefox_spawnselector
```

<mark style="color:red;">`tefox_spawnselector`</mark> must start **after** your framework and housing resource, since it reads their configuration on load.

**3. Connect Your Multicharacter System**

{% tabs %}
{% tab title="tefox\_multicharacter" %}
No setup needed — the connection is built in.

Just open <mark style="color:yellow;">`config.lua`</mark> and set:

```lua
Config.SpawnSystem = "tefox_spawnselector"
```

That's it. TEFOX Multicharacter handles the rest automatically.
{% endtab %}

{% tab title="qb-multicharacter" %}
{% code title="qb-multicharacter › server › main.lua" %}

```lua
RegisterNetEvent('qb-multicharacter:server:loadUserData', function(cData)
    local src = source
    if QBCore.Player.Login(src, cData.citizenid) then
        repeat
            Wait(10)
        until hasDonePreloading[src]
        print('^2[qb-core]^7 '..GetPlayerName(src)..' (Citizen ID: '..cData.citizenid..') has successfully loaded!')
        QBCore.Commands.Refresh(src)
        loadHouseData(src) -- if you are using ps-housing: delete this func loadHouseData(src)
        TriggerClientEvent('tefox_spawnselector:client:openUI', src, cData, false)
        TriggerEvent("qb-log:server:CreateLog", "joinleave", "Loaded", "green", "**".. GetPlayerName(src) .. "** (<@"..(QBCore.Functions.GetIdentifier(src, 'discord'):gsub("discord:", "") or "unknown").."> |  ||"  ..(QBCore.Functions.GetIdentifier(src, 'ip') or 'undefined') ..  "|| | " ..(QBCore.Functions.GetIdentifier(src, 'license') or 'undefined') .." | " ..cData.citizenid.." | "..src..") loaded..")
    end
end)
```

{% endcode %}

{% code title="qb-multicharacter › server › main.lua" %}

```lua
RegisterNetEvent('qb-multicharacter:server:createCharacter', function(data)
    local src = source
    local newData = {}
    newData.cid = data.cid
    newData.charinfo = data
    if QBCore.Player.Login(src, false, newData) then
        repeat
            Wait(10)
        until hasDonePreloading[src]
        if GetResourceState('qb-apartments') == 'started' and Apartments.Starting then
            print('^2[qb-core]^7 '..GetPlayerName(src)..' has successfully loaded!')
            QBCore.Commands.Refresh(src)
            loadHouseData(src) -- if you are using ps-housing: delete this func loadHouseData(src)
            TriggerClientEvent("qb-multicharacter:client:closeNUI", src)
            TriggerClientEvent('tefox_spawnselector:client:openUI', src, newData, true)
            GiveStarterItems(src)
        else
            print('^2[qb-core]^7 '..GetPlayerName(src)..' has successfully loaded!')
            QBCore.Commands.Refresh(src)
            loadHouseData(src) -- if you are using ps-housing: delete this func loadHouseData(src)
            TriggerClientEvent("qb-multicharacter:client:closeNUIdefault", src)
            TriggerClientEvent('tefox_spawnselector:client:openUI', src, newData, true)
            GiveStarterItems(src)
        end
    end
end)
```

{% endcode %}
{% endtab %}

{% tab title="esx-multicharacter" %}
{% code title="esx-multicharacter › client › main.lua › esx:playerLoaded" %}

```lua
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerData, isNew, skin)
    local spawn = playerData.coords or Config.Spawn
    if isNew or not skin or #skin == 1 then
        local finished = false
        skin = Config.Default[playerData.sex]
        skin.sex = playerData.sex == "m" and 0 or 1
        local model = skin.sex == 0 and mp_m_freemode_01 or mp_f_freemode_01
        RequestModel(model)
        while not HasModelLoaded(model) do
            RequestModel(model)
            Wait(0)
        end
        SetPlayerModel(PlayerId(), model)
        SetModelAsNoLongerNeeded(model)
        TriggerEvent('skinchanger:loadSkin', skin, function()
            local playerPed = PlayerPedId()
            SetPedAoBlobRendering(playerPed, true)
            ResetEntityAlpha(playerPed)
            TriggerEvent('esx_skin:openSaveableMenu', function()
                finished = true
            end, function()
                finished = true
            end)
        end)
        repeat Wait(200) until finished
    end
    DoScreenFadeOut(750)
    Wait(750)
    SetCamActive(cam, false)
    RenderScriptCams(false, false, 0, true, true)
    cam = nil
    local playerPed = PlayerPedId()
    FreezeEntityPosition(playerPed, true)
    if not isNew then TriggerEvent('skinchanger:loadSkin', skin or Characters[spawned].skin) end
    TriggerEvent('tefox_spawnselector:client:openUI', playerData, isNew)
    repeat Wait(200) until not IsScreenFadedOut()
    TriggerServerEvent('esx:onPlayerSpawn')
    TriggerEvent('esx:onPlayerSpawn')
    TriggerEvent('playerSpawned')
    TriggerEvent('esx:restoreLoadout')
    Characters, hidePlayers = {}, false
end)
```

{% endcode %}
{% endtab %}

{% tab title="other" %}
{% code title="" %}

```lua
TriggerClientEvent('tefox_spawnselector:client:openUI', src, cData, isNew)
```

{% endcode %}
{% endtab %}
{% endtabs %}

**4. Verify the installation**

Set <mark style="color:$info;">`Config.Debug = true`</mark> and check the console when a character loads:

```lua
[tefox_spawnselector] Framework: qbcore
[T] openUI | isNew=false
[tefox_spawnselector] UI opened — 6 location(s) | isNew=false
```

{% hint style="info" %}
If <mark style="color:$info;">`openUI`</mark> never appears, the multicharacter integration line isn't being reached — double-check its placement.
{% endhint %}
