SetVehicleWheelStates: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
 
(11 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
This function sets the state of wheels on the vehicle.
This function sets the state of wheels on the vehicle.


Line 5: Line 6:


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">setVehicleWheelStates ( vehicle theVehicle, int frontLeft, [ int rearLeft = -1, int frontRight = -1, int rearRight = -1 ])</syntaxhighlight>
<syntaxhighlight lang="lua">bool setVehicleWheelStates ( vehicle theVehicle, int frontLeft, [ int rearLeft = -1, int frontRight = -1, int rearRight = -1 ])</syntaxhighlight>
 
{{OOP||[[vehicle]]:setWheelStates||getVehicleWheelStates}}
==Required Arguments==
==Required Arguments==
*'''theVehicle:''' A handle to the [[vehicle]] that you wish to change the wheel states of.
*'''theVehicle:''' A handle to the [[vehicle]] that you wish to change the wheel states of.
Line 20: Line 21:
* '''1:''' Flat
* '''1:''' Flat
* '''2:''' Fallen off
* '''2:''' Fallen off
* '''3:''' Collisionless


==Returns==
==Returns==
Line 25: Line 27:


==Example==
==Example==
<section name="Server" class="server" show="true">
This example displays the states of the vehicle's wheels and changes their states if any arguments were passed.
<syntaxhighlight lang="lua">
function scriptWheelStates ( thePlayer, command, newFLeft, newRLeft, newFRight, newRRight )
    local theVehicle = getPedOccupiedVehicle ( thePlayer )
    if ( theVehicle ) then      -- check if the player is in a car
        if ( newFLeft ) then    -- if there's at least one argument passed, we change the wheel states
            if not setVehicleWheelStates ( theVehicle, newFLeft, newRLeft, newFRight, newRRight ) then
                outputChatBox ( "Bad arguments." )
            end
        end
        local states = { [0]="inflated", [1]="flat", [2]="fallen off" }    -- we store the states in a table
        local frontLeft, rearLeft, frontRight, rearRight = getVehicleWheelStates ( theVehicle )
        outputChatBox ( "Your vehicle's wheel states:", thePlayer )        -- output them in the chatbox
        outputChatBox ( "Front-Left: " .. states [ frontLeft ] .. ", Front-Right: " .. states [ frontRight ] ..
          ", Rear-Left: " .. states [ rearLeft ] .. ", Rear-Right: " .. states [ rearRight ], thePlayer )
    else
        outputChatBox ( "You have to be in a vehicle to use this command.", thePlayer )
    end
end
addCommandHandler ( "wheelstates", scriptWheelStates )</syntaxhighlight>
</section>
<section name="Client" class="client" >
This example displays the states of the vehicle's wheels and changes their states if any arguments were passed.
This example displays the states of the vehicle's wheels and changes their states if any arguments were passed.
<syntaxhighlight lang="lua">function scriptWheelStates ( player, command, newFLeft, newRLeft, newFRight, newRRight )
<syntaxhighlight lang="lua">
  local theVehicle = getPlayerOccupiedVehicle ( player )
function scriptWheelStates (command, newFLeft, newRLeft, newFRight, newRRight )
  if ( theVehicle ) then -- check if the player is in a car
    local theVehicle = getPedOccupiedVehicle ( localPlayer )
  if ( newFLeft ) then -- if there's at least one argument passed, we change the wheel states
    if ( theVehicle ) then     -- check if the player is in a car
  if not setVehicleWheelStates ( theVehicle, newFLeft, newRLeft, newFRight, newRRight ) then
        if ( newFLeft ) then   -- if there's at least one argument passed, we change the wheel states
    outputChatBox ( "Bad arguments." )
            if not setVehicleWheelStates ( theVehicle, newFLeft, newRLeft, newFRight, newRRight ) then
  end
                outputChatBox ( "Bad arguments." )
end
            end
    local states = { [0]="inflated", [1]="flat", [2]="fallen off" } -- we store the states in a table
        end
    local frontLeft, frontRight, rearLeft, rearRight = getVehicleWheelStates ( theVehicle )
        local states = { [0]="inflated", [1]="flat", [2]="fallen off" }   -- we store the states in a table
    outputChatBox ( "Wheel states:" ) -- output them in the chatbox
        local frontLeft, rearLeft, frontRight, rearRight = getVehicleWheelStates ( theVehicle )
    outputChatBox ( "Front-Left: " .. states [ frontLeft ] .. ", Front-Right: " .. states [ frontRight ]
        outputChatBox ( "Your vehicle's wheel states:")       -- output them in the chatbox
      .. ", Rear-Left: " .. states [ rearLeft ] .. ", Rear-Right: " .. states [ rearRight ] )
        outputChatBox ( "Front-Left: " .. states [ frontLeft ] .. ", Front-Right: " .. states [ frontRight ] ..
  else outputChatBox ( "You have to be in a vehicle to use this command." )
          ", Rear-Left: " .. states [ rearLeft ] .. ", Rear-Right: " .. states [ rearRight ])
  end
    else
        outputChatBox ( "You have to be in a vehicle to use this command.")
    end
end
end
addCommandHandler ( "wheelstates", scriptWheelStates )
addCommandHandler ( "wheelstates", scriptWheelStates )</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 20:54, 9 September 2019

This function sets the state of wheels on the vehicle.

Internally, no vehicles have more than 4 wheels. If they appear to, they will be duplicating other wheels.

Syntax

bool setVehicleWheelStates ( vehicle theVehicle, int frontLeft, [ int rearLeft = -1, int frontRight = -1, int rearRight = -1 ])

OOP Syntax Help! I don't understand this!

Method: vehicle:setWheelStates(...)
Counterpart: getVehicleWheelStates


Required Arguments

  • theVehicle: A handle to the vehicle that you wish to change the wheel states of.
  • frontLeft: A whole number representing the wheel state (-1 for no change)

Optional Arguments

  • rearLeft: A whole number representing the wheel state (-1 for no change)
  • frontRight: A whole number representing the wheel state (-1 for no change)
  • rearRight: A whole number representing the wheel state (-1 for no change)

Wheel-State values

  • 0: Inflated
  • 1: Flat
  • 2: Fallen off
  • 3: Collisionless

Returns

Returns a boolean value true or false that tells you if it was successful or not.

Example

Click to collapse [-]
Server

This example displays the states of the vehicle's wheels and changes their states if any arguments were passed.

function scriptWheelStates ( thePlayer, command, newFLeft, newRLeft, newFRight, newRRight )
    local theVehicle = getPedOccupiedVehicle ( thePlayer )
    if ( theVehicle ) then      -- check if the player is in a car
        if ( newFLeft ) then    -- if there's at least one argument passed, we change the wheel states
            if not setVehicleWheelStates ( theVehicle, newFLeft, newRLeft, newFRight, newRRight ) then
                outputChatBox ( "Bad arguments." )
            end
        end
        local states = { [0]="inflated", [1]="flat", [2]="fallen off" }    -- we store the states in a table
        local frontLeft, rearLeft, frontRight, rearRight = getVehicleWheelStates ( theVehicle )
        outputChatBox ( "Your vehicle's wheel states:", thePlayer )        -- output them in the chatbox
        outputChatBox ( "Front-Left: " .. states [ frontLeft ] .. ", Front-Right: " .. states [ frontRight ] ..
           ", Rear-Left: " .. states [ rearLeft ] .. ", Rear-Right: " .. states [ rearRight ], thePlayer )
    else
        outputChatBox ( "You have to be in a vehicle to use this command.", thePlayer )
    end
end
addCommandHandler ( "wheelstates", scriptWheelStates )
Click to expand [+]
Client

See Also