Jump to content

Problem with team car color


explOdeR

Recommended Posts

Hey bros I have a problem with my script i made that but when i take a changuevehicle the team color changue to random colour please help

function onSetTeamColorToCar(thePlayer) 
            if isPedInVehicle (thePlayer) then 
                local hisTeam = getPlayerTeam(thePlayer) 
                if (hisTeam) then 
                    local r,g,b = getTeamColor(hisTeam) 
                    local hisVehicle = getPedOccupiedVehicle(thePlayer) 
                    setVehicleColor(hisVehicle,tonumber(r),tonumber(g),tonumber(b)) 
                else -- if player not have team then 
                    local r,g,b = math.random(255),math.random(255),math.random(255) 
                    local hisVehicle = getPedOccupiedVehicle(thePlayer) 
                    setVehicleColor(hisVehicle,r,g,b) 
                end 
            end 
        end 
      
    function onWaitingForLaggers() --Delay it a bit to allow players to warp in their vehicle 
        setTimer(onSetTeamColorToCar,2000,1,source) 
    end 
addEventHandler("onNotifyPlayerReady",getRootElement(),onWaitingForLaggers) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),onSetTeamColorToCar) 
addEventHandler("onPlayerReachCheckpoint",getRootElement(),onSetTeamColorToCar) 
addEventHandler("onResourceStart",getRootElement(),onSetTeamColorToCar) 

Link to comment
function onSetTeamColorToCar ( thePlayer ) 
    local hisVehicle = getPedOccupiedVehicle ( thePlayer ) 
    local hisTeam = getPlayerTeam ( thePlayer ) 
    if ( hisTeam ) then 
        local r, g, b = getTeamColor ( hisTeam )         
        setVehicleColor ( hisVehicle, r, g, b ) 
    else -- if player not have team then 
        local r, g, b = math.random ( 255 ), math.random ( 255 ), math.random ( 255 ) 
        setVehicleColor ( hisVehicle, r, g, b ) 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), onSetTeamColorToCar ) 
  
addEvent ( "onPlayerPickUpRacePickup", true ) 
addEventHandler ( "onPlayerPickUpRacePickup", getRootElement(), 
    function ( ) 
        onSetTeamColorToCar ( source ) 
    end 
) 
  
addEvent ( "onPlayerReachCheckpoint", true ) 
addEventHandler ( "onPlayerReachCheckpoint", getRootElement(), 
    function ( ) 
        onSetTeamColorToCar ( source ) 
    end 
) 

The first argument of 'onPlayerPickUpRacePickup' is the pickup ID.

The first argument 'onPlayerReachCheckpoint' is the checkpoint ID.

You forgot about addEvent.

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