Jump to content

Happy new Year 2013 and help me


JoZeFSvK

Recommended Posts

Posted

Happy new year :) , i try create our colors and i have problem

i think when map start all cars will have this color red or green or yellow ...

function mapStart (startedResource) 
if getResourceInfo ( startedResource, "type" ) == "map" then 
setVehicleColor(vehicle, 255, 255, 255, 255, 255, 255) 
or 
setVehicleColor(vehicle, 0, 0, 0, 0, 0, 0) 
or 
setVehicleColor(vehicle, 255, 0, 0, 255, 0, 0) 
or 
setVehicleColor(vehicle, 0, 255, 0, 0, 255, 0) 
or 
setVehicleColor(vehicle, 0, 0, 255, 0, 0, 255) 
end 
end 
addEventHandler("onResourceStart",getRootElement(),mapStart) 

Posted
function mapStart(startedResource) 
    if getResourceInfo(startedResource, "type") == "map" then 
        local r1, g1, b1, r2, g2, b2 = math.random(255), math.random(255), math.random(255), math.random(255), math.random(255), math.random(255) 
        for i, vehicle in ipairs(getElementsByType("vehicle")) do 
            setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) 
        end 
    end 
end 
addEventHandler("onResourceStart", root, mapStart) 

Posted
hmm i see defalut colors :x

it's will sets a random color (same random color) for all vehicles whenever any map started.

Aren't that what you looking for? :roll:

Posted
colors = { 
    [1] = {255, 255, 255, 255, 255, 255}, 
    [2] = {0, 0, 0, 0, 0, 0}, 
    [3] = {255, 0, 0, 255, 0, 0}, 
    [4] = {0, 255, 0, 0, 255, 0}, 
    [5] = {0, 0, 255, 0, 0, 255} 
} 
  
function mapStart(startedResource) 
    if getResourceInfo(startedResource, "type") == "map" then 
        local r1, g1, b1, r2, g2, b2 = unpack(colors[math.random(#colors)]) 
        for i, vehicle in ipairs(getElementsByType("vehicle")) do 
            setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) 
        end 
    end 
end 
addEventHandler("onResourceStart", root, mapStart) 

Posted

ok :D .. so

- we have 3 cars and start map

- we see old carcolors

- we add script and start

- new map start and we see our colors car 1 = yellow 255,255,0 , car2 = red 255,0,0 car3 = blue 0,0,255

- we open script and see our colors which we see on server we can add new color or delete colors are in (RGB)

do you understand me ?

Posted

You mean that you don't want all cars have same color, but different color where you have put it in the script?

Posted
colors = { 
    [1] = {255, 255, 255, 255, 255, 255}, 
    [2] = {0, 0, 0, 0, 0, 0}, 
    [3] = {255, 0, 0, 255, 0, 0}, 
    [4] = {0, 255, 0, 0, 255, 0}, 
    [5] = {0, 0, 255, 0, 0, 255} 
} 
  
function mapStart(startedResource) 
    if getResourceInfo(startedResource, "type") == "map" then 
        for i, vehicle in ipairs(getElementsByType("vehicle")) do 
            local r1, g1, b1, r2, g2, b2 = unpack(colors[math.random(#colors)]) 
            setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) 
        end 
    end 
end 
addEventHandler("onResourceStart", root, mapStart) 

Posted
hmm i see again defalut colors

Then i guess you have other script that reset the colors.

but still i don't understand, the color will set when the map start, so where the hell is the problem?!

Are you sure you have it server-side?

What default colors are you talking about? can you post image?

Posted

Is it for race? then use this:

addEvent("onRaceStateChanging",true) 
addEventHandler("onRaceStateChanging",root, 
function (new, old) 
if (new == "GridCountdown") then 
    for i,v in pairs(getElementsByType("player")) do 
     
  local playerVehicle = getPedOccupiedVehicle(v) 
setVehicleColor ( playerVehicle, math.random(255), math.random(255), math.random(255), math.random(255), math.random(255), math.random(255) ) 
end 
end) 
  

Edit: and happy 2013! :)

Posted
addEventHandler ( "onResourceStart", root,  
    function ( theResource ) 
        if getResourceInfo ( theResource, "type") == "map" then 
            if isTimer ( theTimer ) then 
                killTimer ( theTimer )  
            end 
            setTimer (  
                function ( ) 
                    for _, theVehicles in ipairs ( getElementsByType ( "vehicle" ) ) do 
                        theTimer = setTimer ( startColors, 150, 0, theVehicles ) 
                    end 
                end 
            , 10000, 1 ) 
        end 
    end 
) 
  
function startColors ( theVehicles ) 
    local r1, g1, b1 = math.random(255), math.random(255), math.random(255) 
    local r2, g2, b2 = math.random(255), math.random(255), math.random(255) 
    setVehicleColor ( theVehicles, r1, g1, b1, r2, g2, b2 ) 
end 

Posted

for all of you that's just a big mistake :~O

you should use ( resourceRoot ) not ( root )

addEventHandler( 'onResourceStart', resourceRoot, 
    function ( thisResource ) 
        local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
        local r2, g2, b2 = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
        for _, vehicle in ipairs( getElementsByType( 'vehicle' ) ) do 
            setVehicleColor( vehicle, r, g, b, r2, g2, b2 ) 
        end 
    end 
) 

  • 4 weeks later...
Posted

Wow .. this code ..

addEventHandler( 'onResourceStart', resourceRoot, 
    function ( thisResource ) 
        local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
        local r2, g2, b2 = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
        for _, vehicle in ipairs( getElementsByType( 'vehicle' ) ) do 
            setVehicleColor( vehicle, r, g, b, r2, g2, b2 ) 
        end 
    end 
) 

When i restart script and restart , restart i see nice colors ... but when i cheange 'onResourceStart' for 'onRaceStateChanging' and restart map nothing i saw defalut colors :/ where will problem ?

Posted

edit work :) but when start map i see defalut color and after 1 second to develop a nice color how fix it ?

addEvent("onRaceStateChanging",true) 
addEventHandler("onRaceStateChanging",root, 
    function ( thisResource ) 
        local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
        local r2, g2, b2 = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
        for _, vehicle in ipairs( getElementsByType( 'vehicle' ) ) do 
            setVehicleColor( vehicle, r, g, b, r2, g2, b2 ) 
        end 
    end 
) 

Posted
addEvent ( "onRaceStateChanging", true ) 
addEventHandler ( "onRaceStateChanging", root, 
    function ( ) 
        if isTimer ( theTimer ) then killTimer ( theTimer ) end 
        theTimer = setTimer ( 
            function ( ) 
                local r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
                local r2, g2, b2 = math.random( 255 ), math.random( 255 ), math.random( 255 ) 
                for _, vehicle in ipairs ( getElementsByType( "vehicle" ) ) do 
                    setVehicleColor ( vehicle, r, g, b, r2, g2, b2 ) 
                end 
            end 
        , 500, 0 ) 
    end 
) 

Posted

If you are using Race resource, you better change vehicle colors. So go to resource panel -> race (double click) -> (scrolldown) Vechile colors -> change from random to file.

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