------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- EXAMPLE OF USING:
local current_train = nil
local function CreateTrain(n, direction)
if tonumber(n) then
if n > 0 and n < 100 then
trainHash = train_hashes[n]
else
trainHash = n
end
else
trainHash = GetHashKey(n)
end
local trainWagons = Citizen.InvokeNative(0x635423D55CA84FC8, trainHash) -- _GET_NUM_CARS_FROM_TRAIN_CONFIG(Hash trainConfig);
for wagonIndex = 0, trainWagons - 1 do
local trainWagonModel = Citizen.InvokeNative(0x8DF5F6A19F99F0D5, trainHash, wagonIndex) -- _GET_TRAIN_MODEL_FROM_TRAIN_CONFIG_BY_CAR_INDEX
Citizen.InvokeNative(0xFA28FE3A6246FC30, trainWagonModel) -- REQUEST_MODEL
local i = 0
while not Citizen.InvokeNative(0x1283B8B89DD5D1B6, trainWagonModel) and i < 100 do --HasModelLoaded(
Citizen.InvokeNative(0xFA28FE3A6246FC30, trainWagonModel) -- request model
Citizen.Wait(50)
i=i+1
end
end
local does_train_have_passengers = 1
local does_train_have_conductor = 1
local train = Citizen.InvokeNative(0xC239DBD9A57D2A71, trainHash, GetEntityCoords(PlayerPedId()), direction, does_train_have_passengers, 1, does_train_have_conductor) -- _CREATE_MISSION_TRAIN
Citizen.Wait(500)
current_train = train
end
-- SPAWN TRAIN OR DELETE TRAIN LIKE THAT:
-- train gunslinger3_config
-- train 0x3D72571D
-- train 10 (creates 10th train from list "mission_trains")
-- train delete
RegisterCommand("train", function(source, args, raw)
if args[1] ~= "delete" then
print("trying to create train")
local n = tonumber(args[1])
if not n then
n = GetHashKey(args[1])
end
if n then
local direction = 0
if args[2] then
direction = tonumber(args[2])
if direction == nil then
direction = 0
end
end
CreateTrain(n, direction)
else
print("wrong train hash or name")
end
else
print("trying to delete train "..tostring(current_train))
if current_train and current_train > 0 then
local train_driver_id = Citizen.InvokeNative(0x2963B5C1637E8A27, current_train) -- GET_DRIVER_OF_VEHICLE
if train_driver_id and train_driver_id ~= 0 and train_driver_id ~= PlayerPedId() then
SetEntityAsMissionEntity(train_driver_id,1,1)
DeletePed(train_driver_id)
end
Citizen.InvokeNative(0x0D3630FB07E8B570, Citizen.PointerValueIntInitialized(current_train)) -- DELETE_MISSION_TRAIN
Citizen.InvokeNative(0xA3120A1385F17FF7) -- DELETE_ALL_TRAINS
current_train = 0
end
end
end)
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------