SetTrainPosition: Difference between revisions
m (shared) |
m (add example) |
||
Line 16: | Line 16: | ||
==Example== | ==Example== | ||
<section name="Example 1" class="server" show="true"> | |||
local function setMyPosition(player, _, position) | |||
local veh = player.vehicle | |||
if not veh then | |||
player:outputChat("You are not in a vehicle!") | |||
return | |||
end | |||
if veh.vehicleType ~= "Train" then | |||
player:outputChat("You are not in a train!") | |||
return | |||
end | |||
-- convert position to a number | |||
position = tonumber(position) | |||
-- if position cannot be converted to a number | |||
if not position then | |||
player:outputChat("Syntax: /settrainpos <position>") | |||
player:outputChat("position: number between 0 and 1") | |||
return | |||
end | |||
if (position < 0) or (position > 1) then | |||
player:outputChat("position must be between 0 and 1!") | |||
end | |||
veh.position = position | |||
end | |||
addCommandHandler("settrainpos", setMyPosition) | |||
</section> | |||
{{Example}} | {{Example}} | ||
==See Also== | ==See Also== | ||
{{Vehicle functions}} | {{Vehicle functions}} |
Revision as of 16:05, 2 January 2016
Sets the position the train is currently on the track
Syntax
bool setTrainPosition ( vehicle train, float position )
OOP Syntax Help! I don't understand this!
- Method: vehicle:setTrainPosition(...)
- Variable: .trainPosition
- Counterpart: getTrainPosition
Required Arguments
- train: the train of which to set the track
- position: the position along the track
Returns
Returns true if the train position was set, false otherwise.
Example
local function setMyPosition(player, _, position) local veh = player.vehicle if not veh then player:outputChat("You are not in a vehicle!") return end
if veh.vehicleType ~= "Train" then player:outputChat("You are not in a train!") return end
-- convert position to a number position = tonumber(position)
-- if position cannot be converted to a number if not position then player:outputChat("Syntax: /settrainpos <position>") player:outputChat("position: number between 0 and 1") return end
if (position < 0) or (position > 1) then player:outputChat("position must be between 0 and 1!") end
veh.position = position end addCommandHandler("settrainpos", setMyPosition)
Script Example Missing Function SetTrainPosition needs a script example, help out by writing one. | |
Before submitting check out Editing Guidelines Script Examples. |
-- TODO
See Also
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates