[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
#2

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

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

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.
Reply
#5

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

Thanks. Let me know if there's any problems.
Reply
#7

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)
Reply
#8

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.
Reply
#9

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

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

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.
Reply
#12

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

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.
Reply
#14

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

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

Should be fixed now. Download the latest version.
Reply
#17

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).
Reply
#18

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.
Reply
#19

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.
Reply
#20

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)