GetTrainSpeed: Difference between revisions
Jump to navigation
Jump to search
(New page: __NOTOC__ {{Server client function}} Gets the speed at which a train is traveling on the rails. ==Syntax== <syntaxhighlight lang="lua">float getTrainSpeed ( vehicle train )</syntaxhighlight> ===Required Arguments=...) |
(correcting, getSpeed a nil value) |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 6: | Line 6: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">float getTrainSpeed ( vehicle train )</syntaxhighlight> | <syntaxhighlight lang="lua">float getTrainSpeed ( vehicle train )</syntaxhighlight> | ||
{{OOP||[[vehicle]]:getTrainSpeed|trainSpeed|setTrainSpeed}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''train:''' the train of which to retrieve the speed. | *'''train:''' the train of which to retrieve the speed. | ||
Line 12: | Line 12: | ||
===Returns=== | ===Returns=== | ||
Returns the train's speed if successful, ''false'' otherwise. | Returns the train's speed if successful, ''false'' otherwise. | ||
==Example== | |||
<section name="Server" class="server" show="true"> | |||
This example outputs how fast a player is going if they're in a train. The command is "/speed". | |||
<syntaxhighlight lang="lua"> | |||
function getPlayersTrainSpeed ( source, command ) -- Define source in the function header. | |||
if ( isPedInVehicle ( source ) ) -- Check if they're in a vehicle. | |||
local veh = getPedOccupiedVehicle ( source ) -- Get the vehicle they're in. | |||
if ( getVehicleType ( veh ) == "Train" ) then -- Check if the vehicle they're in is a train. | |||
local speed = getTrainSpeed ( veh ) -- Get the trains speed. | |||
outputChatBox ( "You are travelling at a speed of " .. speed, source, 255, 0, 0 ) -- Output their speed. | |||
else | |||
outputChatBox ( "You must be in a train to use this command.", source, 255, 0, 0 ) -- Tell them they're not in a train. | |||
end | |||
else | |||
outputChatBox ( "You must be in a train to use this command.", source, 255, 0, 0 ) -- Tell them they're not in a train. | |||
end | |||
end | |||
addCommandHandler ( "speed", getPlayersTrainSpeed ) -- Make the function trigger when a player types "/speed". | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | ==See Also== | ||
{{Vehicle functions}} | {{Vehicle functions}} |
Latest revision as of 10:33, 5 November 2023
Gets the speed at which a train is traveling on the rails.
Syntax
float getTrainSpeed ( vehicle train )
OOP Syntax Help! I don't understand this!
- Method: vehicle:getTrainSpeed(...)
- Variable: .trainSpeed
- Counterpart: setTrainSpeed
Required Arguments
- train: the train of which to retrieve the speed.
Returns
Returns the train's speed if successful, false otherwise.
Example
Click to collapse [-]
ServerThis example outputs how fast a player is going if they're in a train. The command is "/speed".
function getPlayersTrainSpeed ( source, command ) -- Define source in the function header. if ( isPedInVehicle ( source ) ) -- Check if they're in a vehicle. local veh = getPedOccupiedVehicle ( source ) -- Get the vehicle they're in. if ( getVehicleType ( veh ) == "Train" ) then -- Check if the vehicle they're in is a train. local speed = getTrainSpeed ( veh ) -- Get the trains speed. outputChatBox ( "You are travelling at a speed of " .. speed, source, 255, 0, 0 ) -- Output their speed. else outputChatBox ( "You must be in a train to use this command.", source, 255, 0, 0 ) -- Tell them they're not in a train. end else outputChatBox ( "You must be in a train to use this command.", source, 255, 0, 0 ) -- Tell them they're not in a train. end end addCommandHandler ( "speed", getPlayersTrainSpeed ) -- Make the function trigger when a player types "/speed".
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