GetTrainDirection: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
 (New page: __NOTOC__ {{Server client function}} Gets the direction in which a train is driving (clockwise or counterclockwise).  ==Syntax== <syntaxhighlight lang="lua">bool getTrainDirection ( vehicle train )</syntaxhighlight> ...)  | 
				m (fix oop typo)  | 
				||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 5: | Line 5: | ||
==Syntax==  | ==Syntax==  | ||
<syntaxhighlight lang="lua">bool getTrainDirection ( vehicle train )</syntaxhighlight>  | <syntaxhighlight lang="lua">bool getTrainDirection ( vehicle train )</syntaxhighlight>  | ||
{{OOP||[[vehicle]]:getDirection|direction|setTrainDirection}}  | |||
===Required Arguments===  | ===Required Arguments===  | ||
*'''train:''' the train of which to get the driving direction.  | *'''train:''' the train of which to get the driving direction.  | ||
| Line 11: | Line 11: | ||
===Returns===  | ===Returns===  | ||
Returns ''true'' if the train is driving clockwise on the train track, ''false'' if it is going counterclockwise or a failure occured.  | Returns ''true'' if the train is driving clockwise on the train track, ''false'' if it is going counterclockwise or a failure occured.  | ||
==Example==  | |||
This example outputs to the player the direction the train they're driving is travelling.  | |||
<syntaxhighlight lang="lua">  | |||
function trainDir(thePlayer,command)  | |||
	if (isPedInVehicle(thePlayer)) then -- Check if they're even in a vehicle.  | |||
		if (getVehicleType(getPedOccupiedVehicle(thePlayer)) == "Train") then -- Check if they're in a train.  | |||
			local direction = getTrainDirection(getPedOccupiedVehicle(thePlayer)) -- Get the train's direction.  | |||
				if (direction) then  | |||
					outputChatBox("You're driving clockwise.",thePlayer,255,255,0) -- Output that they're driving clockwise.  | |||
				else  | |||
					outputChatBox("You're driving anti-clockwise.",thePlayer,255,255,0) -- Output that they're driving anti-clockwise.  | |||
				end  | |||
		else  | |||
			outputChatBox("You must be in a train to use this command.",thePlayer,255,0,0) -- Output that they're not in a train.  | |||
		end  | |||
	else  | |||
		outputChatBox("You must be in a train to use this command.",thePlayer,255,0,0) -- Output that they're not in a vehicle.  | |||
	end  | |||
end  | |||
addCommandHandler("direction",trainDir)  | |||
</syntaxhighlight>  | |||
==See Also==  | ==See Also==  | ||
{{Vehicle functions}}  | {{Vehicle functions}}  | ||
Latest revision as of 12:44, 6 September 2015
Gets the direction in which a train is driving (clockwise or counterclockwise).
Syntax
bool getTrainDirection ( vehicle train )
OOP Syntax Help! I don't understand this!
- Method: vehicle:getDirection(...)
 - Variable: .direction
 - Counterpart: setTrainDirection
 
Required Arguments
- train: the train of which to get the driving direction.
 
Returns
Returns true if the train is driving clockwise on the train track, false if it is going counterclockwise or a failure occured.
Example
This example outputs to the player the direction the train they're driving is travelling.
function trainDir(thePlayer,command)
	if (isPedInVehicle(thePlayer)) then -- Check if they're even in a vehicle.
		if (getVehicleType(getPedOccupiedVehicle(thePlayer)) == "Train") then -- Check if they're in a train.
			local direction = getTrainDirection(getPedOccupiedVehicle(thePlayer)) -- Get the train's direction.
				if (direction) then
					outputChatBox("You're driving clockwise.",thePlayer,255,255,0) -- Output that they're driving clockwise.
				else
					outputChatBox("You're driving anti-clockwise.",thePlayer,255,255,0) -- Output that they're driving anti-clockwise.
				end
		else
			outputChatBox("You must be in a train to use this command.",thePlayer,255,0,0) -- Output that they're not in a train.
		end
	else
		outputChatBox("You must be in a train to use this command.",thePlayer,255,0,0) -- Output that they're not in a vehicle.
	end
end
addCommandHandler("direction",trainDir)
See Also
- addVehicleUpgrade
 - addVehicleSirens
 - attachTrailerToVehicle
 - blowVehicle
 - createVehicle
 - detachTrailerFromVehicle
 - fixVehicle
 - getOriginalHandling
 - getTrainDirection
 - getTrainPosition
 - getTrainSpeed
 - getVehicleColor
 - getVehicleCompatibleUpgrades
 - getVehicleController
 - getVehicleDoorOpenRatio
 - getVehicleDoorState
 - getVehicleEngineState
 - getVehicleHandling
 - getVehicleHeadLightColor
 - getVehicleLandingGearDown
 - getVehicleLightState
 - getVehicleMaxPassengers
 - getVehicleModelFromName
 - getVehicleName
 - getVehicleNameFromModel
 - setVehicleNitroActivated
 - 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
 - removeVehicleSirens
 - setTrainDerailable
 - setTrainDerailed
 - setTrainDirection
 - setTrainPosition
 - setTrainSpeed
 - setVehicleColor
 - setVehicleDamageProof
 - setVehicleDoorOpenRatio
 - setVehicleDoorState
 - setVehicleDoorsUndamageable
 - setVehicleEngineState
 - setVehicleFuelTankExplodable
 - setVehicleHandling
 - setVehicleHeadLightColor
 - setVehicleLandingGearDown
 - setVehicleLightState
 - setVehicleLocked
 - setVehicleOverrideLights
 - setVehiclePaintjob
 - setVehiclePanelState
 - setVehiclePlateText
 - setVehicleSirens
 - setVehicleSirensOn
 - setVehicleTaxiLightOn
 - setVehicleTurretPosition
 - setVehicleVariant
 - setVehicleWheelStates