SetVehicleEngineState: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This function | {{Server client function}} | ||
This function turns a vehicle's engine on or off. Note that the engine will always be turned on when someone enters the driver seat, unless you override that behaviour with scripts. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool setVehicleEngineState ( vehicle theVehicle, bool | <syntaxhighlight lang="lua"> | ||
bool setVehicleEngineState ( vehicle theVehicle, bool engineState ) | |||
</syntaxhighlight> | |||
{{OOP||[[vehicle]]:setEngineState|engineState|getVehicleEngineState}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theVehicle''': The [[vehicle]] you wish to change the engine state of. | *'''theVehicle''': The [[vehicle]] you wish to change the engine state of. | ||
*''' | *'''engineState''': A boolean value representing whether the engine will be turned on (''true'') or off (''false''). | ||
==Returns== | ===Returns=== | ||
Returns 'true' if the vehicle's engine state was successfully changed, 'false' otherwise. | Returns ''true'' if the vehicle's engine state was successfully changed, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example will | <section name="Clientside example" class="client" show="true"> | ||
This example lets the driver toggle vehicle engine on/off. | |||
<syntaxhighlight lang="lua"> | |||
function toggleEngine() | |||
local vehicle = getPedOccupiedVehicle(localPlayer) | |||
if vehicle and getVehicleController(vehicle) == localPlayer then | |||
setVehicleEngineState(vehicle, not getVehicleEngineState(vehicle)) | |||
end | |||
end | |||
addCommandHandler("engine", toggleEngine) | |||
</syntaxhighlight> | |||
</section> | |||
<section name="Serverside example" class="server" show="true"> | |||
This example will turn off a vehicle's engine when the driver gets out of the car. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function turnEngineOff ( theVehicle, leftSeat, jackerPlayer ) | |||
-- if it's the driver who got out, and he was not jacked, | |||
if leftSeat == 0 and not jackerPlayer then | |||
-- turn off the engine | |||
setVehicleEngineState ( theVehicle, false ) | |||
end | |||
end | end | ||
-- add 'turnEngineOff' as a handler for "onPlayerExitVehicle" | |||
addEventHandler ( "onPlayerVehicleExit", root, turnEngineOff ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Vehicle functions}} | {{Vehicle functions}} |
Latest revision as of 09:01, 4 November 2020
This function turns a vehicle's engine on or off. Note that the engine will always be turned on when someone enters the driver seat, unless you override that behaviour with scripts.
Syntax
bool setVehicleEngineState ( vehicle theVehicle, bool engineState )
OOP Syntax Help! I don't understand this!
- Method: vehicle:setEngineState(...)
- Variable: .engineState
- Counterpart: getVehicleEngineState
Required Arguments
- theVehicle: The vehicle you wish to change the engine state of.
- engineState: A boolean value representing whether the engine will be turned on (true) or off (false).
Returns
Returns true if the vehicle's engine state was successfully changed, false otherwise.
Example
Click to collapse [-]
Clientside exampleThis example lets the driver toggle vehicle engine on/off.
function toggleEngine() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle and getVehicleController(vehicle) == localPlayer then setVehicleEngineState(vehicle, not getVehicleEngineState(vehicle)) end end addCommandHandler("engine", toggleEngine)
Click to collapse [-]
Serverside exampleThis example will turn off a vehicle's engine when the driver gets out of the car.
function turnEngineOff ( theVehicle, leftSeat, jackerPlayer ) -- if it's the driver who got out, and he was not jacked, if leftSeat == 0 and not jackerPlayer then -- turn off the engine setVehicleEngineState ( theVehicle, false ) end end -- add 'turnEngineOff' as a handler for "onPlayerExitVehicle" addEventHandler ( "onPlayerVehicleExit", root, turnEngineOff )
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