SetVehicleColor: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} | ||
This function will set the color of a vehicle. | {{Warning|Informations below apply to MTA:SA v1.1 and newer! Scroll down to view old version of this function.|true}} | ||
This function will set the color of a vehicle. Colors are in RGB format, vehicles can have up to 4 colors. Most vehicles have 2 colors only. | |||
{{New feature|3.0110|1.1| | {{New feature|3.0110|1.1| | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 38: | Line 23: | ||
==Example== | ==Example== | ||
<section name="Example 1" class="server" show="true"> | <section name="Example 1" class="server" show="true"> | ||
This example implements a serverside ''random_color'' console command. | |||
<syntaxhighlight lang="lua"> | |||
addCommandHandler( 'random_color', | |||
function( uPlayer ) | |||
if isPedInVehicle( uPlayer ) then | |||
local uVehicle = getPedOccupiedVehicle( uPlayer ) | |||
if uVehicle then | |||
local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) | |||
setVehicleColor( uVehicle, r, g, b ) | |||
end | |||
end | |||
end | |||
) | |||
</syntaxhighlight> | |||
</section> | |||
{{Warning|Informations below apply to MTA:SA v1.0.5 and older!|true}} | |||
This function will set the color of a vehicle. Each vehicle can have up to 4 colors, for different aspects of the vehicle. Most vehicles only use two of the colors. | |||
==Syntax== | |||
<syntaxhighlight lang="lua"> | |||
bool setVehicleColor ( vehicle theVehicle, int color1, int color2, int color3, int color4 ) | |||
</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''theVehicle:''' The [[vehicle]] that you wish to set the color of. | |||
*'''color1:''' An integer indicating the first (main) color for the vehicle | |||
*'''color2:''' An integer indicating the second color for the vehicle | |||
*'''color3:''' An integer indicating the third color for the vehicle | |||
*'''color4:''' An integer indicating the fourth color for the vehicle | |||
The table below shows valid color ids: | |||
{{Vehicle_colors}} | |||
<br> | |||
<section name="Example 1" class="server" show="false"> | |||
This example implements a serverside ''set_vehicle_color'' console command. | This example implements a serverside ''set_vehicle_color'' console command. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 71: | Line 93: | ||
</section> | </section> | ||
<section name="Example 2" class="server" show="false"> | |||
<section name="Example 2" class="server" show=" | |||
This example changes all vehicles color to random every 0.5 sec. | This example changes all vehicles color to random every 0.5 sec. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 91: | Line 112: | ||
==See Also== | ==See Also== | ||
{{Vehicle_functions}} | {{Vehicle_functions}} |
Revision as of 17:55, 5 September 2012
This function will set the color of a vehicle. Colors are in RGB format, vehicles can have up to 4 colors. Most vehicles have 2 colors only.
Syntax
bool setVehicleColor ( vehicle theVehicle, int r1, int g1, int b1, [int r2, int g2, int b2,] [int r3, int g3, int b3,] [int r4, int g4, int b4] )
Required Arguments
- theVehicle: The vehicle that you wish to set the color of.
- r1, g1, b1: Three integers indicating the red, green and blue components of the first (main) color for the vehicle
Optional Arguments
- r2, g2, b2: Three integers indicating the red, green and blue components of the second color for the vehicle
- r3, g3, b3: Three integers indicating the red, green and blue components of the third color for the vehicle
- r4, g4, b4: Three integers indicating the red, green and blue components of the fourth color for the vehicle
Returns
Returns true if vehicle's color was set, false if an invalid vehicle or invalid colors were specified.
Example
Click to collapse [-]
Example 1This example implements a serverside random_color console command.
addCommandHandler( 'random_color', function( uPlayer ) if isPedInVehicle( uPlayer ) then local uVehicle = getPedOccupiedVehicle( uPlayer ) if uVehicle then local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) setVehicleColor( uVehicle, r, g, b ) end end end )
This function will set the color of a vehicle. Each vehicle can have up to 4 colors, for different aspects of the vehicle. Most vehicles only use two of the colors.
Syntax
bool setVehicleColor ( vehicle theVehicle, int color1, int color2, int color3, int color4 )
Required Arguments
- theVehicle: The vehicle that you wish to set the color of.
- color1: An integer indicating the first (main) color for the vehicle
- color2: An integer indicating the second color for the vehicle
- color3: An integer indicating the third color for the vehicle
- color4: An integer indicating the fourth color for the vehicle
The table below shows valid color ids:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 |
120 | 121 | 122 | 123 | 124 | 125 | 126 |
Click to expand [+]
Example 1Click to expand [+]
Example 2
See Also
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates