Jump to content

Happy new Year 2013 and help me


JoZeFSvK

Recommended Posts

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) 

Link to comment
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) 

Link to comment
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) 

Link to comment

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 ?

Link to comment
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) 

Link to comment
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?

Link to comment

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! :)

Link to comment
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 

Link to comment

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 
) 

Link to comment
  • 4 weeks later...

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 ?

Link to comment

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 
) 

Link to comment
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 
) 

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