SetVehicleColor

From Multi Theft Auto: Wiki
Revision as of 22:07, 27 December 2019 by Xman40100 (talk | contribs) (Added clarification for https://github.com/multitheftauto/mtasa-blue/issues/1193#issuecomment-569347801)
Jump to navigation Jump to search

This function will set the color of a vehicle using either a RGB format, or the standard San Andreas color IDs. Vehicles can have up to 4 colors, most of the vehicles have 2 colors only.

If p1, p2, p3 and p4 are used, MTA will take it as the palette color format, more or less arguments than that will use the RGB format.

Syntax

bool setVehicleColor ( vehicle theVehicle, int r1/p1, int g1/p2, int b1/p3, [int r2]/int p4, [int g2, int b2, int r3, int g3, int b3, int r4, int g4, int b4] )            


OOP Syntax Help! I don't understand this!

Method: vehicle:setColor(...)


Required Arguments

  • theVehicle: The vehicle that you wish to set the color of.
  • RGB format:
    • r1, g1, b1: Three integers indicating the red, green and blue components of the first (main) color for the vehicle
  • Palette format:

Optional Arguments (RGB format only)

  • 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.

Examples

Click to collapse [-]
Example 1 - RGB format

This 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
)


Click to collapse [-]
Example 2 - palette format

This example implements a serverside command for the player to spawn a red and white Banshee, using the palette colors.

addCommandHandler("banshee", function(player)
    local x, y, z = getElementPosition(player)
    local rx, ry, rz = getElementRotation(player)
    local vehicle = createVehicle(429, x, y, z, 0.0, 0.0, rz, "PALETTE")
    setVehicleColor(vehicle, 3, 1, 0, 0)-- A red and white Banshee!
    addVehicleUpgrade(vehicle, 1010)
    warpPedIntoVehicle(player, vehicle, 0)
    outputChatBox("You have spawned a red and white Banshee! I also added NOS for you!", source, 50, 168, 82)
end)

Issues

Issue ID Description
#9033 Clientside setVehicleColor doesn't work directly after creation

See Also