SetVehicleVariant: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
Only available in MTA:SA v1.2 and onwards.
Only available in MTA:SA v1.2 and onwards.
}}
}}
Page in the making.
This function sets the variant of a specified vehicle. In GTA SA some vehicles are different for example the labelling on trucks or the contents of a pick-up truck and the varying types of a motor bike. For the default GTA SA variant list see: [[Vehicle variants]]


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">int getVehicleLightState ( vehicle theVehicle, int light )</syntaxhighlight>
<syntaxhighlight lang="lua">bool getVehicleVariant ( vehicle theVehicle, int variant1, int variant2 )</syntaxhighlight>


==Required Arguments==
==Required Arguments==
*'''theVehicle:''' A handle to the [[vehicle]] that you wish to know the light state of.
*'''theVehicle:''' A handle to the [[vehicle]] that you want to get the variant of. Specifying no variant will result in random one being picked.
*'''light:''' A whole number between 0 and 3
 
==Optional Arguments==
* '''variant1''': An integer for the second vehicle variant see [[Vehicle variants]]
* '''variant2''': An integer for the first vehicle variant see [[Vehicle variants]]


==Returns==
==Returns==
Returns 0 (working) or 1 (broken)
On success:
* '''bool''': Returns true as the vehicle variants were successfully set.
On failure:
* '''bool''': False because the specified vehicle didn't exist or specified variants were invalid.


==Example==
==Example==
<syntaxhighlight lang="lua">newcar = createVehicle ( 520, 1024, 1024, 1024 )
This example lets the vehicle driver set their vehicle variant with setvehvar
state = getVehicleLightState ( newcar, 0 )
<syntaxhighlight lang="lua">
outputChatBox ( "The front-left light state on this car: " .. state )</syntaxhighlight>
function setMyVehiclesVariant(theUser, command, var1, var2)
    local var1, var2 = tonumber(var1), tonumber(var2) -- If anything was passed make sure its number or nil
    local myVeh = getPedOccupiedVehicle(theUser) -- Get the vehicle that they're in
    if (myVeh and getVehicleController(myVeh) == theUser) then -- Make sure they're in control
        local wasSet = setVehicleVariant(myVeh, var1, var2) -- Set what they wanted
        if (wasSet) then
            outputChatBox("Vehicle variant successfully set!", theUser, 0, 255, 0)
        else
            outputChatBox("Vehicle variant unsuccessfully set.", theUser, 255, 255, 0)
        end
    end
end
addCommandHandler("setvehvar", setMyVehiclesVariant) -- Add the command
</syntaxhighlight>


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

Revision as of 23:46, 16 November 2011

Only available in MTA:SA v1.2 and onwards. This function sets the variant of a specified vehicle. In GTA SA some vehicles are different for example the labelling on trucks or the contents of a pick-up truck and the varying types of a motor bike. For the default GTA SA variant list see: Vehicle variants

Syntax

bool getVehicleVariant ( vehicle theVehicle, int variant1, int variant2 )

Required Arguments

  • theVehicle: A handle to the vehicle that you want to get the variant of. Specifying no variant will result in random one being picked.

Optional Arguments

Returns

On success:

  • bool: Returns true as the vehicle variants were successfully set.

On failure:

  • bool: False because the specified vehicle didn't exist or specified variants were invalid.

Example

This example lets the vehicle driver set their vehicle variant with setvehvar

function setMyVehiclesVariant(theUser, command, var1, var2)
    local var1, var2 = tonumber(var1), tonumber(var2) -- If anything was passed make sure its number or nil
    local myVeh = getPedOccupiedVehicle(theUser) -- Get the vehicle that they're in
    if (myVeh and getVehicleController(myVeh) == theUser) then -- Make sure they're in control
        local wasSet = setVehicleVariant(myVeh, var1, var2) -- Set what they wanted
        if (wasSet) then
            outputChatBox("Vehicle variant successfully set!", theUser, 0, 255, 0)
        else
            outputChatBox("Vehicle variant unsuccessfully set.", theUser, 255, 255, 0)
        end
    end
end
addCommandHandler("setvehvar", setMyVehiclesVariant) -- Add the command

See Also