SetVehicleRotorState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} {{New feature/item|3.0161|1.6.0|22862| Turns the rotor on/off for an plane or helicopter. A vehicle with the rotor turned off cannot hover in the air.}} {{Note|The function should not be confused with setVehicleEngineState.}} ==Syntax== <syntaxhighlight lang="lua"> bool setVehicleRotorState(vehicle theVehicle, bool state [, bool stopRotor = true ] ) </syntaxhighlight> {{OOP||vehicle:setRotorState|rotorState|getRotorState}} ===Requ...")
 
mNo edit summary
Line 10: Line 10:
bool setVehicleRotorState(vehicle theVehicle, bool state [, bool stopRotor = true ] )
bool setVehicleRotorState(vehicle theVehicle, bool state [, bool stopRotor = true ] )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[vehicle]]:setRotorState|rotorState|getRotorState}}
{{OOP||[[vehicle]]:setRotorState|rotorState|getVehicleRotorState}}


===Required Arguments===
===Required Arguments===

Revision as of 02:20, 31 December 2024

ADDED/UPDATED IN VERSION 1.6.0 r22862:
Turns the rotor on/off for an plane or helicopter. A vehicle with the rotor turned off cannot hover in the air.
[[{{{image}}}|link=|]] Note: The function should not be confused with setVehicleEngineState.

Syntax

bool setVehicleRotorState(vehicle theVehicle, bool state [, bool stopRotor = true ] )

OOP Syntax Help! I don't understand this!

Method: vehicle:setRotorState(...)
Variable: .rotorState
Counterpart: getVehicleRotorState


Required Arguments

  • theVehicle: The vehicle (helicopter or plane) whose rotor you want to toggle.
  • state: The rotor state, which determines whether it should be on (true) or off (false).

Optional Arguments

  • stopRotor: Specifies whether the rotor should be stopped after being turned off. If not, the rotor will continue spinning at a constant speed, but it won't slow down or accelerate. It will also not be able to lift off the ground. You can also use setVehicleRotorSpeed to manage the rotor speed.

Returns

Returns true if successful, false otherwise.

Example

local function toggleRotor()
    local veh = getPedOccupiedVehicle(localPlayer)
    if (not isElement(veh)) then
        return
    end

    setVehicleRotorState(veh, not getVehicleRotorState(veh))
    setVehicleEngineState(veh, not getVehicleEngineState(veh))
end

addEventHandler('onClientVehicleEnter', root, function(plr, seat)
    if (seat == 0)
        if (getVehicleType(source) == 'Plane' or getVehicleType(source) == 'Helicopter') then
            setVehicleRotorState(source, false)
            setVehicleEngineState(source, false)
            bindKey('E', 'down', toggleRotor)
        end
    end
end)

See Also