JoZeFSvK Posted December 31, 2012 Share Posted December 31, 2012 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
3NAD Posted December 31, 2012 Share Posted December 31, 2012 setVehicleColor ( vehicle, math.random( 255 ), math.random( 255 ), math.random( 255 ) ) Link to comment
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 i try but dont work Link to comment
TAPL Posted December 31, 2012 Share Posted December 31, 2012 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
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 hmm i see defalut colors Link to comment
TAPL Posted December 31, 2012 Share Posted December 31, 2012 hmm i see defalut colors it's will sets a random color (same random color) for all vehicles whenever any map started. Aren't that what you looking for? Link to comment
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 i think when start map i see on vehicles colors which i write in script Link to comment
TAPL Posted December 31, 2012 Share Posted December 31, 2012 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
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 again i see all colors but this in script no Link to comment
TAPL Posted December 31, 2012 Share Posted December 31, 2012 Can you explain in better way what you really want to do? because i am confused. Link to comment
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 ok .. 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
TAPL Posted December 31, 2012 Share Posted December 31, 2012 You mean that you don't want all cars have same color, but different color where you have put it in the script? Link to comment
TAPL Posted December 31, 2012 Share Posted December 31, 2012 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
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 hmm i see again defalut colors Link to comment
TAPL Posted December 31, 2012 Share Posted December 31, 2012 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
JoZeFSvK Posted December 31, 2012 Author Share Posted December 31, 2012 its is server side and i have only this 1 script in server Link to comment
denny199 Posted December 31, 2012 Share Posted December 31, 2012 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
3NAD Posted January 1, 2013 Share Posted January 1, 2013 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
Blaawee Posted January 1, 2013 Share Posted January 1, 2013 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
JoZeFSvK Posted January 27, 2013 Author Share Posted January 27, 2013 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
JoZeFSvK Posted January 27, 2013 Author Share Posted January 27, 2013 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
JoZeFSvK Posted January 27, 2013 Author Share Posted January 27, 2013 problem 2. carcolor is cheange 2x while 1 sec start map .. i see defalut then cheange color and then again chenage color .. Link to comment
3NAD Posted January 27, 2013 Share Posted January 27, 2013 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
h4x7o0r Posted January 27, 2013 Share Posted January 27, 2013 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now