isa_Khamdan Posted July 9, 2013 Posted July 9, 2013 Hmm I am wondering if I can make the car color change every 0.5 second for a selected player serial . anyway this code works but for all cars how can I bind it for a player serial? function randomVehColors() for i, car in ipairs( getElementsByType( "vehicle" ) ) do local color = {} color[1] = math.random(0,126) color[2] = math.random(0,126) color[3] = math.random(0,126) color[4] = math.random(0,126) setVehicleColor ( car, color[1], color[2], color[3], color[4] ) end end setTimer( randomVehColors, 500, 0 )
itoko Posted July 9, 2013 Posted July 9, 2013 Hope that's what you asked for: local theSerial = "putyourserialhere" function randomVehColors() for _,player in ipairs(getElementsByType("player")) do if getPlayerSerial(player) == theSerial then if isPedInVehicle(player) then local car = getPedOccupiedVehicle(player) local color = {} color[1] = math.random(0,126) color[2] = math.random(0,126) color[3] = math.random(0,126) color[4] = math.random(0,126) setVehicleColor ( car, color[1], color[2], color[3], color[4] ) end end end end setTimer( randomVehColors, 500, 0 )
isa_Khamdan Posted July 9, 2013 Author Posted July 9, 2013 Thanks a lot it works great but how can I choose the car? cuz I don't want it to change the colors randomly in every car that the selected player drive
itoko Posted July 9, 2013 Posted July 9, 2013 (edited) Here you go: local theSerial = "" -- put the serial of the player local theCar = 411 -- put the ID of the car function randomVehColors() for _,player in ipairs(getElementsByType("player")) do if getPlayerSerial(player) == theSerial then if isPedInVehicle(player) then local car = getPedOccupiedVehicle(player) if getElementModel(car) == theCar then local color = {} color[1] = math.random(0,126) color[2] = math.random(0,126) color[3] = math.random(0,126) color[4] = math.random(0,126) setVehicleColor ( car, color[1], color[2], color[3], color[4] ) end end end end end setTimer( randomVehColors, 500, 0 ) Edited July 9, 2013 by Guest
xXMADEXx Posted July 9, 2013 Posted July 9, 2013 You accidentally put the ID, not variable here. if getElementModel(car) == theCar then
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