Jump to content

Make a team, color car


Spyke25

Recommended Posts

Hello.

I made a script it make 2 teams.

I would to know how i can set a color at the car when a player join the team.

For example, i have a red team, when i join this team i will have a red car automatically ( race server ).

Can someone help me ?

Thanks in advance. :)

Link to comment
Ok, thanks.

But im a beginner of lua scripting, so i ask you if that's right :

    teamName = createTeam ( "Name", 255, 0, 0 ) 
setVehicleColor ( playerVehicle, col1, col2, col3, col4 ) 

Try it and you will know, if you got any errors , post them here :D

Link to comment

You mean this?

  
local teamName 
teamName = createTeam ( "Name", 255, 0, 0 ) 
col1, col2, col3 = getTeamColor ( teamName ) 
setVehicleColor ( playerVehicle, col1 or 0, col2 or 0, col3 or 0 , 0 ) 

Example:

  
local teamName,col1,col2,col3     
teamName = createTeam ( "Name", 255, 0, 0 ) 
  
  
function setColors() 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
        local col1,col2,col3     
        col1, col2, col3 = getTeamColor ( teamName ) 
        setVehicleColor ( car, col1 or 0, col2 or 0, col3 or 0 , 0 ) 
    end 
end 
  
setTimer( setColors, 500, 0 ) 
  

Edited by Guest
Link to comment
Ok, thanks.

But im a beginner of lua scripting, so i ask you if that's right :

    teamName = createTeam ( "Name", 255, 0, 0 ) 
setVehicleColor ( playerVehicle, col1, col2, col3, col4 ) 

Sorry, i can't let him fail, that Won't do as you want, sorry capy, but he had to know one way or another.

Umm, what ?

Link to comment
How i can set the color i want?

For example, if i want to give a yellow color at car, what i need to change in your code?

  
setVehicleColor( 
  car, -- vehicle variable 
  255, -- color red 
  255, -- color green 
  0, -- color blue 
  0  
) 
  

Link to comment

Ok then,

is this right?

function createTeamsOnStart () 
local teamName,col1,col2,col3     
    teamGyg = createTeam ( "~GYG~", 255, 255, 0 )  
  
  
function setColors() 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
        local col1,col2,col3     
        col1, col2, col3 = getTeamColor ( teamName ) 
        setVehicleColor ( car,  255,  255,  0 , 0 ) 
    end 
end 
  
setTimer( setColors, 500, 0 ) 

Link to comment

This correct

  
local teamGyg 
    teamGyg = createTeam ( "~GYG~", 255, 255, 0 )  
  
  
function setColors() 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
       local col1,col2,col3     
       col1, col2, col3 = getTeamColor ( teamGyg ) 
        setVehicleColor ( car,  col1 or 0,  col2 or 0,  col3 or 0, 0 ) 
    end 
end 
  
setTimer( setColors, 500, 0 ) 

Link to comment

Syntax:

bool setVehicleColor ( vehicle theVehicle, int r1, int g1, int b1 ) 

r1, g1, b1: Three integers indicating the red, green and blue components of the first (main) color for the vehicle

So yellow is 255 , 255 , 0

local teamGyg = createTeam ( "~GYG~", 255, 255, 0 ) 
  
  
function setColors() 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
       --local col1, col2, col3 = getTeamColor ( teamGyg ) 
        setVehicleColor ( car,  255 , 255 , 0 ) 
    end 
end 
  
setTimer( setColors, 500, 0 ) 

Link to comment

For example

function randomVehColors() 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
        local color = {} 
        color[1] = math.random(0,126) -- random from 0 to 126, because colors is from 0 to 126 
        color[2] = math.random(0,126) 
        color[3] = math.random(0,126) 
        color[4] = math.random(0,126) -- we take 4 random numbers because setVehicleColor have parameters with 4 colors 
        setVehicleColor ( car, color[1], color[2], color[3], color[4] ) -- setting color to vehicle 
    end 
end 
  
setTimer( randomVehColors, 500, 0 ) -- timer changes all vehicles colors to random every 0.5 sec. 

:wink:

Link to comment

Ok thanks, but with this code :

local teamGyg = createTeam ( "~GYG~", 255, 255, 0 ) 
  
  
function setColors() 
    for i, car in ipairs( getElementsByType( "vehicle" ) ) do 
       --local col1, col2, col3 = getTeamColor ( teamGyg ) 
        setVehicleColor ( car,  255 , 255 , 0 ) 
    end 
end 
  
setTimer( setColors, 500, 0 ) 

ALL the vehicles are yellow and black, and not ONLY the vehicles of the team member. How i can fix ?

Link to comment

You must get the team vehicles variable, ways of doing this:

getElementByID 
-- 
setElementData 
getElementData 

If you have a table with the team vehicles then:

function setColors() 
    for i, car in ipairs( teamVehicles ) do 
        setVehicleColor ( car,  255 , 255 , 0 ) 
    end 
end 
 setColors() 
--setTimer( setColors, 500, 0 ) 

Link to comment

I have errors with this :

local teamGyg = createTeam ( "~GYG~", 255, 255, 0 ) 
  
  
function setColors() 
    for i, car in ipairs( teamVehicles ) do 
       --local col1, col2, col3 = getTeamColor ( teamGyg ) 
        setVehicleColor ( car,  255 , 255 , 0 ) 
    end 
end 
  
setTimer( setColors, 500, 0 ) 

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