## Recommended Posts

Hi.

i am create vehicles by map editor and import to folder Maps ragemp server :

all cars black color !!??

`How to randomize colors Cars (vehicle) auto?`

##### Share on other sites

Well here's the vehicle function (Read more here: https://wiki.rage.mp/index.php?title=Vehicle::Vehicle)

```mp.vehicles.new(model, position,
{
numberPlate: numberPlate,
alpha: alpha,
color: color,
locked: locked,
engine: engine,
dimension: dimension
});```

And this is how you generate random numbers between 1 and 10

`Math.floor((Math.random() * 10) + 1);`

All you have to do is put that together so it picks a random number and you're done.

##### Share on other sites

On 9/9/2018 at 12:35 PM, MrPancakers said:

Well here's the v﻿ehicle function (Read more here: https://wiki.rage.mp/index.php?title=Vehicle::Vehicle)

```
mp.vehicles.new(model, position,
{
numberPlate: numberPlate,
alpha: alpha,
color: color,
locked: locked,
engine: engine,
dimension: dimension
});```

And this is how you generate﻿ random numbers between 1 and 10

```
Math.floor((Math.random() * 10) + 1);```

All you have to do is put that together so it picks a random number and you're done.﻿

please send example code for vehicle random color?

##### Share on other sites

```
function Randomize(Minimal, Maximum) { // functinon randomizer =D
let randomized = Math.floor((Math.random() * Maximum) + Minimal);
return randomized;
}

mp.vehicles.new(model, position, // structure create vehicle...
{
color: [[Randomize(1, 255), Randomize(1, 255), Randomize(1, 255)][Randomize(1, 255), Randomize(1, 255), Randomize(1, 255)]]
});

// if vehicle created you can use it...

let vehicleRandomized = mp.vehicles.new(mp.joaat('elegy'), new mp.Vector3(0.0, 0.0, 75.0)); // create vehicle (model, position)

vehicleRandomized.setColorRGB(Randomize(1, 255), Randomize(1, 255), Randomize(1, 255), Randomize(1, 255), Randomize(1, 255), Randomize(1, 255));```

This is example for you!!

• 1

thanks !

## Create an account

Register a new account