[Include] vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7)
#1

Vehicle Functions
by MP2
Introduction
When a vehicle's color(s) in CreateVehicle are set to -1, random colors (defined in carcols.dat) will be used. The thing is, the colours are not synced with other players so while one player may have a red car the other one will see a grey one. This fixes that by having the carcol.dat data inside the script, and using that.

It also adds two new functions - GetVehicleColor(s) and GetVehicleInterior. GetVehicleColor(s) will also work when you set the color to -1, as the data is in the script!

You can also use -1 as a color in ChangeVehicleColor now.

IMPORTANT NOTE: GetVehicleColor will NOT work in filterscripts for vehicles that were created in the gamemode (or vice versa). This is because vehicles (generally) are created in your gamemode, and the filterscript is loaded AFTER. The filterscripts can't read the data from the gamemode.

Changelog
1.2 (05/05/2015)
- Updated for 0.3.7 (added siren parameter for CreateVehicle and AddStaticVehicleEx)
- Removed 'interior' parameter from CreateVehicle/AddStaticVehicleEx to keep in line with SA-MP's functions. Use LinkVehicleToInterior or SetVehicleInterior instead. If you used the 'interior' parameter before, it's 'siren' now.
- Commented out some unfinished code. May get around to finishing it.
- AddStaticVehicle and AddStaticVehicleEx no longer re-direct to CreateVehicle. They use their own respective functions
- Using y_hooks again..
- Added GetVehicleSeatCount and GetVehicleModelSeatCount
- Added vehicle type checks. See GetVehicleType and GetVehicleModelType below.

1.1.3 (10th of February 2013):
- Fixed a bug that caused OnVehicleSpawn to not be called. Caused by another array index out of bounds issue due to me not checking whether a vehicle colour was set to -1 (-1 is an invalid array index).

1.1.2 (7th of February 2013):
- y_hooks no longer used (proper plug-n-play)
- Hooked 'OnVehicleRespray' (reported missing by 'im'

1.1.1 (22nd of January 2013):
- Fixed out of bounds array index issue with vehicle ID 2000.

1.1 (4th of May 2012):
- Removing a paintjob now restores the vehicle's color (fixes SA:MP bug where vehicle became white)
- Added 'GetVehiclePaintjob' function
- Added RemoveVehiclePaintjob (simple macro ('redirect') to ChangeVehiclePaintjob)

1.0 (2nd of May 2012):
- Initial Release

Usage
Function documentation:

GetVehicleInterior(vehicleid);
Returns the interior ID of a vehicle.

GetVehicleColor(vehicleid, &color1, &color2);
Get a vehicle's color(s). You need to declare two variables to store the colors in:
pawn Код:
new color1, color2;
GetVehicleColor(vehicleid, color1, color1);
There are 4 'aliases':
- GetVehicleColor
- GetVehicleColour
- GetVehicleColours
- GetVehicleColors

so you don't have to worry about forgetting the exact function name.

GetVehiclePaintjob(vehicleid)
Returns the vehicle's paintjob ID (3 if none).

RemoveVehiclePaintjob(vehicleid)
Remove a vehicle's paintjob (sets it to 3).

OnVehicleCreated
I also added a callback called OnVehicleCreated which is called when a vehicle is first created (with CreateVehicle/AddStaticVehicle(Ex)). Useful for various things:
pawn Код:
public OnVehicleCreated(vehicleid)
{
    vFuel[vehicleid] = 100; // Set fuel to full

    SetVehicleHealth(vehicleid, 2000); // Set to double health
    return 1;
}
NOTE: This is NOT called when a vehicle re-spawns. Use the native callback OnVehicleSpawn(vehicleid).

GetVehicleType/GetVehicleModelType
pawn Код:
#define VTYPE_ROAD 0
#define VTYPE_BIKE 1
#define VTYPE_PLANE 2
#define VTYPE_HELI 3
#define VTYPE_BOAT 4
#define VTYPE_TRAIN 5

// Example
if(GetVehicleType(vehicleid) == VTYPE_BOAT)
{
    // Do something
}
Installation
• Download the .inc file below
• Place it in C:\Program Files\Rockstar Games\GTA San Andreas\pawno\include (or where ever your include folder is)
• Add " #include <vfunc> " at the top of your gamemode under "#include <a_samp>"
• Enjoy!

Download
http://pastebin.com/g8t7Jy7a

No mirrors please. If the links happen to go down PM me and I'll get another one up very quickly.

Thank you!
Thank you for using this include. If you have any suggestions or find any problems/bugs, please do let me know, thanks.
Reply


Messages In This Thread
vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7) - by MP2 - 02.05.2012, 07:23
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Faisal_khan - 02.05.2012, 07:27
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by System64 - 02.05.2012, 07:42
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 02.05.2012, 07:47
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by 2KY - 03.05.2012, 14:19
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 04.05.2012, 11:47
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 04.05.2012, 21:42
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Kyle - 02.06.2012, 15:16
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Jochemd - 02.06.2012, 15:19
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Kyle - 02.06.2012, 17:34
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 02.06.2012, 19:27
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Kyle - 29.07.2012, 11:40
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 30.07.2012, 12:01
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 22.01.2013, 14:24
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by im - 07.02.2013, 07:29
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 07.02.2013, 07:35
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 10.02.2013, 19:28
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Apenmeeuw - 14.03.2013, 20:04
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Konstantinos - 14.03.2013, 20:23
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 16.03.2013, 01:05
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Konstantinos - 16.03.2013, 10:23
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 16.03.2013, 12:57
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by SMW - 15.06.2013, 18:04
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by MP2 - 16.06.2013, 00:00
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by HeLiOn_PrImE - 28.12.2013, 11:18
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Emmet_ - 29.12.2013, 06:44
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Alphlax - 29.12.2013, 06:53
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by HeLiOn_PrImE - 29.12.2013, 09:22
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Emmet_ - 29.12.2013, 09:27
Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - by Zamora - 29.12.2013, 09:40
Re: vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7) - by FERCOPRO - 05.07.2016, 03:42
Re: vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7) - by MerryDeer - 22.07.2016, 08:17

Forum Jump:


Users browsing this thread: 1 Guest(s)