[Tool/Web/Other] How to obtain the color of a vehicle?
#1

Hello, I do not know if you ever tried to get the primary and secondary color of a vehicle, there is an include for this but it is not necessary, here I give you a very quick way of doing this.

Step 1
Code:
new Color[MAX_VEHICLES][2];
Step 2

Replace all CreateVehicle to CreateVehicleEx and add this function

Code:
CreateVehicleEx(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, bool:addsiren = false)
{
	new vehiclespawned = INVALID_VEHICLE_ID;
 	vehiclespawned = CreateVehicle(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, addsiren);
	Color[vehiclespawned][0] = color1;
	Color[vehiclespawned][1] = color2;
	printf("Vehicled spawned > Model: %d / C1: %d / C2: %d.", vehicletype, Color[vehiclespawned][0], Color[vehiclespawned][1]);
	return vehiclespawned;
}
The parameters of CreateVehicle and CreateVehicleEx are the same.

Example of use

Code:
CMD:obtenercolor(playerid, params[])
{
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) // If you are a driver of any vehicle.
	{
	    new autito = GetPlayerVehicleID(playerid);
		SendClientMessage(playerid, -1, "Hello, the colors of your vehicle are:");
		new str[32];
		format(str, sizeof(str), "Primary: %d / Secondary: %d", Color[autito][0], Color[autito][1]);
		SendClientMessage(playerid, -1, str);
	}
	return 1;
}
Reply
#2

Since max color is 255

it can be done like this:

PHP Code:
new Color[MAX_VEHICLES][2 char]; 
usage:

PHP Code:
Color[vehicleid]{0} = color1;
Color[vehicleid]{1} = color2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)