Jump to content

Car color


extlatvia

Recommended Posts

Hey, i want set to my team car color . i use auto teams.

And i want a set car color for me only or other player. can give or tell how make that.?

  
function vehiclepaint(player,seat) 
    if (seat == 0 and getPlayerTeam(player)) then 
        local r,g,b = getTeamColor(getPlayerTeam(player)) 
        setVehicleColor(source,r,g,b,0,0,0) 
    end 
end 
addEventHandler("onVehicleEnter",getRootElement(),vehiclepaint) 
  
addCommandHandler("addteam", 
    function(source, cmd, clantag, color, ...) 
        local name = {...} 
        if not name[1] then 
            outputChatBox("syntax: "..cmd.." ", source) 
            return 
        end 
        local r,g,b = getColorFromString(color) 
        if not r then 
            outputChatBox(cmd..": invalid color code", source) 
            return 
        end 
        name = table.concat(name, ' ') 
        local config = xmlLoadFile("config.xml") 
--      local config = getResourceConfig("config.xml") 
        local teamset, teamname 
        for name,settings in next,teams do 
            if settings.tag == clantag then 
                teamset, teamname = settings, name 
                break 
            end 
        end 
        if teamset then 
            local name_differs, color_differs 
            local c = teamset.color 
            local t = getTeamFromName(teamname) 
            if c[1] ~= r or c[2] ~= g or c[3] ~= b then 
                teamset.color = {r,g,b} 
                color_differs = true 
                if t then setTeamColor(t, r, g, b)end 
            end 
            if teamname ~= name then 
                name_differs = true 
            end 
            if color_differs or name_differs then 
                for k,child in next,xmlNodeGetChildren(config)do 
                    if xmlNodeGetAttribute(child, "tag") == clantag then 
                        if color_differs then 
                            xmlNodeSetAttribute(child, "color", string.format("#%02X%02X%02X", r, g, b)) 
                        end 
                        if name_differs then 
                            xmlNodeSetAttribute(child, "name", name) 
                        end 
                        break 
                    end 
                end 
            end 

Here is code from script. And when start map in Race gamemode i have car color gold and black, but when i change car its a some other color and i want to gold and black color stay all time.

Link to comment

try this:

addEventHandler("onVehicleEnter",root,function(plyer,seat,jacked) 
    if(plyer)then 
    if(seat == 0) then 
        r,g,b=getTeamColor(getPlayerTeam(plyer)) 
        setVehicleColor(getPedOccupiedVehicle(plyer),r,g,b) 
    end 
    end 
end) 

Edited by Guest
Link to comment
function vehiclepaint ( player, seat ) 
    if ( seat == 0 and getPlayerTeam ( player ) ) then 
        local r,g,b = getTeamColor ( getPlayerTeam ( player ) ) 
        setVehicleColor ( source, r, g, b, 0, 0, 0 ) 
    end 
end 
addEventHandler ( "onVehicleEnter",root, vehiclepaint ) 
  
addEvent ( "onPlayerPickUpRacePickup", true ) 
addEventHandler ( "onPlayerPickUpRacePickup", root, 
    function ( pickupID, pickupType, vehicleModel ) 
        if ( pickupType == "vehiclechange" and getPlayerTeam ( source ) ) then 
            local r, g, b = getTeamColor ( getPlayerTeam ( source ) ) 
            setVehicleColor ( getPedOccupiedVehicle ( source ), r, g, b, 0, 0, 0 ) 
        end 
    end 
) 
  
addCommandHandler("addteam", 
    function(source, cmd, clantag, color, ...) 
        local name = {...} 
        if not name[1] then 
            outputChatBox("syntax: "..cmd.." ", source) 
            return 
        end 
        local r,g,b = getColorFromString(color) 
        if not r then 
            outputChatBox(cmd..": invalid color code", source) 
            return 
        end 
        name = table.concat(name, ' ') 
        local config = xmlLoadFile("config.xml") 
--      local config = getResourceConfig("config.xml") 
        local teamset, teamname 
        for name,settings in next,teams do 
            if settings.tag == clantag then 
                teamset, teamname = settings, name 
                break 
            end 
        end 
        if teamset then 
            local name_differs, color_differs 
            local c = teamset.color 
            local t = getTeamFromName(teamname) 
            if c[1] ~= r or c[2] ~= g or c[3] ~= b then 
                teamset.color = {r,g,b} 
                color_differs = true 
                if t then setTeamColor(t, r, g, b)end 
            end 
            if teamname ~= name then 
                name_differs = true 
            end 
            if color_differs or name_differs then 
                for k,child in next,xmlNodeGetChildren(config)do 
                    if xmlNodeGetAttribute(child, "tag") == clantag then 
                        if color_differs then 
                            xmlNodeSetAttribute(child, "color", string.format("#%02X%02X%02X", r, g, b)) 
                        end 
                        if name_differs then 
                            xmlNodeSetAttribute(child, "name", name) 
                        end 
                        break 
                    end 
                end 
            end 
        end 
    end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...