SetVehicleRotorState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(3 intermediate revisions by one other user not shown)
Line 17: Line 17:


===Optional Arguments===
===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.
*'''stopRotor:''' Specifies whether the rotor should be stopped after being turned off. If false, the rotor will continue spinning at a constant speed (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===
Line 23: Line 23:


==Example==
==Example==
<section name="Client" class="client" show="true">
This example code will add a command called '/rotorstart' that will either shut your vehicle's rotors off or start them up again. Do note that once rotors are stopped you will simply fall from the sky.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local function toggleRotor()
function rotorStartStop()
     local veh = getPedOccupiedVehicle(localPlayer)
    -- We need to check if the player is in a vehicle, and whether or not it is a plane or helicopter
     if (not isElement(veh)) then
     local vehicle = getPedOccupiedVehicle(localPlayer)
         return
     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
    -- Set the rotor state depending on previous state and give a message
    local rotorState = getVehicleRotorState(vehicle)
    if (rotorState) then
        setVehicleRotorState(vehicle, false)
        outputChatBox("Your vehicle's rotor has been stopped, you will now drop out of the sky!", 255, 0, 0)
    else
        setVehicleRotorState(vehicle, true)
        outputChatBox("Your vehicle's rotor has been started up, fly away!", 0, 255, 0)
     end
     end
    setVehicleRotorState(veh, not getVehicleRotorState(veh))
    setVehicleEngineState(veh, not getVehicleEngineState(veh))
end
end
 
addCommandHandler("rotorstart", rotorStartStop) -- Add our command handler
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)
 
addEventHandler('onClientVehicleStartExit', root, function(plr, seat)
    if (seat == 0 and (getVehicleType(source) == 'Plane' or getVehicleType(source) == 'Helicopter')) then
        unbindKey('E', 'down', toggleRotor)
    end
end)
</syntaxhighlight>
</syntaxhighlight>
 
</section>
==See Also==
==See Also==
{{Client vehicle functions}}
{{Client vehicle functions}}

Latest revision as of 09:52, 26 July 2025

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 false, the rotor will continue spinning at a constant speed (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

Click to collapse [-]
Client

This example code will add a command called '/rotorstart' that will either shut your vehicle's rotors off or start them up again. Do note that once rotors are stopped you will simply fall from the sky.

function rotorStartStop()
    -- 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
    -- Set the rotor state depending on previous state and give a message
    local rotorState = getVehicleRotorState(vehicle)
    if (rotorState) then
        setVehicleRotorState(vehicle, false)
        outputChatBox("Your vehicle's rotor has been stopped, you will now drop out of the sky!", 255, 0, 0)
    else
        setVehicleRotorState(vehicle, true)
        outputChatBox("Your vehicle's rotor has been started up, fly away!", 0, 255, 0)
    end
end
addCommandHandler("rotorstart", rotorStartStop) -- Add our command handler

See Also