# How to use Starter Apartments

***

{% hint style="info" %}
**Info:** Starter Apartments let you automatically give new players a simple property when they first join your server or create a character.
{% endhint %}

#### 1. Prepare the Property

Enter the server, go to the `/housing` admin menu and create a Building. Then:

1. Save the property
2. Go to your database and find the `id` of the new property in the `houses` table
3. Copy that ID and paste it into the `Object` field in the config below

#### 2. Configure Starter Apartments

Go to the `config.lua` file and find this code:

```lua
Config.StarterApartments = {
    Object = 114, -- You need to have a property building created and here is to find the id of this building from the database.
    Name = 'Starting Apartment #%s', -- Name of the starter apartment, which will be displayed in the menu.
    Type = 'shell', -- 'shell' / 'ipl'

    Shell = 'standardmotel_shell',
    Ipl = 'apa_v_mp_h_01_a',

    DefaultPurchasePrice = 0, -- Default purchase price of the starter apartment. (By setting 0, the player will not be able to sell the property to make money)
    DefaultRentPrice = 0, -- Default rent price of the starter apartment.

    AllowFurnitureInside = true, -- true : Allow furniture inside the starter apartment
    AllowChangeTheme = true, -- true : Allow changing the theme of the starter apartment IPL
    DefaultThemeIpl = 'modern',

    Delivery = {
        Enabled = true,
        Coords = vector4(2.4304, -2.1917, 498.4416, 79.99999237060547), -- Coords of the storage in the starter apartment
    },

    Storage = {
        Enabled = true,
        Coords = vector3(1.5388, -3.0803, 499.7162), -- Coords of the storage in the starter apartment
        Slots = 20, -- Slots of the storage in the starter apartment
        Weight = 25000, -- Weight of the storage in the starter apartment
    },

    Wardrobe = {
        Enabled = true,
        Coords = vector3(1.3227, 2.8945, 500.0726), -- Coords of the wardrobe in the starter apartment
    },
}
```

#### 3. Assign Apartment Automatically

From your multicharacter, identity, or framework, call this server-side export when a player registers for the first time:

```lua
---@param {identifier: string}: Player Identifier (e.g. 'char1:1100113jadckz')
exports['vms_housing']:AddStarterApartment(identifier)
```

{% tabs %}
{% tab title="es\_extended" %}

1. Go to your `es_extended/server/main.lua`
2. Find your function `loadESXPlayer`
3. Go to the end of the function and add the highlighted code in the appropriate place:

<pre class="language-lua"><code class="lang-lua">    TriggerEvent("esx:playerLoaded", playerId, xPlayer, isNew)
    userData.money = xPlayer.getMoney()
    userData.maxWeight = xPlayer.getMaxWeight()
    xPlayer.triggerEvent("esx:playerLoaded", userData, isNew, userData.skin)

    if setPlayerInventory then
        setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
    end

<strong>    if isNew then
</strong><strong>        exports['vms_housing']:AddStarterApartment(identifier)
</strong><strong>    end
</strong>
    xPlayer.triggerEvent("esx:registerSuggestions", Core.RegisteredCommands)
    print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
end
</code></pre>

{% endtab %}

{% tab title="qb-multicharacter" %}

1. Go to your `qb-multicharacter/server/main.lua`
2. Find your function `GiveStarterItems`
3. Add the highlighted code in the appropriate place:

<pre class="language-lua"><code class="lang-lua">local function GiveStarterItems(source)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    for _, v in pairs(QBCore.Shared.StarterItems) do
        local info = {}
        if v.item == 'id_card' then
            info.citizenid = Player.PlayerData.citizenid
            info.firstname = Player.PlayerData.charinfo.firstname
            info.lastname = Player.PlayerData.charinfo.lastname
            info.birthdate = Player.PlayerData.charinfo.birthdate
            info.gender = Player.PlayerData.charinfo.gender
            info.nationality = Player.PlayerData.charinfo.nationality
        elseif v.item == 'driver_license' then
            info.firstname = Player.PlayerData.charinfo.firstname
            info.lastname = Player.PlayerData.charinfo.lastname
            info.birthdate = Player.PlayerData.charinfo.birthdate
            info.type = 'Class C Driver License'
        end
        exports['qb-inventory']:AddItem(src, v.item, v.amount, false, info, 'qb-multicharacter:GiveStarterItems')
    end
<strong>    exports["vms_housing"]:AddStarterApartment(Player.PlayerData.citizenid)
</strong>end
</code></pre>

{% endtab %}
{% endtabs %}

#### 4. Additional Notes

* Set `DefaultPurchasePrice` and `DefaultRentPrice` to `0` to prevent players from selling the apartment.
* This system is perfect for giving new players a default place to live without extra steps.
* You can fully customize the locations for delivery, wardrobe, and storage.

Once configured, your players will receive a starter apartment automatically when joining the server or creating their character.

#### 5. Teleport player to Starter Apartment

{% hint style="info" %}
Teleporting a player to a starter apartment is not mandatory - **it's an optional use**.
{% endhint %}

{% tabs %}
{% tab title="esx\_multicharacter" %}

1. Go to your `esx_multicharacter/client/modules/multicharacter.lua`
2. Find your function `Multicharacter:LoadSkinCreator`
3. Replace function:

```lua
function Multicharacter:LoadSkinCreator(skin)
    TriggerEvent("skinchanger:loadSkin", skin, function()
        exports['vms_housing']:TeleportToStartingApartment()
        Citizen.Wait(2500)
        DoScreenFadeIn(600)
        SetPedAoBlobRendering(self.playerPed, true)
        ResetEntityAlpha(self.playerPed)

        TriggerEvent("esx_skin:openSaveableMenu", function()
            Multicharacter.finishedCreation = true
        end, function()
            Multicharacter.finishedCreation = true
        end)
    end)
end
```

{% endtab %}

{% tab title="qb-multicharacter" %}

1. Go to your `esx_multicharacter/client/modules/multicharacter.lua`
2. Find your event `Multicharacter:LoadSkinCreator`
3. Replace function:

```lua
RegisterNetEvent('qb-multicharacter:client:closeNUIdefault', function()
    DeleteEntity(charPed)
    SetNuiFocus(false, false)
    DoScreenFadeOut(500)
    TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
    TriggerEvent('QBCore:Client:OnPlayerLoaded')
    Wait(1000)
    exports['vms_housing']:TeleportToStartingApartment()
    Wait(2500)
    openCharMenu()
    SetEntityVisible(PlayerPedId(), true)
    Wait(800)
    TriggerEvent('qb-clothes:client:CreateFirstCharacter')
end)
```

{% endtab %}
{% endtabs %}
