Is your feature request related to a problem? Please describe.
I was creating a Pay'n'Spray script that works similarly to the way it works on singleplayer. Browsing the wikia for the methods used for get and set the vehicle colors, I found out that getVehicleColor has an RGB argument that can be turned on to return only the standard vehicle color IDs from singleplayer. However, this argument is missing when using the method setVehicleColor, as it only accepts RGB values for 4 different colors.
Describe the solution you'd like
To not break any implementations of setVehicleColor, a new method would be created to only add vehicle colors using IDs.
setVehicleColorID(vehicle theVehicle, int color1, int color2)
vehicle:setColorID(int id)
Describe alternatives you've considered
Obviously, scripters can use the color IDs using a table that contains the RGB values of the standard colors from San Andreas, while this can be achieved, it takes an amount of time to be done. To workaround this, I compiled the RGB values of the color IDs from the wikia, and created a setVehicleColorID function:
-- This table's content is based on the colors from here: https://wiki.multitheftauto.com/wiki/Vehicle_Colors
-- It was taken using the Eyedropper tool from Mozilla Firefox 71.
local saColorIds = {
[0] = {0, 0, 0}, [1] = {255, 255, 255}, [2] = {42, 119, 161}, [3] = {132, 4, 16}, [4] = {38, 55, 57}, [5] = {134, 68, 110}, [6] = {215, 142, 16}, [7] = {76, 117, 183}, [8] = {189, 190, 198}, [9] = {94, 112, 114},
[10] = {70, 89, 122}, [11] = {101, 106, 121}, [12] = {93, 126, 141}, [13] = {88, 89, 90}, [14] = {214, 218, 214}, [15] = {156, 161, 163}, [16] = {51, 95, 63}, [17] = {115, 14, 26}, [18] = {123, 10, 42}, [19] = {159, 157, 148},
[20] = {59, 78, 120}, [21] = {115, 46, 62}, [22] = {105, 30, 59}, [23] = {150, 145, 140}, [24] = {81, 84, 89}, [25] = {63, 62, 69}, [26] = {165, 169, 167}, [27] = {99, 92, 90}, [28] = {61, 74, 104}, [29] = {151, 149, 146},
[30] = {66, 31, 33}, [31] = {95, 39, 43}, [32] = {132, 148, 171}, [33] = {118, 123, 124}, [34] = {100, 100, 100}, [35] = {90, 87, 82}, [36] = {37, 37, 39}, [37] = {45, 58, 53}, [38] = {147, 163, 150}, [39] = {109, 122, 136},
[40] = {34, 25, 24}, [41] = {111, 103, 95}, [42] = {124, 28, 42}, [43] = {95, 10, 21}, [44] = {25, 56, 38}, [45] = {93, 27, 32}, [46] = {157, 152, 114}, [47] = {122, 117, 96}, [48] = {152, 149, 134}, [49] = {173, 176, 176},
[50] = {132, 137, 136}, [51] = {48, 79, 69}, [52] = {77, 98, 104}, [53] = {22, 34, 72}, [54] = {39, 47, 75}, [55] = {125, 98, 86}, [56] = {158, 164, 171}, [57] = {156, 141, 113}, [58] = {109, 24, 34}, [59] = {78, 104, 129},
[60] = {156, 156, 152}, [61] = {145, 115, 71}, [62] = {102, 28, 38}, [63] = {148, 157, 159}, [64] = {164, 167, 165}, [65] = {142, 140, 70}, [66] = {52, 26, 30}, [67] = {106, 122, 140}, [68] = {170, 173, 142}, [69] = {171, 152, 143},
[70] = {133, 31, 46}, [71] = {111, 130, 151}, [72] = {88, 88, 83}, [73] = {154, 167, 144}, [74] = {96, 26, 35}, [75] = {32, 32, 44}, [76] = {164, 160, 150}, [77] = {170, 157, 132}, [78] = {120, 34, 43}, [79] = {14, 49, 109},
[80] = {114, 42, 63}, [81] = {123, 113, 94}, [82] = {116, 29, 40}, [83] = {30, 46, 50}, [84] = {77, 50, 47}, [85] = {124, 27, 68}, [86] = {46, 91, 32}, [87] = {57, 90, 131}, [88] = {109, 40, 55}, [89] = {167, 162, 143},
[90] = {175, 177, 177},[91] = {54, 65, 85},[92] = {109, 108, 110},[93] = {15, 106, 137},[94] = {32, 75, 107},[95] = {43, 62, 87},[96] = {155, 159, 157},[97] = {108, 132, 149},[98] = {77, 93, 96},[99] = {174, 155, 127},
[100] = {64, 108, 143}, [101] = {31, 37, 59}, [102] = {171, 146, 118}, [103] = {19, 69, 115}, [104] = {150, 129, 108}, [105] = {100, 104, 106}, [106] = {16, 80, 130}, [107] = {161, 153, 131}, [108] = {56, 86, 148}, [109] = {82, 86, 97},
[110] = {127, 105, 86}, [111] = {140, 146, 154}, [112] = {89, 110, 135}, [113] = {71, 53, 50}, [114] = {68, 98, 79}, [115] = {115, 10, 39}, [116] = {34, 52, 87}, [117] = {100, 13, 27}, [118] = {163, 173, 198}, [119] = {105, 88, 83},
[120] = {155, 139, 128}, [121] = {98, 11, 28}, [122] = {91, 93, 94}, [123] = {98, 68, 40}, [124] = {115, 24, 39}, [125] = {27, 55, 109}, [126] = {236, 106, 174}
}
-- setVehicleColorID(vehicle theVehicle, int color1 [, int color2])
function setVehicleColorID(theVehicle, color1, color2)
if (vehicle == nil or not getElementType(vehicle) == "vehicle") then
outputDebugString("setVehicleColorID argument #1: expected element type 'vehicle', got "..type(theVehicle), 1)
return false
end
if (not type(color1) == "number") then
outputDebugString("setVehicleColorID argument #2: expected type 'number', got "..type(color1), 1)
return false
end
if (not color2 == nil and type(color2) == "number") then
outputDebugString("setVehicleColorID argument #3: expected type 'number', got "..type(color2), 1)
return false
end
if (not math.floor(color1) == color1) then
outputDebugString("setVehicleColorID argument #2: float values are not accepted.")
return false
end
if (not color2 == nil and not math.floor(color2) == color2) then
outputDebugString("setVehicleColorID argument #3: float values are not accepted.")
return false
end
return setVehicleColor(theVehicle, saColorIds[color1][1], saColorIds[color1][2], saColorIds[color1][3], saColorIds[color2][1], saColorIds[color2][2], saColorIds[color2][3])
end
If you provide exactly four colors to setVehicleColor, it will use the palette colours.
Here is the old documentation for this (scroll down) https://wiki.multitheftauto.com/index.php?title=SetVehicleColor&oldid=45880
It is implemented here: https://github.com/multitheftauto/mtasa-blue/blob/master/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp#L1692-L1696
Does that help?
I understand, however, the current documentation doesn't have that information.
So, the first 3 parameters after the vehicle, in a row, means a palette color? What if they don't use the exactly colors from the palette? Unless they receive the color ID as the arguments, would the colors be correct? The wikia says that it receives the colors using a RGB format, and how would you know that it is a valid color ID, if, e.g, 126 is also a valid RGB value?
setVehicleColor (vehicle theVehicle, int r1, int g1, int b1)
I understand, however, the current documentation doesn't have that information.
Indeed, I don't know why that was removed from the wiki.
So, the first 3 parameters after the vehicle, in a row, means a palette color?
The first four* parameters, after the vehicle. If four colours are given, it knows to treat them as palette colours.
If a vehicle does not have four colours, you must still provide extra colours — it will only work if there are exactly 4 colours provided.
That means, there are five overloads for this function:
setVehicleColor(vehicle veh, int palette1, int palette2, int palette3, int palette4)setVehicleColor(vehicle veh, int r1, int g1, int b1)setVehicleColor(vehicle veh, int r1, int g1, int b1, int r2, int g2, int b2)setVehicleColor(vehicle veh, int r1, int g1, int b1, int r2, int g2, int b2, int r3, int g3, int b3)setVehicleColor(vehicle veh, int r1, int g1, int b1, int r2, int g2, int b2, int r3, int g3, int b3, int r4, int g4, int b4)The first four* parameters, after the vehicle. If four colours are given, it knows to treat them as palette colours.
Yeah, I just tested it out. You are right. I'll try to edit the wikia to add that clarification. :)
Okay, I added the change to the wikia. Thank you for answering me. :)
No worries, and thanks for updating the wiki!
Most helpful comment
If you provide exactly four colors to
setVehicleColor, it will use the palette colours.Here is the old documentation for this (scroll down) https://wiki.multitheftauto.com/index.php?title=SetVehicleColor&oldid=45880
It is implemented here: https://github.com/multitheftauto/mtasa-blue/blob/master/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp#L1692-L1696
Does that help?