# Spawn Select

[**Buy Here**](https://codesign.pro/product/4206363)

[**FiveM Forums Post**](https://forum.cfx.re/t/paid-spawn-selector-by-codesign/2030503)

[**YouTube Showcase Video**](https://youtu.be/2mIqabOUCLc)

This resource can be purchased as part of a bundle for a discount [here](https://codesign.pro/package/4298761).

#### Translate

* [Click here to translate this page.](https://docs-codesign-pro.translate.goog/paid-scripts/spawn-select?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=en-GB&_x_tr_pto=nui)
* [How do I change language?](https://gyazo.com/38606313ac9a7c290dc2c72b6793bde6)

## INSTALLATION GUIDE

### Step 0 - First Steps

{% hint style="warning" %}
**1.** Download your resource from [FiveM’s Keymaster](https://keymaster.fivem.net/asset-grants). &#x20;

**2.** Unzip the `cd_spawnselect.zip` folder and place this folder in your server's resource folder.

**3.** Add the resource to your server start config (server.cfg): `ensure cd_spawnselect`. If you are using a framework, it must be placed anywhere below your framework resource e.g., es\_extended, not above.

```
ensure es_extended
ensure cd_spawnselect
```

{% endhint %}

### Step 1 - Fxmanifest

{% hint style="warning" %}
Depending on your framework and dependencies, you may need to make some changes inside the **`[cd_spawnselect/fxmanifest.lua]`**. We have made this easier by [commenting ](https://i.imgur.com/bbb0dam.png)on the lines you possibly need to change.
{% endhint %}

### Step 2 - Configure Resource

{% hint style="warning" %}
You **MUST** read all configurable options inside the **`[cd_spawnselect/configs/config.lua]`** file and configure them to suit your server's needs. Please read the [”commented out help text”](https://i.imgur.com/QCja8UZ.png) at the end of each line so you can understand what each config option does.

**The most important sections are the options under the** [**Framework** ](https://i.imgur.com/4ukCTZr.png)**and** [**Important** ](https://i.imgur.com/IVm7E8l.png)**sections at the top of the `config.lua`. Everything else is optional.**

{% endhint %}

### Step 3 - SQL Database

{% hint style="warning" %}
You **MUST** import the SQL file to your database. This SQL file is located inside th&#x65;**`READ_ME_AFTER_PURCHASING`** folder, the file is named **`SQL_main.sql`**. Watch this video if you are unsure how to do this [HeidiSQL ](https://youtu.be/s3tqlHV3yb0)/ [PHPMyAdmin](https://youtu.be/NXqmYn7bbMM).
{% endhint %}

### Step 4 - Required Changes

{% tabs %}
{% tab title="ESX" %}
There are **no required changes** you need to make. All you need to do is configure the `config.lua` correctly.
{% endtab %}

{% tab title="QBCore" %}
**Step 1:** Make sure the event named `qb-spawn:client:openUI` has not been changed, or if it has been changed you need to change this event name in the `cd_spawnselect/client_customise_me.lua` to what your modified QBCore has named it because when this event is triggered it will open the spawn select UI.

**Step 2:** Until a future update, the qb-spawn resource is still required to handle the first spawn of new characters so they can choose an apartment. This code in the `client.lua` of `qb-apartments` should look like this.

{% code title="qb-apartments client main.lua" %}

```lua
RegisterNetEvent('apartments:client:setupSpawnUI')
AddEventHandler('apartments:client:setupSpawnUI', function(cData)
    QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result)
        if result ~= nil then
            DoScreenFadeOut(0)
            TriggerEvent('cd_spawnselect:OpenUI')
            TriggerEvent("apartments:client:SetHomeBlip", result.type)
        else
            TriggerEvent('qb-spawn:client:setupSpawns', cData, true, Apartments.Locations)
            TriggerEvent('qb-spawn:client:openUI', true)
        end
    end, cData.citizenid)
end)
```

{% endcode %}

**Step 3:** Remove lines 52-56 client\_customise\_me.lua in cd\_spawnselect.

{% code title="--Comment out or remove these lines." %}

```lua
-- RegisterNetEvent('qb-spawn:client:openUI')
-- AddEventHandler('qb-spawn:client:openUI', function()
--     DoScreenFadeOut(0)
--     Citizen.Wait(2000)
--     TriggerEvent('cd_spawnselect:OpenUI')
-- end)
```

{% endcode %}

Apart from that there are **no other required changes** you need to make to external scripts if you are using version 3.1.0+. All you need to do is configure the `config.lua` correctly.
{% endtab %}

{% tab title="vRP" %}
There are **no required changes** you need to make. All you need to do is configure the `config.lua` correctly.
{% endtab %}

{% tab title="No-framework" %}
There are **no required changes** you need to make. All you need to do is configure the `config.lua` correctly.
{% endtab %}

{% tab title="Other (custom framework)" %}
There are **no required changes** you need to make. All you need to do is configure the `config.lua` correctly.
{% endtab %}
{% endtabs %}

##

## OPTIONAL FEATURES

This section is to help you understand how the built-in features of this resource work, and if applicable, how you can make them compatible with other resources. These features are not required, they are optional and can be configured in the `[configs/config.lua]`.

### Force Opening the UI

**IF** you want to open the spawn select UI for a player you can trigger the client event below. You can also send coordinates in the first argument; these coordinates will be used for the player's "Last Location". If the coordinates in the first argument are nil then the script will get the "Last Location" coordinates from the `GetLastPosition` function in the `server_customise_me.lua`.

{% tabs %}
{% tab title="client-side to client-side" %}

```lua
TriggerEvent('cd_spawnselect:OpenUI')
```

{% endtab %}

{% tab title="From server to client" %}

```lua
TriggerClientEvent('cd_spawnselect:OpenUI', source)
```

{% endtab %}
{% endtabs %}

##

## INFORMATION <a href="#information" id="information"></a>

### Chat Commands <a href="#chat-commands" id="chat-commands"></a>

These chat commands can be renamed and/or disabled in the [Keys and Commands](https://i.imgur.com/bTvuXLZ.png) section of the `[configs/config.lua]`.

The exact usage for each command will be displayed in the chat suggestions when using the commands in-game.

| **Command**            | **Description**                                                    |
| ---------------------- | ------------------------------------------------------------------ |
| **`/personalspawn`**   | The command to add/delete/show your personal spawn.                |
| **`/openspawnselect`** | (Test Command) This is a test command to open the spawn select UI. |

##

## COMMON ISSUES

Please check out our [**Troubleshooting Guide**](https://docs.codesign.pro/coding-information/self-debugging#troubleshooting) before contacting our support.

🔔 <mark style="color:red;">**Folder Name**</mark> Make sure the folder name is `cd_terminalhacker`.

🔔 <mark style="color:red;">**Encrypted Files**</mark> Do not edit the encrypted files in any way.

🔔 <mark style="color:red;">**Not Using ESX**</mark> If you do not use ESX, please read [Step 1](https://docs.codesign.pro/paid-scripts/spawn-select#step-1) again carefully; you must use the Custom Framework option.

🔔 <mark style="color:red;">**Coords need to be floats not integers**</mark> Make sure the coords in the config.lua and mapdata.js have a decimal place at the end.

> <mark style="color:red;">**xPlayer Error?**</mark>
>
> eg., if you see this error: `attempt to index a nil value (local 'xPlayer')`.
>
> {% code overflow="wrap" %}
>
> ```
> ✔️ This means you are triggering the TriggerEvent('cd_spawnselect:OpenUI') event before ESX has fully cached and loaded your player data. Some servers take longer than others due to lower VPS specs, bad optimization, etc... so it takes the SQL queries longer to complete. If you use a multicharacter script, you can fix this by increasing the wait timer by a few seconds before triggering the event from your multiple character script.
> ```
>
> {% endcode %}

> <mark style="color:red;">**SQL Default Value?**</mark>
>
> eg., if you see an error similar to this example when inserting an SQL query into your database - `“BLOB/TEXT column 'personal_spawn' can't have a default value”`.
>
> {% code overflow="wrap" %}
>
> ```
> ✔️ You can use “VARCHAR(256)” instead of “LONGTEXT” in the SQL query.
> ```
>
> {% endcode %}

> <mark style="color:red;">**SQL Unknown Column?**</mark>
>
> eg., if you see an SQL error in the server console similar to this example - `ER_BAD_FIELD_ERROR: Unknown colum 'personal_spawn' in 'where clause'`.
>
> {% code overflow="wrap" %}
>
> ```
> ✔️ You are missing one of the required database columns. The SQL file can be found in the "READ_ME_AFTER_PURCHASING" folder.
> ```
>
> {% endcode %}

> <mark style="color:red;">**Ped visible on first spawn?**</mark>
>
> eg., if you see your ped when first loading into the server before the character selection screen activates.
>
> {% code overflow="wrap" %}
>
> ```
> ✔️ This should not happen, there should be a black screen, so means another script is conflicting. This is most likely caused by 1 line of code in es_extended or essentialmode or spawnmanager. Search for DoScreenFadeIn in the client-side of either of these resources and remove it then restart your server. (It could be in other resources too but these are the common ones).
> ```
>
> {% endcode %}

## ERROR CODES

If you see an error code not listed below, please open a script support ticket in the [Codesign Discord](https://discord.gg/codesign).

{% tabs %}
{% tab title="Server" %}
N/A
{% endtab %}

{% tab title="Client" %} <mark style="color:red;">**3456**</mark> - The `position` in the users database table for this player's character was 0,0,0. The next time a player exits the game this should update the coordinates in the database.

<mark style="color:red;">**6874**</mark> - The player's last saved position was nil.

<mark style="color:red;">**9871**</mark> - The player's job spawn coordinates were nil.

<mark style="color:red;">**6433**</mark> - The player's personal spawn coordinates were nil.

<mark style="color:red;">**3345**</mark> - The coordinates for the chosen spawn location were nil.

<mark style="color:red;">**8897**</mark> - There was an error in the `GetJob` function in the client customize me.

<mark style="color:red;">**2234**</mark> - There was an error in the `HasFullySpawnedIn` function in the client customize me from something you have changed.
{% endtab %}
{% endtabs %}

## CHANGELOG

> **Files Changed**
>
> Not every update requires you to replace the whole folder. We do this because we understand it's a pain to redo the configs for every update.

* **All Files -** This means you should delete your old `cd_spawnselect` folder, download and add in the latest version, reconfigure the configs folder and restart your server.
* **All Files Except config.lua -** This means you should do all of the above (in the All Files section) but additionally **make a backup of the `config.lua`** file and replace the new config.lua file with the one you made a backup of.
* **Specific Files -** This means you can copy and paste the **SPECIFIC** new files over the old ones and restart the server.

> **Update Type**
>
> On rare occasions, you are forced to update to the latest version. Mostly due to authentication updates where the old versions will no longer work.

* **Mandatory -** This means you MUST update to this new version, or the old versions will no longer work.
* **Optional -** This means it's completely your choice whether you wish to update to the latest version. But we do not offer support for old versions for obvious reasons; they are old.

{% hint style="warning" %}
**Skipping Updates**

If you are attempting to update to the latest version but have skipped previous updates, you should update all files just to be safe. For example., let's say you are currently on v4.0.1, you did not update when v4.0.2 was released, and now v4.0.3 is released, and you want to update; you should always use the “All Files” update method.
{% endhint %}

{% tabs %}
{% tab title="v3.0.0" %}

### 26/12/2020 - 19/10/2021

v3.0.0 - v3.1.2

**Files Changed:**&#x20;

* [x] All Files
* [ ] All Files Except config.lua
* [ ] Specific Files

**Update Type:**

* [x] Mandatory
* [ ] Optional

**Changelog:**

{% hint style="success" %}
**Add**

* Added locales for the UI.
* Added the ability to rename all esx events such as the setjob and playerloaded events.
* Added drag-and-drop QBCore compatibility.
  {% endhint %}

{% hint style="info" %}
**Edit**

* Minor code clean up.
* Updated the codesign error handlers.
* Changed the default police job spawn to MRPD.
* Moved the framework code and chat commands to the client customise me to allow for further customization.
* Rewrote a large majority of the code for optimisation and overall cleaned up the code.
* The script is now drag-and-drop with esx, qbcore, vrp and no framework without having to make changes to external scripts.
  {% endhint %}

{% hint style="warning" %}
**Fix**

* Fixed random server error on server start.
* Fixed rare falling to death error.
* Fixed the issue where the OpenUI event would not register if the event was triggered before the script was authorised.
* Fixed the bug where you would be frozen and invisible after spawning.
* Temporary fix for the canary issue until the new Tebex FiveM license system is ready to launch, when this is released we will be fully switching over to the new system.
* Fixed an issue that sometimes caused players to be frozen in the sky.
* Reworked the camera animation after you have chosen your character. This should also resolve visual issues of clipping through landmarks when spawning in certain locations.
* Fixed an issue when using the "no framework" config option.
  {% endhint %}
  {% endtab %}

{% tab title="v4.0.0" %}

### 03/11/2021

**Files Changed:**

* [x] All Files
* [ ] All Files Except config.lua
* [ ] Specific Files

Update Type:

* [x] Mandatory
* [ ] Optional

**Changelog:**&#x20;

{% hint style="danger" %}
**Authentication**

* **We are now using the official Authentication System provided by FiveM. The old auth system will be taken offline 1 week from now (give or take a few days if needed).**
  {% endhint %}

{% hint style="success" %}
**Add**

* Added compatibility for oxmysq
  {% endhint %}
  {% endtab %}

{% tab title="v4.0.1" %}

### 08/11/2021

**Files Changed:**&#x20;

* [ ] All Files
* [ ] All Files Except config.lua
* [x] Specific Files

```lua
fxmanifest.lua - (IMPORTANT)
server/main/server.lua - (IMPORTANT)
client/main/client.lua - (IMPORTANT)
html (FULL FOLDER) - (IMPORTANT)
```

**Update Type:**

* [x] Mandatory
* [ ] Optional

**Changelog:**

{% hint style="danger" %}
**Authentication**

* **Small authentication update to ensure stability**.
  {% endhint %}
  {% endtab %}

{% tab title="v4.0.2" %}

### 22/04/2022

**Files Changed:**&#x20;

* [ ] All Files
* [ ] All Files Except config.lua
* [x] Specific Files

```lua
fxmanifest.lua - (IMPORTANT)
server/server.lua
configs/client_customise_me.lua
```

**Update Type:**

* [ ] Mandatory
* [x] Optional

**Changelog:**

{% hint style="success" %}
**Add**

* Added compatibility with latest oxmysql.&#x20;
  {% endhint %}

{% hint style="warning" %}
**Fix**

* Fixed an issue where the UI would open before the script has fully loaded.
  {% endhint %}
  {% endtab %}

{% tab title="v4.0.3" %}

### 09/08/2022

**Files Changed:**&#x20;

* [ ] All Files
* [ ] All Files Except config.lua
* [x] Specific Files

```lua
fxmanifest.lua - (IMPORTANT)
html (FULL FOLDER) - (IMPORTANT)
```

**Update Type:**

* [ ] Mandatory
* [x] Optional

**Changelog:**

{% hint style="success" %}
**Add**

* Added the ability for users to zoom and scroll on the spawnselect map UI (same as dispatch).
  {% endhint %}
  {% endtab %}
  {% endtabs %}
