Jump to content

[RACE]Team set vehicle color?


Admigo

Recommended Posts

Dear scripters,

I have a problem with this script:

function setTheCarColors( ) 
    local endteam = getTeamFromName( "END#" ) 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
        local theplayer = getVehicleOccupant( car ) 
        local nowteam = getPlayerTeam( theplayer ) 
        if theplayer then 
        if(nowteam == endteam) then 
                setVehicleColor(car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 
        end 
        end 
         
    end 
end 
addEvent("onVehColorChange",true) 
addEventHandler("onVehColorChange",getRootElement(),setTheCarColors) 
  
function timer() --Delay it a bit to allow players to warp in their vehicle... 
    setTimer(setTheCarColors,500,0) 
end 
addEventHandler("onMapStarting",getRootElement(),timer) 
addCommandHandler ( "set_vehicle_color", setTheCarColors ) 

I want that players is admin team get a yellow carpaint with a time of 500 so its detecting it.

But why this code dont work?

Thanks Admigo

Link to comment

onMapStarting is a custom event so you need to add; addEvent too.

But since you are never killing the timer, you dont need to put it inside that event.

function setTheCarColors( ) 
        local endteam = getTeamFromName( "END#" ) 
        for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
            local theplayer = getVehicleOccupant( car ) 
            local nowteam = getPlayerTeam( theplayer ) 
            if theplayer then 
            if(nowteam == endteam) then 
                    setVehicleColor(car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 
            end 
            end 
            
        end 
    end 
    addEvent("onVehColorChange",true) 
    addEventHandler("onVehColorChange",getRootElement(),setTheCarColors) 
      
    setTimer(setTheCarColors,500,0) 

Link to comment

Server side.

addEvent( "onVehColorChange",true ) 
addEvent( "onMapStarting",true ) 
  
function setTheCarColors( ) 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
        local theplayer = getVehicleOccupant( car ) 
        if isElement( theplayer ) then 
            local nowteam = getPlayerTeam( theplayer ) 
            local endteam = getTeamFromName( "END#" ) 
            if nowteam == endteam then 
                setVehicleColor( car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) 
            end 
        end 
    end 
end 
addEventHandler( "onVehColorChange",root,setTheCarColors ) 
  
function timer( ) --Delay it a bit to allow players to warp in their vehicle... 
    setTimer( setTheCarColors,500,0 ) 
end 
addEventHandler("onMapStarting",root,timer ) 
addCommandHandler ( "set_vehicle_color", setTheCarColors ) 

Link to comment
onMapStarting is a custom event so you need to add; addEvent too.

But since you are never killing the timer, you dont need to put it inside that event.

function setTheCarColors( ) 
        local endteam = getTeamFromName( "END#" ) 
        for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
            local theplayer = getVehicleOccupant( car ) 
            local nowteam = getPlayerTeam( theplayer ) 
            if theplayer then 
            if(nowteam == endteam) then 
                    setVehicleColor(car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 
            end 
            end 
            
        end 
    end 
    addEvent("onVehColorChange",true) 
    addEventHandler("onVehColorChange",getRootElement(),setTheCarColors) 
      
    setTimer(setTheCarColors,500,0) 

I get spam error:bad argument@GetPlayerTeam

How can i fix this?

Link to comment
addEvent( "onVehColorChange",true ) 
addEvent( "onMapStarting",true ) 
  
function setTheCarColors( ) 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
        local theplayer = getVehicleController( car ) 
        if (theplayer and isElement( theplayer )) then 
            local nowteam = getPlayerTeam( theplayer ) 
            local endteam = getTeamFromName( "END#" ) 
            if (nowteam == endteam) then 
                setVehicleColor( car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) 
            end 
        end 
    end 
end 
addEventHandler( "onVehColorChange",root,setTheCarColors ) 
  
function timer( ) --Delay it a bit to allow players to warp in their vehicle... 
    setTimer( setTheCarColors,500,0 ) 
end 
addEventHandler("onMapStarting",root,timer ) 
addCommandHandler ( "set_vehicle_color", setTheCarColors ) 

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