Professional Documents
Culture Documents
Y Vehicledata
Y Vehicledata
I have time and again seen code defining properties of vehicles that uses loops or
vast chunks of memory, when far far less is needed. Many of those times I've even
explained HOW to do it smaller, but no-one has, so I did.
The include has three prefixes - that is, three groups of functions - "Vehicle_",
"Model_", and "VIM_". All three groups have the same functions, but take different
inputs.
[list][*][size=2][color=red][b][u][color=green]Vehicle_[/color][/u][/b][/color][/
size][/list]
[list][*][size=2][color=red][b][u][color=green]Model_[/color][/u][/b][/color][/
size][/list]
[list][*][size=2][color=red][b][u][color=green]VIM_[/color][/u][/b][/color][/size]
[/list]
These functions take a special [b]VIM[/b] variable, that is, one with a tag of
[b]VIM:[/b]. [b]VIM[/b] stands for Vehicle Internal Model, and is specific to this
include (but others are free to use it if they want). This is different to normal
models in three ways:
This second point is very important. Standard model IDs start at 400 and go up to
611, so if you want to use them to index an array you either need 400 empty slots
in the array, or to subtract 400 from the model ID (which is exactly what
[b]VIM[/b]s are).
[size=5][color=red][b][u][color=green]Functions[/color][/u][/b][/color][/size]
[list]
[*][b]Vehicle_GetCategory(vehicleid)[/b] - Return the category of the vehicle, as
defined on [url=http://wiki.sa-mp.com/]http://wiki.sa-mp.com/[/url]. The return
values are;
[pawn]
CATEGORY_UNKNOWN
CATEGORY_AIRPLANE
CATEGORY_HELICOPTER
CATEGORY_BIKE
CATEGORY_CONVERTIBLE
CATEGORY_INDUSTRIAL
CATEGORY_LOWRIDER
CATEGORY_OFFROAD // Two
CATEGORY_OFF_ROAD // versions
CATEGORY_PUBLIC
CATEGORY_SALOON
CATEGORY_SPORT
CATEGORY_STATIONWAGON // Two
CATEGORY_STATION_WAGON // versions
CATEGORY_BOAT
CATEGORY_TRAILER
CATEGORY_UNIQUE
CATEGORY_RC
[/pawn]
Some vehicles may seem to fit in to multiple categories, more information on those
can be got with the functions below. These ONLY return data from the wiki.
[*][b]Vehicle_IsTruck(vehicleid)[/b] -
[*][b]Vehicle_IsVan(vehicleid)[/b] -
[*][b]Vehicle_IsFire(vehicleid)[/b] -
[*][b]Vehicle_IsPolice(vehicleid)[/b] -
[*][b]Vehicle_IsFBI(vehicleid)[/b] -
[*][b]Vehicle_IsSWAT(vehicleid)[/b] -
[*][b]Vehicle_IsMilitary(vehicleid)[/b] -
[*][b]Vehicle_IsHelicopter(vehicleid)[/b] -
[*][b]Vehicle_IsBoat(vehicleid)[/b] -
[*][b]Vehicle_IsPlane(vehicleid)[/b] -
[*][b]Vehicle_IsBike(vehicleid)[/b] -
[*][b]Vehicle_IsAmbulance(vehicleid)[/b] -
[*][b]Vehicle_IsTaxi(vehicleid)[/b] -
[*][b]Vehicle_IsCoastguard(vehicleid)[/b] -
[*][b]Vehicle_IsTank(vehicleid)[/b] -
[*][b]Vehicle_IsFlowerpot(vehicleid)[/b] -
[*][b]Vehicle_IsTransport(vehicleid)[/b] -
[/list]
[size=5][color=red][b][u][color=green]VIM Conversion[/color][/u][/b][/color][/size]
Equivalents to all the above functions also exist for [b]VIM:[/b] tagged variables
- replace the [b]Vehicle_[/b] prefix with [b]VIM_[/b].
There are two ways to get a [b]VIM:[/b] variable - from a vehicleid or from a
modelid:
[pawn]
new
VIM:vimFromVehicleID = Vehicle_GetVIM(vehicleid),
VIM:vimFromModelID = Model_ToVIM(vehicleid),
[/pawn]
Note the difference in "Get" and "To" - this is by design, as models are closer to
VIMs than vehicleids are.
That is all fine, but internally calls several functions twice (including
[b]GetVehicleModel[/b]). This is slightly better:
But that still has to do the "- 400" subtraction discussed earlier (and check that
the result is valid).
Using VIM functions you can do the conversion and bounds checks once, then use the
result far more efficiently:
[pawn]
#define VIM_IsPoliceCar(%0) (VIM_IsCar(%0) && VIM_IsPolice(%0))
new
VIM:vim = Vehicle_GetVIM(vehicleid);
if (VIM_IsPoliceCar(vim) || VIM_IsSWAT(vim))
{
// Whatever.
}
[/pawn]