Jump to content
RAGE Multiplayer Community

Random colors for vehicle


Recommended Posts

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

mp.vehicles.new(model, position,
{
    heading: heading,
    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.

Link to post
Share on other sites
On 9/9/2018 at 12:35 PM, MrPancakers said:

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

mp.vehicles.new(model, position,
{
    heading: heading,
    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?

Link to post
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!! 

  • Like 1
Link to post
Share on other sites

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