GetVehicleRotorState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
Line 7: Line 7:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool getVehicleRotoState ( vehicle theVehicle )
bool getVehicleRotorState ( vehicle theVehicle )
</syntaxhighlight>
</syntaxhighlight>


Line 19: Line 19:


==Example==
==Example==
{{Needs Example}}
<section name="Client" class="client" show="true">
This code adds a simple command that allows you to check a vehicle's rotor state keeping in mind you have to be in either a plane or helicopter.
<syntaxhighlight lang="lua">
function checkRotor()
    -- We need to check if the player is in a vehicle, and whether or not it is a plane or helicopter
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (not vehicle or (getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane")) then
        outputChatBox("You are not in a plane or helicopter!", 255, 0, 0)
        return false
    end
    -- And now we show rotor state using a neat ternary expression
    local rotorState = getVehicleRotorState(vehicle)
    outputChatBox("Your vehicle's rotor is "..(rotorState and "spinning" or "stopped").."!", 0, 255, 0)
end
addCommandHandler("rotor", checkRotor)
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Client vehicle functions}}
{{Client vehicle functions}}

Latest revision as of 22:04, 25 July 2025

ADDED/UPDATED IN VERSION 1.6.0 r22862:
This function returns a vehicle's (plane or helicopter) rotor state (on or off).
[[{{{image}}}|link=|]] Note: The function should not be confused with getVehicleEngineState.

Syntax

bool getVehicleRotorState ( vehicle theVehicle )


OOP Syntax Help! I don't understand this!

Method: vehicle:getRotorState(...)
Variable: .rotorState
Counterpart: setVehicleRotorState


Required Arguments

  • theVehicle: the vehicle you wish to get the engine state of.

Returns

Returns true if the vehicle's rotor is started, false otherwise.

Example

Click to collapse [-]
Client

This code adds a simple command that allows you to check a vehicle's rotor state keeping in mind you have to be in either a plane or helicopter.

function checkRotor()
    -- We need to check if the player is in a vehicle, and whether or not it is a plane or helicopter
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if (not vehicle or (getVehicleType(vehicle) ~= "Helicopter" and getVehicleType(vehicle) ~= "Plane")) then
        outputChatBox("You are not in a plane or helicopter!", 255, 0, 0)
        return false
    end
    -- And now we show rotor state using a neat ternary expression
    local rotorState = getVehicleRotorState(vehicle)
    outputChatBox("Your vehicle's rotor is "..(rotorState and "spinning" or "stopped").."!", 0, 255, 0)
end
addCommandHandler("rotor", checkRotor)

See Also