GetTrainPosition: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Client function}} {{New feature/item|3.0160|1.6|7485| Gets the position the train is currently on the track }} ==Syntax== <syntaxhighlight lang="lua">float getTrainPosition ( vehi...") |
m (fix version) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{ | {{Shared function}} | ||
{{New feature/item|3. | {{New feature/item|3.0153|1.5.3|7485| | ||
Gets the position the train is currently on the track | Gets the position the train is currently on the track | ||
}} | }} | ||
Line 14: | Line 14: | ||
Returns a float that represents how along the track it is, ''false'' if there is problem with train element. | Returns a float that represents how along the track it is, ''false'' if there is problem with train element. | ||
==Example== | ==Example== | ||
<section class="server" name="Server script" show="true"> | |||
This example adds a command called "/getpos", allowing you to get the position of the train. | |||
<syntaxhighlight lang="lua"> | |||
function position(player) | |||
if player and isElement(player) then | |||
if isPedInVehicle(player) then -- make sure we're actually in a vehicle | |||
local vehicle = getPedOccupiedVehicle(player) | |||
if vehicle then | |||
local vehType = getVehicleType (vehicle) | |||
if vehType == "Train" then -- make sure we're in a train | |||
local position = getTrainPosition (vehicle) | |||
outputChatBox("The Train position is: "..position) | |||
else | |||
outputChatBox("You are not in a train!") | |||
end | |||
end | |||
else | |||
outputChatBox("You are not in a vehicle!") | |||
end | |||
end | |||
end | |||
addCommandHandler("getpos",position) | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | ==See Also== | ||
{{Vehicle functions}} | {{Vehicle functions}} |
Latest revision as of 17:13, 22 October 2016
Gets the position the train is currently on the track
Syntax
float getTrainPosition ( vehicle train )
OOP Syntax Help! I don't understand this!
- Method: vehicle:getTrainPosition(...)
- Variable: .trainPosition
- Counterpart: setTrainPosition
Required Arguments
- train: the train to get the position of
Returns
Returns a float that represents how along the track it is, false if there is problem with train element.
Example
Click to collapse [-]
Server scriptThis example adds a command called "/getpos", allowing you to get the position of the train.
function position(player) if player and isElement(player) then if isPedInVehicle(player) then -- make sure we're actually in a vehicle local vehicle = getPedOccupiedVehicle(player) if vehicle then local vehType = getVehicleType (vehicle) if vehType == "Train" then -- make sure we're in a train local position = getTrainPosition (vehicle) outputChatBox("The Train position is: "..position) else outputChatBox("You are not in a train!") end end else outputChatBox("You are not in a vehicle!") end end end addCommandHandler("getpos",position)
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