SA-MP Forums Archive
[Include] vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7) (/showthread.php?tid=339088)

Pages: 1 2


vFunc - Synced random vehicle colors (-1), GetVehicleColor and more vehicle-related functions (UPDATED FOR 0.3.7) - MP2 - 02.05.2012

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.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Faisal_khan - 02.05.2012

Good work bro I also had this problem I thought that this is a non-fixable.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - System64 - 02.05.2012

Nice job, although there is already RyDeR's (I guess) include for GetVehiceColor


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 02.05.2012

His doesn't sync random vehicle colors (-1, -1) properly, he just uses random(127). Mine uses the ACTUAL random carcolors from carcols.dat.

I wrote this two months ago and didn't release it yet, then I saw his topic yesterday actually and it reminded me to release this.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - 2KY - 03.05.2012

I will be using this. OnVehicleCreated is VERY useful, thank you. I'll post feedback soon.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 04.05.2012

Thanks. Let me know if there's any problems.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 04.05.2012

Version 1.1 released:

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


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Kyle - 02.06.2012

Either this or ******'s Fix include is bugged, sometimes I would exit a vehicle and it would make the vehicles disapear then respawn 5 secs later.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Jochemd - 02.06.2012

Isn't that caused by the respawn delay parameter in CreateVehicle/AddStaticVehicleEx?


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Kyle - 02.06.2012

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Isn't that caused by the respawn delay parameter in CreateVehicle/AddStaticVehicleEx?
The respawn time was 60 seconds...


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 02.06.2012

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
Either this or ******'s Fix include is bugged, sometimes I would exit a vehicle and it would make the vehicles disapear then respawn 5 secs later.
This include doesn't affect vehicles respawning.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Kyle - 29.07.2012

http://forum.sa-mp.com/showthread.ph...18#post2019218


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 30.07.2012

Ah.

This include hooks CreateVehicle (and the similar functions) to store the color of the vehicle. Hence if you create vehicles before this include is included (or use it in a remote script (you should ONLY use it in a gamemode)) the stored colors will still be 0 - black.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 22.01.2013

1.1.1 released to address array index out of bounds issue for vehicle ID 2000 (MAX_VEHICLES).


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - im - 07.02.2013

I think that this doesn't detect color changes made on mod shops (OnVehicleRespray).. or there's a problem with my code.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 07.02.2013

Should be fixed now. Download the latest version.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 10.02.2013

Released a fix for 'OnVehicleSpawn' not being called for certain vehicle models (the ones without any/syncable colours). You should re-download this if you're having problems with OnVehicleSpawn (or even if you aren't tbh).


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Apenmeeuw - 14.03.2013

this keeps appearing, no matter what i do, i can't get it away...

Код:
D:\Program Files\StreetRod\StreetRod 0.3e R2\pawno\include\GetCarColor.inc(1) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.



Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - Konstantinos - 14.03.2013

Quote:
Originally Posted by Apenmeeuw
Посмотреть сообщение
this keeps appearing, no matter what i do, i can't get it away...

Код:
D:\Program Files\StreetRod\StreetRod 0.3e R2\pawno\include\GetCarColor.inc(1) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
The first lines are a description about the include and they're inside a commented text. Make sure it's like this
pawn Код:
/*
Vehicle functions by Mike (MP2)

- Random vehicle colors (-1 in CreateVehicle) are synced between players
- GetVehicleInterior function
- GetVehicleColor function
- ChangeVehicleColor works with -1 (random) colors

*/
Otherwise, it'll give you the error you've got.

// --

It seems to be a very nice include, I'll check it out and I may use it!
Good job.


Re: vfunc - GetVehicleColor, GetVehicleInterior and synced random colors (-1, -1) - MP2 - 16.03.2013

Quote:
Originally Posted by Apenmeeuw
Посмотреть сообщение
this keeps appearing, no matter what i do, i can't get it away...

Код:
D:\Program Files\StreetRod\StreetRod 0.3e R2\pawno\include\GetCarColor.inc(1) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
That isn't my include.