Getting a vehicle colour in text form?

Does anyone know how I can get a vehicles colour in text? Say I check a car and it returns the string ‘blue’. I understand I can do this with RGB values but is there any other simpler way i’m missing by any chance? So far ive got this:

local r, g, b = GetVehicleCustomPrimaryColour(veh)
if r > 150 and g < 100 and b < 100 then
colourText = ‘red’
elseif g > 150 and r < 100 and b < 100 then
colourText = ‘green’
elseif b > 150 and r < 100 and g < 100 then
colourText = ‘blue’
elseif r > 150 and b > 150 and g > 150 then
colourText = ‘white’
elseif r < 50 and g < 50 and b < 50 then
colourText = ‘black’
else then
colourText = ’ ’
end

1 Like

How are you getting the vehicle’s color in the first place?

Have you tried using these natives?
https://runtime.fivem.net/doc/reference.html#_0xB45085B721EFD38C GetVehicleModColor_1Name()
https://runtime.fivem.net/doc/reference.html#_0x4967A516ED23A5A1 GetVehicleModColor_2Name()

I haven’t tested it myself but apparently those return the actual color names for the primary and secondary vehicle paint colors.

I literally had no idea that that’s what those methods did! I thought they were something to do with the vehicles los santos customs mod rather than anything else, thanks so much :D. Also I was using something like GetVehicleCustomPrimaryColour or something like that.

Np, glad they are the ones you’re looking for.

I tried using one of the natives, the one for the vehicles primary colour, and it gives me a LUA error? Heres a picture of the console and my raw code. Currently trying to edit simpleoutlawalert to work with a number plate, colour etc.

You can see that the vehicle ‘Sultan’ was picked up and the Plate was too.

Citizen.CreateThread( function()
    while true do
        Wait(0)
        local plyPos = GetEntityCoords(GetPlayerPed(-1),  true)
        local s1, s2 = Citizen.InvokeNative( 0x2EB41072B4C1E4C0, plyPos.x, plyPos.y, plyPos.z, Citizen.PointerValueInt(), Citizen.PointerValueInt() )
        local street1 = GetStreetNameFromHashKey(s1)
        local street2 = GetStreetNameFromHashKey(s2)
        if IsPedInAnyVehicle(GetPlayerPed(-1)) then
            if IsVehicleNeedsToBeHotwired(GetVehiclePedIsIn(GetPlayerPed(-1))) or IsPedJacking(GetPlayerPed(-1)) then
                origin = true
                DecorSetInt(GetPlayerPed(-1), "IsOutlaw", 2)
                local male = IsPedMale(GetPlayerPed(-1))
                if male then
                    sex = "Male"
                elseif not male then
                    sex = "Female"
                end
                TriggerServerEvent('thiefJackInProgressPos', plyPos.x, plyPos.y, plyPos.z)
                local veh = GetVehiclePedIsIn(GetPlayerPed(-1))
                local vehName2 = GetDisplayNameFromVehicleModel(GetEntityModel(veh))
		print(vehName2)
		local plate = GetVehicleNumberPlateText(veh)
		local colourText = GetVehicleModColor_1Name(veh, 0)
                if s2 == 0 then
                    TriggerServerEvent('thiefJackInProgressS1', street1, vehName2, sex, plate, colourText)
                elseif s2 ~= 0 then
                    TriggerServerEvent('thiefJackInProgressS1', street1, vehName2, sex, plate, colourText)
                end
                Wait(1)
                origin = false
            end
        end
    end
end)

Heres the Server and other client parts that are called:

RegisterNetEvent('thiefJackPlace')
AddEventHandler('thiefJackPlace', function(tx, ty, tz)
            if carJackingAlert then
                local transT = 250
                local thiefBlip = AddBlipForCoord(tx, ty, tz)
                SetBlipSprite(thiefBlip,  10)
                SetBlipColour(thiefBlip,  1)
                SetBlipAlpha(thiefBlip,  transT)
                SetBlipAsShortRange(thiefBlip,  1)
                while transT ~= 0 do
                    Wait(blipJackingTime * 4)
                    transT = transT - 1
                    SetBlipAlpha(thiefBlip,  transT)
                    if transT == 0 then
                        SetBlipSprite(thiefBlip,  2)
                        return end
                end
                
            end
end)
RegisterServerEvent('thiefJackInProgress')
AddEventHandler('thiefJackInProgress', function(street1, street2, veh, sex, plate, colour)
	if veh == "NULL" then
		TriggerClientEvent("outlawNotify", -1, "~r~GTA of of a ~w~"..colour.."~r~ vehicle by a ~w~"..sex.." ~r~between ~w~"..street1.."~r~ and ~w~"..street2.."~r~ with plate ~w~"..plate)
	else
		TriggerClientEvent("outlawNotify", -1, "~r~GTA of of a ~w~"..colour.."~r~ ~w~"..veh.." ~r~by a ~w~"..sex.." ~r~between ~w~"..street1.."~r~ and ~w~"..street2.."~r~ with plate ~w~"..plate)
	end
end)

RegisterServerEvent('thiefJackInProgressS1')
AddEventHandler('thiefJackInProgressS1', function(street1, veh, sex, plate, colour)
	if veh == "NULL" then
		TriggerClientEvent("outlawNotify", -1, "~r~GTA of a ~w~"..colour.."~r~ vehicle  by a ~w~"..sex.." ~r~at ~w~"..street1.."~r~ with plate ~w~"..plate)
	else
		TriggerClientEvent("outlawNotify", -1, "~r~GTA of a ~w~"..colour.."~r~ ~w~"..veh.." ~r~by a ~w~"..sex.." ~r~at ~w~"..street1.."~r~ with plate ~w~"..plate)
	end
end)

Thanks in advance :smiley:

Yeah it seems the function always returns nil so that’s not going to work. You can however create a list of vehicle color ID’s (see here) and then get the color from the array. See the example below. (Not sure if the color list is 100% complete/accurate but it’s the best I could find. Also this isn’t the most perfect way to do this since you’re creating an array and stuffing it with a lot of colors when you may not even use them, but as long as the natives don’t work I don’t see a better solution…)

local colorNames = {
    ['0'] = "Metallic Black",
    ['1'] = "Metallic Graphite Black",
    ['2'] = "Metallic Black Steal",
    ['3'] = "Metallic Dark Silver",
    ['4'] = "Metallic Silver",
    ['5'] = "Metallic Blue Silver",
    ['6'] = "Metallic Steel Gray",
    ['7'] = "Metallic Shadow Silver",
    ['8'] = "Metallic Stone Silver",
    ['9'] = "Metallic Midnight Silver",
    ['10'] = "Metallic Gun Metal",
    ['11'] = "Metallic Anthracite Grey",
    ['12'] = "Matte Black",
    ['13'] = "Matte Gray",
    ['14'] = "Matte Light Grey",
    ['15'] = "Util Black",
    ['16'] = "Util Black Poly",
    ['17'] = "Util Dark silver",
    ['18'] = "Util Silver",
    ['19'] = "Util Gun Metal",
    ['20'] = "Util Shadow Silver",
    ['21'] = "Worn Black",
    ['22'] = "Worn Graphite",
    ['23'] = "Worn Silver Grey",
    ['24'] = "Worn Silver",
    ['25'] = "Worn Blue Silver",
    ['26'] = "Worn Shadow Silver",
    ['27'] = "Metallic Red",
    ['28'] = "Metallic Torino Red",
    ['29'] = "Metallic Formula Red",
    ['30'] = "Metallic Blaze Red",
    ['31'] = "Metallic Graceful Red",
    ['32'] = "Metallic Garnet Red",
    ['33'] = "Metallic Desert Red",
    ['34'] = "Metallic Cabernet Red",
    ['35'] = "Metallic Candy Red",
    ['36'] = "Metallic Sunrise Orange",
    ['37'] = "Metallic Classic Gold",
    ['38'] = "Metallic Orange",
    ['39'] = "Matte Red",
    ['40'] = "Matte Dark Red",
    ['41'] = "Matte Orange",
    ['42'] = "Matte Yellow",
    ['43'] = "Util Red",
    ['44'] = "Util Bright Red",
    ['45'] = "Util Garnet Red",
    ['46'] = "Worn Red",
    ['47'] = "Worn Golden Red",
    ['48'] = "Worn Dark Red",
    ['49'] = "Metallic Dark Green",
    ['50'] = "Metallic Racing Green",
    ['51'] = "Metallic Sea Green",
    ['52'] = "Metallic Olive Green",
    ['53'] = "Metallic Green",
    ['54'] = "Metallic Gasoline Blue Green",
    ['55'] = "Matte Lime Green",
    ['56'] = "Util Dark Green",
    ['57'] = "Util Green",
    ['58'] = "Worn Dark Green",
    ['59'] = "Worn Green",
    ['60'] = "Worn Sea Wash",
    ['61'] = "Metallic Midnight Blue",
    ['62'] = "Metallic Dark Blue",
    ['63'] = "Metallic Saxony Blue",
    ['64'] = "Metallic Blue",
    ['65'] = "Metallic Mariner Blue",
    ['66'] = "Metallic Harbor Blue",
    ['67'] = "Metallic Diamond Blue",
    ['68'] = "Metallic Surf Blue",
    ['69'] = "Metallic Nautical Blue",
    ['70'] = "Metallic Bright Blue",
    ['71'] = "Metallic Purple Blue",
    ['72'] = "Metallic Spinnaker Blue",
    ['73'] = "Metallic Ultra Blue",
    ['74'] = "Metallic Bright Blue",
    ['75'] = "Util Dark Blue",
    ['76'] = "Util Midnight Blue",
    ['77'] = "Util Blue",
    ['78'] = "Util Sea Foam Blue",
    ['79'] = "Uil Lightning blue",
    ['80'] = "Util Maui Blue Poly",
    ['81'] = "Util Bright Blue",
    ['82'] = "Matte Dark Blue",
    ['83'] = "Matte Blue",
    ['84'] = "Matte Midnight Blue",
    ['85'] = "Worn Dark blue",
    ['86'] = "Worn Blue",
    ['87'] = "Worn Light blue",
    ['88'] = "Metallic Taxi Yellow",
    ['89'] = "Metallic Race Yellow",
    ['90'] = "Metallic Bronze",
    ['91'] = "Metallic Yellow Bird",
    ['92'] = "Metallic Lime",
    ['93'] = "Metallic Champagne",
    ['94'] = "Metallic Pueblo Beige",
    ['95'] = "Metallic Dark Ivory",
    ['96'] = "Metallic Choco Brown",
    ['97'] = "Metallic Golden Brown",
    ['98'] = "Metallic Light Brown",
    ['99'] = "Metallic Straw Beige",
    ['100'] = "Metallic Moss Brown",
    ['101'] = "Metallic Biston Brown",
    ['102'] = "Metallic Beechwood",
    ['103'] = "Metallic Dark Beechwood",
    ['104'] = "Metallic Choco Orange",
    ['105'] = "Metallic Beach Sand",
    ['106'] = "Metallic Sun Bleeched Sand",
    ['107'] = "Metallic Cream",
    ['108'] = "Util Brown",
    ['109'] = "Util Medium Brown",
    ['110'] = "Util Light Brown",
    ['111'] = "Metallic White",
    ['112'] = "Metallic Frost White",
    ['113'] = "Worn Honey Beige",
    ['114'] = "Worn Brown",
    ['115'] = "Worn Dark Brown",
    ['116'] = "Worn straw beige",
    ['117'] = "Brushed Steel",
    ['118'] = "Brushed Black steel",
    ['119'] = "Brushed Aluminium",
    ['120'] = "Chrome",
    ['121'] = "Worn Off White",
    ['122'] = "Util Off White",
    ['123'] = "Worn Orange",
    ['124'] = "Worn Light Orange",
    ['125'] = "Metallic Securicor Green",
    ['126'] = "Worn Taxi Yellow",
    ['127'] = "police car blue",
    ['128'] = "Matte Green",
    ['129'] = "Matte Brown",
    ['130'] = "Worn Orange",
    ['131'] = "Matte White",
    ['132'] = "Worn White",
    ['133'] = "Worn Olive Army Green",
    ['134'] = "Pure White",
    ['135'] = "Hot Pink",
    ['136'] = "Salmon pink",
    ['137'] = "Metallic Vermillion Pink",
    ['138'] = "Orange",
    ['139'] = "Green",
    ['140'] = "Blue",
    ['141'] = "Mettalic Black Blue",
    ['142'] = "Metallic Black Purple",
    ['143'] = "Metallic Black Red",
    ['144'] = "hunter green",
    ['145'] = "Metallic Purple",
    ['146'] = "Metaillic V Dark Blue",
    ['147'] = "MODSHOP BLACK1",
    ['148'] = "Matte Purple",
    ['149'] = "Matte Dark Purple",
    ['150'] = "Metallic Lava Red",
    ['151'] = "Matte Forest Green",
    ['152'] = "Matte Olive Drab",
    ['153'] = "Matte Desert Brown",
    ['154'] = "Matte Desert Tan",
    ['155'] = "Matte Foilage Green",
    ['156'] = "DEFAULT ALLOY COLOR",
    ['157'] = "Epsilon Blue",
}

local ped = PlayerPedId()
local veh = GetVehiclePedIsIn(ped, false)

-- Value between 0 and 157
local primary, secondary = GetVehicleColours(veh)
primary = colorNames[tostring(primary)]
secondary = colorNames[tostring(secondary)]

Which could look like this if you formatted a print for example:

6 Likes

Thank you so much! I’ll try to implement this.

It works perfectly, I had to change some things to make it fit but omg thank you :smiley:

Vespura, where did you find all of the names for the colour IDs? I’m currently trying to create a system that requires the use of colours and the names of them.