SetVehicleEngineState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (OOP)
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function changes the on/off state of a vehicle's engine
{{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 EngineOn )</syntaxhighlight>
<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.
*'''EngineOn''': A boolean value representing whether or not the engine will be turnt on or off.
*'''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 disallow the use of the engine in any vehicle
<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">
addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
function turnEngineOff ( theVehicle, leftSeat, jackerPlayer )
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
    -- if it's the driver who got out, and he was not jacked,
  if ( seat == 0 ) then -- if they're getting into the driver seat
    if leftSeat == 0 and not jackerPlayer then
    setVehicleEngineState ( theVehicle, false ) -- turn off the engine
        -- turn off the engine
  end
        setVehicleEngineState ( theVehicle, false )
    end
end
end
-- add 'turnEngineOff' as a handler for "onPlayerExitVehicle"
addEventHandler ( "onPlayerVehicleExit", getRootElement ( ), turnEngineOff )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Vehicle functions}}
{{Vehicle functions}}

Revision as of 19:00, 4 June 2017

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 [-]
Serverside example

This 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", getRootElement ( ), turnEngineOff )

See Also