# Setup Apartments

QIn this section, we'll guide you through the process of setting up apartments with FryDev Spawn. Apartments provide players with immersive living spaces within your FiveM server, enhancing the role-playing experience. Follow these steps to successfully configure apartments:

## Step 1: Ensure Compatibilit*y*

Before proceeding, ensure that you have integrated FryDev Spawn into your server, as explained in our integration guide.

## Step 2: Installing Apartment Resources

If you are using apartments, you'll need the appropriate apartment resource for your server. Install and configure either "qb-apartments" or "ps-housing" according to your preference.

## Step 3: Adjusting Configuration

Open the FryDev Spawn configuration file (`config.lua`) and make sure the following settings align with your apartment resource:

* **Config.APARTMENTS.IN\_USE**: Set this to `true` if you are using apartments, and `false` if you are not.
* **Config.APARTMENTS.SYSTEM**: Choose the appropriate apartment system type: `'qb-apartments'` or `'ps-housing'`.

## Step 4: Customcustomize the starting apartments

Within the apartment resource you've chosen, configure the available apartment points or locations. This step varies depending on the apartment resource you're using, so refer to the respective documentation for detailed instructions.<br>

To customize the starting apartments in your FiveM server, you can make changes to the `CUSTOM.GET_QB_STARTING_APARTMENTS` function located in your `server/sv_custom.lua` file at line 128. Follow these steps to update apartment details:

1. Open your server's `server/sv_custom.lua` file.
2. Locate the `CUSTOM.GET_QB_STARTING_APARTMENTS` function, which is responsible for defining the starting apartments.
3. Within the function, you will find a list of apartment entries, each represented as a table. Here's an example

{% hint style="danger" %}
**Ensure that you only make changes to these parameters and leave the rest of the code unchanged to maintain compatibility with `qb-apartments` and `ps-housing`.**
{% endhint %}

```lua
  {
      label       = "South Rockford Drive",
      id          = "apartment1",
      location    = "Location",
      image       = "https://i.imgur.com/Cx2HylE.jpeg",
      coords      = vector3(12, 12, 12),
      description = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'
  }
```

4. Customize the apartment details as follows:
   * **label**: Change this to the desired name or label for the apartment.
   * **image**: Replace the image URL with the image you want to use for the apartment.
   * **coords**: Adjust the coordinates to specify the location of the apartment.
   * **description**: Modify the description to provide information about the apartment.
5. Save your changes to the `server/sv_custom.lua` file.

{% hint style="info" %}

> **Hint for `ps-housing` Users:**

If you're using `ps-housing` as your housing system, you may notice that in the spawn selector, there is no separate dropdown labeled "apartments." This is because `ps-housing` considers apartments as houses, so you'll only see the dropdown menu for selecting housing options.

Rest assured that despite the absence of a dedicated "apartments" dropdown, you can still access and spawn in apartments using the provided housing options. Simply select from the available housing options in the dropdown, and you'll be able to choose and spawn in the apartments associated with your housing system.

This design is intentional to provide a seamless experience for `ps-housing` users while utilizing the spawn selector.
{% endhint %}

## Install: QB-Apartments Integration

To implement fry\_spawn with qb-apartments please change the following

Got to qb-apartments -> client -> main.lua Line Number: 576

```lua
RegisterNetEvent('apartments:client:setupSpawnUI', function(cData)
    QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result)
     -- Existing Code
    end, cData.citizenid)
end)
```

Into this:

```lua
RegisterNetEvent('apartments:client:setupSpawnUI', function(cData)
    QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result)
        local coords = json.decode(cData.position)
        if result then
            TriggerEvent('fry_spawn:client:open_spawn_qbcore_or_qbx', false, coords)
        else
            if Apartments.Starting then
                TriggerEvent('fry_spawn:client:open_spawn_qbcore_or_qbx', true, {})
            else
                TriggerEvent('fry_spawn:client:open_spawn_qbcore_or_qbx', false, coords)
            end
        end
    end, cData.citizenid)
end)
```

## Install: PS-Housing Integration

To implement fry\_spawn with qb-apartments please change the following

Got to ps-housing -> client -> client.lua Line Number: 52

```lua
RegisterNetEvent('ps-housing:client:setupSpawnUI', function(cData)
  --- Existing Code
end)
```

Into:

```lua
RegisterNetEvent('ps-housing:client:setupSpawnUI', function(cData)
    DoScreenFadeOut(1000)
    local result = lib.callback.await('ps-housing:cb:GetOwnedApartment', source, cData.citizenid)
    local coords = json.decode(cData.position)
    if result then
        TriggerEvent('fry_spawn:client:open_spawn_qbcore_or_qbx', false, coords)
    else
        if Config.StartingApartment then
            TriggerEvent('fry_spawn:client:open_spawn_qbcore_or_qbx', true, {})
        else
            TriggerEvent('fry_spawn:client:open_spawn_qbcore_or_qbx', false, coords)
        end
    end
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jerzys-sandbox.gitbook.io/jerzys-sandbox/spawn-selector/integration/setup-apartments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
