Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CreateMissionTrain.md #791

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 73 additions & 8 deletions VEHICLE/CreateMissionTrain.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@ ns: VEHICLE
Vehicle CREATE_MISSION_TRAIN(int variation, float x, float y, float z, BOOL direction);
```

Train models must be [requested](#_0x963D27A58DF860AC) before use. See trains.xml for freight and metro variations.
Train models must be [requested](#_0x963D27A58DF860AC) before use. See trains.xml (located in `Grand Theft Auto V\update\update.rpf\common\data\levels\gta5\trains.xml`) for freight and metro variations.

Model names to request can be found by searching `model_name` in the file.

The `Lua` usage example provided down below has been provided in such way so users can test each and every train variation.

### Newly added parameters (seen in 2372 build)

```
NativeDB Added Parameter 6: Any p5
NativeDB Added Parameter 7: Any p6
NativeDB Added Parameter 6: BOOL isNetwork
NativeDB Added Parameter 7: BOOL netMissionEntity
```

* **isNetwork**: Whether to create a network object for the train. If false, the train exists only locally.
* **netMissionEntity**: Whether to register the train as pinned to the script host in the R* network model.

### Train Models:
* freight

### Carriage Models:
* freightcar
* freightcar2 (Added v2372)
* freightcont1
Expand All @@ -25,11 +36,65 @@ NativeDB Added Parameter 7: Any p6
* metrotrain
* tankercar

### Some train variations (default from trains.xml as of build 2372)
* 17. Very long train and freight variation.
* 18. Freight train only.
* 25. Double metro train (with both models flipped opposite to each other). This used to be `24` before the 2372 build.

## Parameters
* **variation**:
* **x**:
* **y**:
* **z**:
* **direction**:
* **variation**: The variation id, these can range from 0 to 25 as of build 2372.
* **x**: Spawn coordinate X component.
* **y**: Spawn coordinate Y component.
* **z**: Spawn coordinate Z component.
* **direction**: The direction in which the train will go (true or false)

## Return value
A script handle (fwScriptGuid index) for the train, or 0 if the train failed to be created.

## Examples
```lua
--[[
This function needs to be invoked prior to calling CreateMissionTrain or the trains (as well as its carriages) won't spawn.
Could also result in a game-crash when CreateMissionTrain is called without
loading the train model needed for the variation before-hand.
]]
function loadTrainModels()
local trainsAndCarriages = {
'freight', 'metrotrain', 'freightcont1', 'freightcar',
'freightcar2', 'freightcont2', 'tankercar', 'freightgrain'
}

for _, vehicleName in ipairs(trainsAndCarriages) do
local modelHashKey = GetHashKey(vehicleName)
RequestModel(modelHashKey) -- load the model
-- wait for the model to load
while not HasModelLoaded(modelHashKey) do
Citizen.Wait(500)
end
end
end

loadTrainModels()

RegisterCommand("createtrain", function(source, args, rawCommand)
if #args < 1 then
TriggerEvent('chat:addMessage', {
args = {
'Error, provide a variation id, you can find those in trains.xml. Variations range from 0 to 25.'
}
})
return
end

local playerCoords = GetEntityCoords(PlayerPedId())
-- Now actually create a train using a variation
-- These coordinates were used for testing: 1438.98, 6405.92, 34.19
CreateMissionTrain(
tonumber(args[1]),
playerCoords.x, playerCoords.y, playerCoords.z,
true,
true,
true
)
end, false)
```
Loading