javad_iran

Random colors for vehicle

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?

 

sorry for bad english

Share this post


Link to post
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,
{
    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.

Share this post


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?

Share this post


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

Share this post


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.