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.
Train Track Switch
Route System
All Train Hash
All Train Hash
trainCreator Example Data
trainCreator Example Data
All functions/Variables
All functions/Variables
Example
Example
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.
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.
{
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
}
}
}
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.
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)