---
description: >-
  This resource allows you to spawn trains and change train tracks. The sole
  purpose of this script is to create external functions that you can use for
  your own script.
---

# qadr\_train\_creator - Standalone

### Train Track Switch

{% embed url="https://youtu.be/XQnkvHo-HeE" %}

### Route System

{% embed url="https://youtu.be/PYREmkGwGW8" %}

### All Train Hash

<details>

<summary>All Train Hash</summary>

```lua
=TRAIN====================================
index	hash	wagons
1	-1464742217	6
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	703203753	northpassenger01x
3	703203753	northpassenger01x
4	1786827347	privatebaggage01x
5	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
2	-577630801	5
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	703203753	northpassenger01x
3	1297830025	privateboxcar02x
4	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
3	-1901305252	5
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	253923078	privateflatcar01x
3	253923078	privateflatcar01x
4	253923078	privateflatcar01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
4	-1719006020	13
=WAGONS===================================
index	hash	modelname
0	89913743	privateSteamer01x
1	1192745176	privateCoalCar01x
2	479008570	privatepassenger01x
3	479008570	privatepassenger01x
4	479008570	privatepassenger01x
5	479008570	privatepassenger01x
6	253923078	privateflatcar01x
7	253923078	privateflatcar01x
8	479008570	privatepassenger01x
9	253923078	privateflatcar01x
10	253923078	privateflatcar01x
11	1786827347	privatebaggage01x
12	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
5	519580241	15
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	-321394418	midlandrefrigeratorCar
3	405368030	privateboxcar04x
4	405368030	privateboxcar04x
5	253923078	privateflatcar01x
6	962088794	midlandboxcar05x
7	253923078	privateflatcar01x
8	962088794	midlandboxcar05x
9	962088794	midlandboxcar05x
10	253923078	privateflatcar01x
11	405368030	privateboxcar04x
12	253923078	privateflatcar01x
13	962088794	midlandboxcar05x
14	962088794	midlandboxcar05x
=END======================================
 
=TRAIN====================================
index	hash	wagons
6	1495948496	6
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	-1828437268	northpassenger03x
3	703203753	northpassenger01x
4	253923078	privateflatcar01x
5	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
7	1365127661	7
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	253923078	privateflatcar01x
3	-1828437268	northpassenger03x
4	-1828437268	northpassenger03x
5	253923078	privateflatcar01x
6	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
8	-1083616881	1
=WAGONS===================================
index	hash	modelname
0	-636146522	trolley01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
9	1030903581	10
=WAGONS===================================
index	hash	modelname
0	89913743	privateSteamer01x
1	1192745176	privateCoalCar01x
2	405368030	privateboxcar04x
3	253923078	privateflatcar01x
4	-988822064	privateboxcar01x
5	-988822064	privateboxcar01x
6	479008570	privatepassenger01x
7	479008570	privatepassenger01x
8	572854005	privateDining01x
9	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
10	-2006657222	9
=WAGONS===================================
index	hash	modelname
0	89913743	privateSteamer01x
1	1192745176	privateCoalCar01x
2	1786827347	privatebaggage01x
3	703203753	northpassenger01x
4	703203753	northpassenger01x
5	-988822064	privateboxcar01x
6	-988822064	privateboxcar01x
7	-988822064	privateboxcar01x
8	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
11	1285344034	9
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	1786827347	privatebaggage01x
3	1786827347	privatebaggage01x
4	-1828437268	northpassenger03x
5	-1828437268	northpassenger03x
6	-1828437268	northpassenger03x
7	1786827347	privatebaggage01x
8	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
12	-156591884	9
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	1786827347	privatebaggage01x
3	1786827347	privatebaggage01x
4	-1828437268	northpassenger03x
5	-1828437268	northpassenger03x
6	-988822064	privateboxcar01x
7	-988822064	privateboxcar01x
8	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
13	987516329	9
=WAGONS===================================
index	hash	modelname
0	89913743	privateSteamer01x
1	1192745176	privateCoalCar01x
2	1786827347	privatebaggage01x
3	1786827347	privatebaggage01x
4	479008570	privatepassenger01x
5	479008570	privatepassenger01x
6	-1032231746	privateopensleeper01x
7	-1032231746	privateopensleeper01x
8	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
14	-1740474560	5
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	-1828437268	northpassenger03x
3	1786827347	privatebaggage01x
4	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
15	-651487570	7
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	253923078	privateflatcar01x
3	-1828437268	northpassenger03x
4	-1828437268	northpassenger03x
5	253923078	privateflatcar01x
6	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
16	-593637311	4
=WAGONS===================================
index	hash	modelname
0	89913743	privateSteamer01x
1	1192745176	privateCoalCar01x
2	572854005	privateDining01x
3	944661538	privateArmoured
=END======================================
 
=TRAIN====================================
index	hash	wagons
17	1094934838	10
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	1786827347	privatebaggage01x
3	-1828437268	northpassenger03x
4	-1828437268	northpassenger03x
5	1297830025	privateboxcar02x
6	405368030	privateboxcar04x
7	1297830025	privateboxcar02x
8	405368030	privateboxcar04x
9	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
18	1054492269	1
=WAGONS===================================
index	hash	modelname
0	1493442814	handcart
=END======================================
 
=TRAIN====================================
index	hash	wagons
19	1216031719	9
=WAGONS===================================
index	hash	modelname
0	1871675108	winterSteamer
1	265500599	wintercoalcar
2	253923078	privateflatcar01x
3	-988822064	privateboxcar01x
4	405368030	privateboxcar04x
5	405368030	privateboxcar04x
6	253923078	privateflatcar01x
7	-234987592	privateObservationcar
8	944661538	privateArmoured
=END======================================
 
=TRAIN====================================
index	hash	wagons
20	1824681511	10
=WAGONS===================================
index	hash	modelname
0	89913743	privateSteamer01x
1	1192745176	privateCoalCar01x
2	962088794	midlandboxcar05x
3	962088794	midlandboxcar05x
4	405368030	privateboxcar04x
5	253923078	privateflatcar01x
6	253923078	privateflatcar01x
7	405368030	privateboxcar04x
8	405368030	privateboxcar04x
9	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
21	-904280534	12
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	1786827347	privatebaggage01x
3	1786827347	privatebaggage01x
4	703203753	northpassenger01x
5	703203753	northpassenger01x
6	-1828437268	northpassenger03x
7	-1828437268	northpassenger03x
8	405368030	privateboxcar04x
9	405368030	privateboxcar04x
10	405368030	privateboxcar04x
11	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
22	-1360990987	1
=WAGONS===================================
index	hash	modelname
0	-636146522	trolley01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
23	6161325	8
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	703203753	northpassenger01x
3	703203753	northpassenger01x
4	-1828437268	northpassenger03x
5	253923078	privateflatcar01x
6	1786827347	privatebaggage01x
7	-1946016570	caboose01x
=END======================================
 
=TRAIN====================================
index	hash	wagons
24	-1458552414	8
=WAGONS===================================
index	hash	modelname
0	-164452766	northSteamer01x
1	-544816550	NorthCoalCar01x
2	703203753	northpassenger01x
3	703203753	northpassenger01x
4	-1828437268	northpassenger03x
5	253923078	privateflatcar01x
6	1786827347	privatebaggage01x
7	-1946016570	caboose01x
=END======================================
```



</details>

### trainCreator Example Data

<details>

<summary>trainCreator Example Data</summary>

<pre class="language-lua"><code class="lang-lua">local data = {
        trainhash = 1495948496,                     -- Train hash
        direction = 1,                              -- Train spawn direction
        coords = vector3(-168.99, 620.01, 112.66),  -- Train spawn position
        disableRiding = true,                       -- You can prevent players from using the train. Players who join the server after the train is created can still use the train. I am looking for an effective way to do this.
        trainMaxSpeed = 100.0,                      -- Must be float. Only work ped not player
        deleteTrainWhenCreatedPlayerLeave = true,   -- Delete train when player leave
        blipName = "Train Blip",                    -- Blip name
        conductor = "driveSelf",                    -- You can use any ped
        -- You can select any ped as conductor like "mp_u_m_m_lom_asbmercs_01".
        -- or you can drive your self with "driveSelf"
        route = { 
        -- You can create a route. 
        -- When the train arrives at any point on the route you created, you can trigger the desired function.
        -- You can also trigger train-related functions in these functions.
<strong>            {
</strong>                coords = vector3(-31.70577, 351.8898, 112.88),
                isInCoords = function(train)
                    print("first point")
                    train:setMaxSpeed(50)
                    train:setTrainSpeed(50)
                end
            },
            {
                coords = vector3(57.8, 117.85, 102.57),
                isInCoords = function(train)
                    print("second point")
                    train:setMaxSpeed(1000)
                    train:setTrainSpeed(1000)
                end
            },
            {
                coords = vector3(-328.57, -343.65, 87.86),
                isInCoords = function(train)
                    print("3. point")
                    train:deleteTrain()
                end
            }
        }

    }
</code></pre>



</details>

### All functions/Variables

<details>

<summary>All functions/Variables</summary>

```lua
local createdTrain = exports["qadr_train_creator"]:trainCreator(data)

local speed = 100
createdTrain:setTrainSpeed(speed) -- You can set train current speed.
createdTrain:deleteTrain()        -- You can delete train and conductor
createdTrain:moveTrain()          -- You can move train when train stop (Only work ped conductor not player)
createdTrain:stop()               -- You can stop train when moving. (Only work ped conductor not player)
createdTrain:setMaxSpeed(speed)   -- You can set train maxSpeed. (Only work ped conductor not player)
createdTrain.trainWagons          -- Return train wagon count
createdTrain.train                -- Return train
createdTrain.allVagons            -- Return all train vagons as objects.
createdTrain.conductor            -- Return conductor ped. (Only work ped conductor not player)
createdTrain.blip                 -- Return train blip.

```



</details>

### Example

<details>

<summary>Example</summary>

```lua
RegisterCommand("cTrain",function()
    local train = exports["qadr_train_creator"]:trainCreator({
        trainhash = 1495948496,
        direction = 1,
        coords = vector3(-168.99, 620.01, 112.66),  -- Train spawn position
        disableRiding = true,                       -- Disable riding on the train
        trainMaxSpeed = 100.0,                      -- Must be float
        blipName = "Train Blip",                    -- Blip name
        conductor = "driveSelf",
        -- You can select any ped as conductor like "mp_u_m_m_lom_asbmercs_01".
        -- or you can drive your self with "driveSelf"
        route = {
            {
                coords = vector3(-31.70577, 351.8898, 112.88),
                isInCoords = function(train)
                    print("first point")
                    train:setMaxSpeed(50)
                    train:setTrainSpeed(50)
                end
            },
            {
                coords = vector3(57.8, 117.85, 102.57),
                isInCoords = function(train)
                    print("second point")
                    train:setMaxSpeed(1000)
                    train:setTrainSpeed(1000)
                end
            },
            {
                coords = vector3(-328.57, -343.65, 87.86),
                isInCoords = function(train)
                    print("3. point")
                    train:deleteTrain()
                end
            }
        }

    })
    train:moveTrain()
    Wait(2000)
    train:setMaxSpeed(5000)
end)
```



</details>

{% hint style="warning" %}
If you use "PED" as a train driver instead of a player, you may have problems with OneSync. After the train and the "PED" move away from the players, the "PED" will be deleted automatically. I haven't found a solution to this for now.
{% endhint %}
