SetVehicleWheelStates: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 30: Line 30:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function scriptWheelStates ( thePlayer, command, newFLeft, newRLeft, newFRight, newRRight )
function scriptWheelStates ( thePlayer, command, newFLeft, newRLeft, newFRight, newRRight )
  local theVehicle = getPlayerOccupiedVehicle ( thePlayer )
    local theVehicle = getPlayerOccupiedVehicle ( thePlayer )
  if ( theVehicle ) then -- check if the player is in a car
    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 ( newFLeft ) then   -- if there's at least one argument passed, we change the wheel states
  if not setVehicleWheelStates ( theVehicle, newFLeft, newRLeft, newFRight, newRRight ) then
            if not setVehicleWheelStates ( theVehicle, newFLeft, newRLeft, newFRight, newRRight ) then
    outputChatBox ( "Bad arguments." )
                outputChatBox ( "Bad arguments." )
  end
            end
end
        end
    local states = { [0]="inflated", [1]="flat", [2]="fallen off" } -- we store the states in a table
        local states = { [0]="inflated", [1]="flat", [2]="fallen off" }   -- we store the states in a table
    local frontLeft, frontRight, rearLeft, rearRight = getVehicleWheelStates ( theVehicle )
        local frontLeft, frontRight, rearLeft, rearRight = getVehicleWheelStates ( theVehicle )
    outputChatBox ( "Your vehicle's wheel states:", thePlayer ) -- output them in the chatbox
        outputChatBox ( "Your vehicle's wheel states:", thePlayer )       -- output them in the chatbox
    outputChatBox ( "Front-Left: " .. states [ frontLeft ] .. ", Front-Right: " .. states [ frontRight ]
        outputChatBox ( "Front-Left: " .. states [ frontLeft ] .. ", Front-Right: " .. states [ frontRight ] ..
      .. ", Rear-Left: " .. states [ rearLeft ] .. ", Rear-Right: " .. states [ rearRight ], thePlayer )
          ", Rear-Left: " .. states [ rearLeft ] .. ", Rear-Right: " .. states [ rearRight ], thePlayer )
  else outputChatBox ( "You have to be in a vehicle to use this command.", thePlayer )
    else
  end
        outputChatBox ( "You have to be in a vehicle to use this command.", thePlayer )
    end
end
end
addCommandHandler ( "wheelstates", scriptWheelStates )</syntaxhighlight>
addCommandHandler ( "wheelstates", scriptWheelStates )</syntaxhighlight>

Revision as of 19:19, 15 August 2007

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

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

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

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 = getPlayerOccupiedVehicle ( 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, frontRight, rearLeft, 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 )

See Also