WolfPire Posted March 13, 2012 Posted March 13, 2012 So i'm doing a special garage which will give your vehicle a random color every second aswell for your nametag. All's going good, until we go to the serverside script. It will just give me 2 colors, and i want it to randomize R, G, B as i'm ordering. Any idea why this script is trolling me? Client WTF = createMarker(2610, 1451, 11, "cylinder", 3, 0, 0, 0, root) function randomiseMarkerColor() r = math.random(0,255) g = math.random(0,255) b = math.random(0,255) setMarkerColor( WTF, r, g, b, 255) end addEventHandler("onClientRender",root, randomiseMarkerColor) function WTFEnt( hitPlayer ) if hitPlayer == localPlayer then if not (nyan) then if isPedOnGround( hitPlayer ) then pVehicleSG = getPedOccupiedVehicle( hitPlayer ) if pVehicleSG then fadeCamera( false, 1.0, 0, 0, 0 ) setElementFrozen(pVehicleSG,true) nyan = playSound("nyan.mp3",true) setTimer(fadeCamera, 2000, 1, true, 1.0 ) triggerServerEvent("carCol",root, pVehicleSG) setTimer(setElementFrozen,1300,1,pVehicleSG,false) setTimer(setElementPosition,2000, 1, pVehicleSG, 2611, 1431, 11) setTimer(destroyElement,1000000,1,nyan) end end else outputChatBox("Too much magic for you pal.", 255, 0, 0) end end end addEventHandler("onClientMarkerHit", root, WTFEnt) _____________________________________________________ Server addEvent("carCol",true) addEventHandler("carCol",root, function(pVehicleSG) setTimer(setVehicleColor, 1000, 1000, pVehicleSG, math.random(0,255), math.random(0,255), math.random(0,255)) setTimer(setPlayerNametagColor, 1000, 1000, getVehicleController(pVehicleSG), math.random(0,255), math.random(0,255), math.random(0,255)) end ) ~ WolfPire ~ ''Overcome your own limits ~'' 日本語もできますよ!
Castillo Posted March 13, 2012 Posted March 13, 2012 I'm not sure if I get what do you mean, what do you mean by: "It will just give me 2 colors"? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Aibo Posted March 13, 2012 Posted March 13, 2012 if you mean that the car and name get different color and you want the same for both — you need to assign the same color: addEvent("carCol",true) addEventHandler("carCol",root, function(pVehicleSG) local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255) setTimer(setVehicleColor, 1000, 1000, pVehicleSG, r,g,b) setTimer(setPlayerNametagColor, 1000, 1000, getVehicleController(pVehicleSG), r,g,b) end ) ?
WolfPire Posted March 13, 2012 Author Posted March 13, 2012 I know, thanks Aibo! Solid... Umm i think you didn't quite get me... When "math.random(0,255)" is triggered. IT will just give me 2 colors per 2 timers and repeat itself over and over. ~ WolfPire ~ ''Overcome your own limits ~'' 日本語もできますよ!
Aibo Posted March 13, 2012 Posted March 13, 2012 colors dont change because all the values for arguments passed to the timer/function are evaluated before timer starts. so you need to randomize the color in the function that is called by timer. function randomColors(pVehicleSG) local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255) setVehicleColor(pVehicleSG, r, g, b) setPlayerNametagColor(getVehicleController(pVehicleSG), r, g, b) end addEvent("carCol",true) addEventHandler("carCol", root, function(pVehicleSG) setTimer(randomColors, 1000, 1000, pVehicleSG) end ) ?
WolfPire Posted March 13, 2012 Author Posted March 13, 2012 colors dont change because all the values for arguments passed to the timer/function are evaluated before timer starts.so you need to randomize the color in the function that is called by timer. function randomColors(pVehicleSG) local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255) setVehicleColor(pVehicleSG, r, g, b) setPlayerNametagColor(getVehicleController(pVehicleSG), r, g, b) end addEvent("carCol",true) addEventHandler("carCol", root, function(pVehicleSG) setTimer(randomColors, 1000, 1000, pVehicleSG) end ) That was exactly on my mind, just that i didn't really know how to fix it, as i tried so many ways to update values. Thanks, it works like a charm, Aibo =3 (Your name means "buddy" or "pal" in Japanese by the way, i think... n_n) And, aswell thanks like always... Solid. ~ WolfPire ~ ''Overcome your own limits ~'' 日本語もできますよ!
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