SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Tools and Files

Thread Tools Display Modes
Old 06/09/2018, 06:36 PM   #1
Little Clucker
Join Date: Dec 2016
Location: Argentina
Posts: 5
Reputation: 0
Default How to obtain the color of a vehicle?

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
new Color[MAX_VEHICLES][2];
Step 2

Replace all CreateVehicle to CreateVehicleEx and add this function

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

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;
labiyebu is offline   Reply With Quote
Old 06/09/2018, 06:48 PM   #2
Huge Clucker
Join Date: Sep 2017
Posts: 281
Reputation: 72
Default Re: How to obtain the color of a vehicle?

Since max color is 255

it can be done like this:

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

PHP Code:
Color[vehicleid]{0} = color1;
Color[vehicleid]{1} = color2
Lokii is offline   Reply With Quote
Old 06/09/2018, 06:55 PM   #3
Beta Tester
Y_Less's Avatar
Join Date: Jun 2008
Location: 629 -
Posts: 15,320
Reputation: 3191
Default Re: How to obtain the color of a vehicle?

So instead of using an include, you just copy the code of the include instead? How is that better? An include will actually do it properly - handle random colours, multiple scripts, and AddStaticVehicle(Ex).

Not using an include is not good, they are much faster.
Y_Less is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to obtain age from date of birth? Jose_grana Scripting Help 7 13/08/2018 02:08 AM
Get Player color and change vehicle color to the player color gurmani11 Scripting Help 4 03/07/2015 12:34 PM
Vehicle color help! LuckyPlaya` Scripting Help 3 22/01/2013 07:53 PM
How to obtain this back. AustinJ Client Support 4 22/04/2012 08:09 AM
how to obtain such textdraw maxi459 Help Archive 2 21/11/2010 09:20 AM

All times are GMT. The time now is 07:51 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.