carcols.dat random colors - Emmet_ - 14.03.2014
Introduction
This is just a simple include which allows you to get 2 random matching colors of a vehicle (based on carcols.dat). Originally, you could use "-1" as the color, but it's very glitchy.
It took about an hour to fetch all of the data from "carcols.dat". Then, I had to sort each entry in the array!
Purpose
In default GTA:SA, vehicles are spawned around the map and given random colors, based on the vehicle's model. To replicate this in SA-MP, you could use "-1" as the color parameter, but it's glitchy (the colors change when you enter and exit interiors). This include fixes that!
Functions
Currently, there is only one function:
pawn Код:
forward GetRandomModelColors(modelid, &color1, &color2);
For example, to get 2 random colors for the "Infernus" vehicle:
pawn Код:
new
color1,
color2;
GetRandomModelColors(411, color1, color2);
ChangeVehicleColor(vehicleid, color1, color2);
Download
http://pastebin.com/TEE9DKJ1
Re: carcols.dat random colors -
RenSoprano - 14.03.2014
Very Nice and easy to use
Re: carcols.dat random colors - Emmet_ - 14.03.2014
Looks like I left the model IDs in during the sorting process. They should be removed now.
Update:
- Added integration for using "-1" in "Create/AddStaticVehicle" - thanks to ******.
- Removed the model ID's from the array (accidentally left them in).
Re: carcols.dat random colors - Emmet_ - 15.03.2014
If I recall correctly, "-1, 5" would probably select a random color for only the first one. I'll do some testing to confirm this!
Edit: I spawned a few NRG-500's (using the original native), using "-1" for color 1, and "3" for color 2. Instead of a random color being generated, it was blue! The same happened when switching the colors around (3, -1).
The same result for other vehicles too:
Perhaps I could add something to fix this.
Re: carcols.dat random colors -
ball - 25.02.2015
Almost year later, but this is very nice include, so must be perfect. I have noticed two problems
Код:
{
rand = random(count);
color1 = g_aColorData[model][rand + 1];
color2 = g_aColorData[model][rand + 2];
}
This code is wrong, why? Let me explain. For example take banshee's and predator's colors
Код:
{16, 12, 12, 13, 13, 14, 14, 1, 2, 2, 1, 1, 3, 3, 1, 10, 10},
{2, 46, 26},
Now code compile this
Код:
{
rand = random(16);
color1 = g_aColorData[model][rand + 1];
color2 = g_aColorData[model][rand + 2];
}
If rand is 15, color1 will be 10, but color2 will be 2. Why? 15 + 2 = 17, 17th index is invalid, so next value will be assigned, in this case 2. Second issue is wrong color selecting. Rand must be even for good colors selecting, but what if rand is odd? Lets introduce this on example
Код:
{
rand = random(16); //for example rand is 7
color1 = g_aColorData[model][rand + 1]; //g_aColorData[model][8]
color2 = g_aColorData[model][rand + 2]; //g_aColorData[model][9]
}
Banshee's colors
Код:
{16, 12, 12, 13, 13, 14, 14, 1, 2, 2, 1, 1, 3, 3, 1, 10, 10}
Eighth index is 2, but eighth index is value for second color, so that's why rand must be even. Fix for this
Код:
rand = random(g_aColorData[modelid - 400][0] / 2) * 2;
Now rand for sure will be even and this fix both explained issues. Sorry for my english, anyway good work.