I’ve been working on an ai train module, or well, trying to improve some already sound code but Im having issues getting passengers on the train. CreateMissionTrain has a passengers flag but it doesn’t seem to apply to the south western line train, for whatever reason.

Has anyone had any ideas about this and how to tackle it?

Alright I think I have a lead. I’ve been using this script here to spawn trains and while not every train will spawn passengers, some will. I’ve marked them in the hashes list. Hopefully this saves someone a few hours as I lost a couple nights on this lol.

local TRAIN_HASHES = {
-1464742217, – no
-577630801, – no
-1901305252, – no
-1719006020,
519580241,
1495948496,
1365127661,
-1083616881,
1030903581,
-2006657222, – YES
1285344034, – YES
-156591884,
987516329,
-1740474560,
-651487570,
-593637311,
1094934838,
1054492269,
1216031719,
}

– train list command (/trains)
RegisterCommand(“trains”, function()
print(“id”, “hash”, “wagons”)
for trainId, trainHash in next, TRAIN_HASHES do
print(trainId, trainHash, N_0x635423d55ca84fc8(trainHash))
end
end)

CURRENT_TRAIN = nil

function SpawnTrainSimple(n)
local trainHash = TRAIN_HASHES[n]
local trainWagons = N_0x635423d55ca84fc8(trainHash)
for wagonIndex = 0, trainWagons - 1 do
local trainWagonModel = N_0x8df5f6a19f99f0d5(trainHash, wagonIndex)
PerformRequest(trainWagonModel)
end
local train = N_0xc239dbd9a57d2a71(trainHash, GetEntityCoords(PlayerPedId()), 0, 1, 1, 1)
SetTrainSpeed(train, 0.0)
TaskWarpPedIntoVehicle(PlayerPedId(), train, -1)
CURRENT_TRAIN = train
end

– train spawn command (/train id)
RegisterCommand(“train”, function(source, args, raw)
local n = tonumber(args[1])
SpawnTrainSimple(n)
end)

function PerformRequest(hash)
RequestModel(hash, 0) – RequestModel
local times = 1
while not Citizen.InvokeNative(0x1283B8B89DD5D1B6, hash) do – HasModelLoaded
Citizen.InvokeNative(0xFA28FE3A6246FC30, hash, 0) – RequestModel
times = times + 1
Citizen.Wait(0)
if times >= 100 then break end
end
end

1 Like

More train hashes and whether or not they spawn passengers; again hopefully this saves someone some hassle.


The rest of the train hashes that I could find and spawn in.