SetVehicleVariant: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(24 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Shared function}}
__NOTOC__
__NOTOC__
{{New feature|3.0120|1.2|
This function sets the variant of a specified vehicle. In GTA: San Andreas 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 variant list see: [[Vehicle variants]].
Only available in MTA:SA v1.2 and onwards.
{{Updated feature/item|1.5.9|1.5.8|20693|Function is also available client-side (previously available server-side only).}}
}}
{{Tip|Both variant arguments need to be supplied, otherwise random ones will be picked.}}
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]]
{{Tip|If you only want one variant, set ''''variant2'''' to ''255''. If you want no variants, then set both ''''variant1'''' and ''''variant2'''' to ''255''.}}
{{Note|The fairings on the NRG-500 and BF-400 are both variants, so unless you explicitly ask for 3 or 4, your bike will have no fairings which some people may find offensive.
}}


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool getVehicleVariant ( vehicle theVehicle, int variant1, int variant2 )</syntaxhighlight>
<syntaxhighlight lang="lua">bool setVehicleVariant ( vehicle theVehicle [, int variant1, int variant2 ] )</syntaxhighlight>
{{OOP||[[vehicle]]:setVariant||getVehicleVariant}}


==Required Arguments==
===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.
*'''theVehicle:''' The [[vehicle]] that you want to set the variant.


==Optional Arguments==
===Optional Arguments===
* '''variant1''': An integer for the second vehicle variant see [[Vehicle variants]]
Both arguments need to be supplied, otherwise random variants will be picked.
* '''variant2''': An integer for the first vehicle variant see [[Vehicle variants]]
* '''variant1''': An integer for the first variant. See [[Vehicle variants]].
* '''variant2''': An integer for the second variant. See [[Vehicle variants]].


==Returns==
==Returns==
On success:
Returns ''true'' if the vehicle variants were successfully set, ''false'' otherwise (the specified vehicle doesn't exist or the specified variants are invalid).
* '''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==
This example lets the vehicle driver set their vehicle variant with setvehvar
This example lets the vehicle driver set their vehicle's variant with a command:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function setMyVehiclesVariant(theUser, command, var1, var2)
function setMyVehicleVariants (thePlayer, commandName, arg1, arg2)
     local var1, var2 = tonumber(var1), tonumber(var2) -- If anything was passed make sure its number or nil
     local variant1, variant2 = tonumber (arg1), tonumber (arg2) -- If anything was passed make sure the arguments are numbers or pass nil
     local myVeh = getPedOccupiedVehicle(theUser) -- Get the vehicle that they're in
     local myVeh = getPedOccupiedVehicle (thePlayer) -- Get the vehicle that the player is 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 (myVeh and getVehicleController (myVeh) == thePlayer) then -- Make sure the player is the vehicle driver (controller)
         if (wasSet) then
         local wasSet = setVehicleVariant (myVeh, variant1, variant2) -- Set the vehicle variants the player passed as arguments
             outputChatBox("Vehicle variant successfully set!", theUser, 0, 255, 0)
 
         if wasSet then
             outputChatBox ("Vehicle variant successfully set!", thePlayer, 0, 255, 0)
         else
         else
             outputChatBox("Vehicle variant unsuccessfully set.", theUser, 255, 255, 0)
             outputChatBox ("Vehicle variant unsuccessfully set.", thePlayer, 255, 255, 0)
         end
         end
     end
     end
end
end
addCommandHandler("setvehvar", setMyVehiclesVariant) -- Add the command
 
addCommandHandler ("setvehvar", setMyVehicleVariants) -- Create the command
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 15:35, 7 November 2024

This function sets the variant of a specified vehicle. In GTA: San Andreas 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 variant list see: Vehicle variants.


Function is also available client-side (previously available server-side only).

[[{{{image}}}|link=|]] Tip: Both variant arguments need to be supplied, otherwise random ones will be picked.
[[{{{image}}}|link=|]] Tip: If you only want one variant, set 'variant2' to 255. If you want no variants, then set both 'variant1' and 'variant2' to 255.
[[{{{image}}}|link=|]] Note: The fairings on the NRG-500 and BF-400 are both variants, so unless you explicitly ask for 3 or 4, your bike will have no fairings which some people may find offensive.

Syntax

bool setVehicleVariant ( vehicle theVehicle [, int variant1, int variant2 ] )

OOP Syntax Help! I don't understand this!

Method: vehicle:setVariant(...)
Counterpart: getVehicleVariant


Required Arguments

  • theVehicle: The vehicle that you want to set the variant.

Optional Arguments

Both arguments need to be supplied, otherwise random variants will be picked.

Returns

Returns true if the vehicle variants were successfully set, false otherwise (the specified vehicle doesn't exist or the specified variants are invalid).

Example

This example lets the vehicle driver set their vehicle's variant with a command:

function setMyVehicleVariants (thePlayer, commandName, arg1, arg2)
    local variant1, variant2 = tonumber (arg1), tonumber (arg2) -- If anything was passed make sure the arguments are numbers or pass nil
    local myVeh = getPedOccupiedVehicle (thePlayer) -- Get the vehicle that the player is in

    if (myVeh and getVehicleController (myVeh) == thePlayer) then -- Make sure the player is the vehicle driver (controller)
        local wasSet = setVehicleVariant (myVeh, variant1, variant2) -- Set the vehicle variants the player passed as arguments

        if wasSet then
            outputChatBox ("Vehicle variant successfully set!", thePlayer, 0, 255, 0)
        else
            outputChatBox ("Vehicle variant unsuccessfully set.", thePlayer, 255, 255, 0)
        end
    end
end

addCommandHandler ("setvehvar", setMyVehicleVariants) -- Create the command

See Also