> For the complete documentation index, see [llms.txt](https://nteamdev.gitbook.io/nteam-development/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nteamdev.gitbook.io/nteam-development/scripts/train-scenario-script.md).

# Train scenario script

Welcome to train scenario script installation guide, config and more

## Installation:

1. Download the script from your Keymaster Account
2. Extract the script (if needed) and move it to the `resources` folder in your **FiveM server directory**.
3. Make changes in `config.lua` (if needed)
4. Open `server.cfg` (found in the root directory).
5. Add `ensure scriptname` (replace **scriptname** with the actual folder name).
6. Save and restart your server.

## Config:

```lua
Config.Scenarios = {
	['Welcome'] = { -- this name must stay Welcome if you are using it for PostCharacterCreator
		StartWalkLocation = vector4(2628.1289, 2936.3772, 40.4228, 57.3484),	-- location where player scenario starts
		StopWalkingLocation = vector4(2623.7268, 2938.6338, 40.4228, 64.0300), -- walking from coords to coords must be straight line
		-- Location where train will be spawned
		spawnLocation = vector4(2614.9763, 2944.1470, 40.1375, 140.1980),
		-- Final Destination where train will stop and player gets out
		targetLocation = vector3(324.7359, -1796.8044, 28.1226),
		TrainModel = 24,
		TrainDirection = false, -- its true/false
		PlayerInCarriage = true,
		DriverModel = 'u_m_m_edtoh',
		-- location where player will be teleported after train stopes at station
		StationCoords = vector4(313.8152, -1784.0806, 28.1811, 236.6900),
		PostScenario = function()
			-- this is client side function
			-- You can trigger any client or server event here / or any client export
		end,
	},

	-- this is our example for video you can edit it or use it ( here we replaced train with another model but you can use any model you want )
	['Jail'] = {
		StartWalkLocation = vector4(184.5892, -1908.8032, 22.8594, 227.5445),	-- location where player scenario starts
		StopWalkingLocation = vector4(206.6665, -1933.1744, 22.3089, 216.1803), -- walking from coords to coords must be straight line
		-- Location where train will be spawned
		spawnLocation = vector4(212.1824, -1931.2069, 22.7389, 318.9960),
		-- Final Destination where train will stop and player gets out
		targetLocation = vector3(1965.6018, 2419.7219, 60.2874),
		TrainModel = 20,
		TrainDirection = true, -- its true/false
		PlayerInCarriage = true,
		DriverModel = 'u_m_m_edtoh',
		-- location where player will be teleported after train stopes at station
		StationCoords = vector4(1851.5878, 2585.7178, 45.6719, 85.5455),
		PostScenario = function()
			-- this is client side function
			-- You can trigger any client or server event here / or any client export
			-- for example here add your jail logic ( to send player to jail )
		end,
	},

	['Paleto'] = {
		StartWalkLocation = vector4(-459.9373, 5368.5127, 81.2990, 251.0909),	-- location where player scenario starts
		StopWalkingLocation = vector4(-453.2338, 5366.6680, 81.2989, 253.9655), -- walking from coords to coords must be straight line
		-- Location where train will be spawned
		spawnLocation = vector4(-447.7654, 5358.0933, 81.9381, 181.3557),
		-- Final Destination where train will stop and player gets out
		targetLocation = vector3(1810.5146, 3510.3872, 38.7271),
		TrainModel = 24,
		TrainDirection = false, -- its true/false
		PlayerInCarriage = true,
		DriverModel = 'u_m_m_edtoh',
		-- location where player will be teleported after train stopes at station
		StationCoords = vector4(1825.2296, 3508.4880, 38.3468, 28.0931),
		PostScenario = function()
			-- this is client side function
			-- You can trigger any client or server event here / or any client export
		end,
	},
}
```

## How to use this resource?

#### **Client-Side Usage:**

If you want to start a scenario from the client side, use:

```lua
TriggerEvent('train:startscenario', 'Welcome') 
```

or replace `'Welcome'` with `'Jail'` or any other scenario you’ve created.

#### **Server-Side Usage:**

If you want to trigger the event from the **server**, use:

```lua
TriggerClientEvent('train:startscenario', source, 'Welcome') 
```
