SetVehicleColor

From Multi Theft Auto: Wiki
Revision as of 15:25, 16 July 2008 by LordAzamath (talk | contribs) (All colours are required arguments, not optional.)
Jump to navigation Jump to search

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

Click to collapse [-]
Server and Client
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

Returns

Returns true if vehicle's color was set, false if an invalid vehicle or invalid color ids were specified.

Example

Click to collapse [-]
Example

This example implements a serverside set_vehicle_color console command.

-- Define our function that will handle the command
function consoleSetVehicleColor ( playerSource, commandName, col1, col2, col3, col4 )
	-- If a player triggered this in-game
	if ( playerSource ) then
		-- Get the player's vehicle
		playerVehicle = getPlayerOccupiedVehicle ( playerSource )
		-- If the player is in a vehicle and we've got at least 1 parameter
		if ( playerVehicle and col1 ) then
			-- Get the vehicle's existing color and use it if fewer than 4 arguments were passed
			exCol1, exCol2, exCol3, exCol4 = getVehicleColor ( playerVehicle )

			if not col2 then col2 = exCol2 end
			if not col3 then col3 = exCol3 end
			if not col4 then col4 = exCol4 end

			-- Set the vehicle's color
			setVehicleColor ( playerVehicle, col1, col2, col3, col4 )
		else
			-- If we didn't get at least 1 parameter or the player doesn't have a vehicle, display some help text
			outputConsole ( "This function will set your current vehicle's colors. A vehicle can have up to 4 colors.", playerSource )
			outputConsole ( "Syntax: set_vehicle_color color1 [ color2 color3 color4 ]", playerSource )
			outputConsole ( "You must be in a vehicle to use this function.", playerSource )
		end
	end
end

-- Register the command handler and attach it to the consoleSetVehicleColor function
addCommandHandler ( "set_vehicle_color", consoleSetVehicleColor )

See Also