Vehicle Synchronization

From SA-MP Wiki

Jump to: navigation, search
vSync
Include
AuthorRIDE2DAY
Released23/09/2017
Latest Version0.03 (07/11/2017)
Development Status Active
License MPL
Forum Topic

Here you may find all the documentation related to the vSync include scripted by RIDE2DAY. If you find any bug, please, report it on the official topic.

Contents


New Functions

GetVehicleName

Description:

Returns the vehicle's name.


Parameters:
(vehicleid, name[], len = sizeof(name))
vehicleidThe ID of the vehicle to get the name of.
name[]An array into which to store the vehicle name, passed by reference.
lenThe length of the string that should be stored. Recommended to be MAX_VEHICLE_NAME.


Return Values:

The length of the vehicle's name or 0 if the vehicle ID doesn't exist.


Example Usage:

new v_name[MAX_VEHICLE_NAME];
new vehicleid = GetPlayerVehicleID(playerid);
 
GetVehicleName(vehicleid, v_name, MAX_VEHICLE_NAME);
 
new string[128];
format(string, 128, "Vehicle's name is %s.", v_name);
SendClientMessage(playerid, -1, string);

GetVehicleNumberPlate

Description:

Returns the vehicle's number plate.


Parameters:
(vehicleid, dest[], len = sizeof(dest))
vehicleidThe ID of the vehicle to get the number plate of.
dest[]An array into which to store the vehicle number plate, passed by reference.
lenThe length of the string that should be stored. Recommended to be MAX_VEHICLE_NUMBERPLATE.


Return Values:

The length of the vehicle's number plate or 0 if the vehicle ID doesn't exist.


Example Usage:

new v_np[MAX_VEHICLE_NUMBERPLATE];
new vehicleid = GetPlayerVehicleID(playerid);
 
GetVehicleName(vehicleid, v_name, MAX_VEHICLE_NUMBERPLATE);
 
new string[128];
format(string, 128, "Vehicle's number plate is %s.", v_np);
SendClientMessage(playerid, -1, string);

GetVehicleColor

Description:

Returns the primary and secondary color of a vehicle.


Parameters:
(vehicleid, &color1, &color2)
vehicleidThe ID of the vehicle to get the colors of.
&color1A variable in which to store vehicle's primary color ID, passed by reference.
&color2A variable in which to store vehicle's secondary color ID, passed by reference.


Return Values:

1 if the function executed successfully or 0 if the vehicle ID doesn't exist.


Example Usage:

new col1, col2;
GetVehicleColor(GetPlayerVehicleID(playerid), col1, col2);

GetVehiclePaintjob

Description:

Returns the paintjob ID of a vehicle.


Parameters:
(vehicleid)
vehicleidThe ID of the vehicle to get the paintjob ID of.


Return Values:

  • The paintjob ID or INVALID_PAINTJOB_ID if the vehicle doesn't have a paintjob.
  • -1 if the vehicle ID doesn't exist.


Example Usage:

new msg[128];
format(msg, 128, "The paintjob ID is %d.", GetVehiclePaintjob(GetPlayerVehicleID(playerid)));
SendClientMessage(playerid, -1, msg);

GetVehicleSiren

Description:

Returns the state of the addsiren parameter.


Parameters:
(vehicleid)
vehicleidThe ID of the vehicle to get the siren state of.


Return Values:

0 if the addsiren parameter is set to off or 1 if it is set to true.


Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
 
if(GetVehicleModel(vehicleid) == 411 && !GetVehicleSiren(vehicleid))
{
    SendClientMessage(playerid, -1, "Your Infernus doesn't have a siren.");
}

GetVehicleInterior

Description:

Returns a vehicle's current interior.


Parameters:
(vehicleid)
vehicleidThe ID of the vehicle to get the interior of.


Return Values:

The interior that the vehicle is in, if the vehicle ID doesn't exist it returns 0.


Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
 
LinkVehicleToInterior(vehicleid, 10);
 
printf("The new interior is %d.", GetVehicleInterior(vehicleid));

GetVehicleSpeed

Description:

Returns the current speed of a vehicle in km/h.


Parameters:
(vehicleid)
vehicleidThe vehicle ID to get the current speed of.


Return Values:

Vehicle's current speed as an integer.


Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
 
printf("The current speed is %d km/h.", GetVehicleSpeed(vehicleid));

GetVehicleMaxSpeed

Description:

Returns the max. speed of a vehicle in km/h.


Parameters:
(modelid)
modelidThe vehicle model ID to get the max. speed of.


Return Values:

Vehicle's max. speed as an integer.


Image:32px-Ambox_warning_orange.png

Note

This function returns a max. speed of 0 km/h for trailers.


Example Usage:

new msg[128];
new max_speed = GetVehicleMaxSpeed(411);
 
format(msg, 128, "The Infernus has a max. speed of %d.", max_speed);
SendClientMessage(playerid, -1, msg);

GetVehicleSeats

Description:

Returns the amount of seats a vehicle has.


Parameters:
(modelid)
modelidThe vehicle model ID to get the seats of.


Return Values:

The amount of seats the vehicle has or -1 if the vehicle doesn't exist.


Example Usage:

new modelid = GetVehicleModel( GetPlayerVehicleID(playerid) );
 
new msg[128];
format(msg, 128, "Your vehicle has %d seats, call some fellas.", GetVehicleSeats(modelid));
SendClientMessage(playerid, -1, msg);

GetVehicleWindows

Description:

Returns the amount of windows which can be used with SetVehicleParamsCarWindows.


Parameters:
(modelid)
modelidThe vehicle model ID to get the windows of.


Return Values:

The amount of windows the vehicle has or 0 if the model ID isn't correct.


Image:32px-Ambox_warning_orange.png

Note

  • There are vehicles where the amount of windows don't match the amount of seats or doors.
  • Some vehicles have three windows:
    • Camper (left side door)
    • Journey (right side door)
    • Newsvan (right back door)


Example Usage:

new modelid = GetVehicleModel( GetPlayerVehicleID(playerid) );
 
new msg[128];
format(msg, 128, "Your vehicle has %d windows, break them!", GetVehicleWindows(modelid));
SendClientMessage(playerid, -1, msg);

GetVehicleMass

Description:

Returns the mass of a vehicle in kg as a float.


Parameters:
(modelid)
modelidThe vehicle model ID to get the mass of.


Return Values:

Vehicle's mass or 0.0 if the vehicle doesn't exist.


Example Usage:

new Float:mass = GetVehicleMass(411);
 
printf("The Infernus has a mass of %.1f kg.", mass); // %.1f for one decimal.

GetVehicleEngineType

Description:

Returns the engine type of a vehicle.


Parameters:
(modelid)
modelidThe vehicle model ID to get the engine type of.


Return Values:

  • D if the vehicle uses diesel.
  • P if the vehicle uses petrol.
  • E if the vehicle is electric.
  • H if the vehicle is a HPV (human-powered vehicle)


Example Usage:

new modelid = GetVehicleModel(GetPlayerVehicleID(playerid));
 
if(GetVehicleEngineType(modelid) != 'H')
{
    SendClientMessage(playerid, -1, "You need a bike in order to start this mission.");
}
else
{
    SendClientMessage(playerid, -1, "Seems you have a bike, good.");
}

GetVehicleDriveType

Description:

Returns the drive type (traction) of a vehicle.


Parameters:
(modelid)
modelidThe vehicle model ID to get the drive type of.


Return Values:

  • F if the vehicle is FWD (front-wheel drive).
  • R if the vehicle is RWD (rear-wheel drive).
  • 4 if the vehicle is 4WD (four-wheel drive).


Example Usage:

new modelid = GetVehicleModel(GetPlayerVehicleID(playerid));
 
if(GetVehicleDriveType(modelid) != '4')
{
    SendClientMessage(playerid, -1, "You need a 4WD vehicle to start this race.");
}

VehicleSupportsNeonLights

Description:

Checks if a vehicle model supports neon lights.


Parameters:
(modelid)
modelidThe vehicle model ID to check.


Return Values:

1 if the vehicle model supports neon lights or 0 if it doesn't.


Example Usage:

new modelid = GetVehicleModel(GetPlayerVehicleID(playerid));
 
if(!VehicleSupportsNeonLights(modelid))
{
    new msg[128];
    new vname[MAX_VEHICLE_NAME];
    GetVehicleName(newveh, vname, MAX_VEHICLE_NAME);
 
    format(msg, 128, "The %s has the neon lights {FF0000}disabled{FFFFFF}.", vname);
    SendClientMessage(playerid, -1, msg);
}

SetVehicleNeonLights

Description:

Enables or disables the neon lights for a vehicle.


Parameters:
(vehicleid, bool:toggle = true, color = NEON_LIGHT_RED)
vehicleidThe vehicle ID to set the neon lights to.
bool:toggletrue to enable the neon lights and false to disable them.
colorThe object model for the neon lights, set to NEON_LIGHT_RED by default.


Return Values:

1 if the function executed successfully or 0 if the vehicle ID doesn't exist.


Image:32px-Ambox_warning_orange.png

Note

  • You should use VehicleSupportsNeonLights before enabling the neon lights.
  • You don't have to disable the neon lights in order to set a new color, that's done automatically.


Color Definition Object Model
NEON_LIGHT_RED 18647
NEON_LIGHT_BLUE 18648
NEON_LIGHT_GREEN 18649
NEON_LIGHT_YELLOW 18650
NEON_LIGHT_PINK 18651
NEON_LIGHT_WHITE 18652

Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
new modelid = GetVehicleModel(vehicleid);
 
if(VehicleSupportsNeonLights(modelid))
{
    SetVehicleNeonLights(vehicleid, true, NEON_LIGHT_GREEN);
    SendClientMessage(playerid, -1, "Your car has {00FF00}green {FFFFFF}neon lights now.");
}

GetVehicleNeonLightsState

Description:

Returns the state of the neon lights on a vehicle.


Parameters:
(vehicleid)
vehicleidThe vehicle ID to get the neon lights state of.


Return Values:

  • 1 if the the neon lights are enabled.
  • 0 if the the neon lights are disabled or if the vehicle ID doesn't exist.


Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
 
if(GetVehicleNeonLightsState(vehicleid))
{
    SendClientMessage(playerid, -1, "You have neon lights, now you may join the Midnight Club!");
}

VehicleSupportsNitro

Description:

Checks if a vehicle model supports nitro.


Parameters:
(modelid)
modelidThe vehicle model ID to check.


Return Values:

1 if the vehicle model supports nitro or 0 if it doesn't.


Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
new modelid = GetVehicleModel(vehicleid);
 
if(VehicleSupportsNitro(modelid))
{
    new msg[128];
    new vname[MAX_VEHICLE_NAME];
    GetVehicleName(newveh, vname, MAX_VEHICLE_NAME);
 
    AddVehicleComponent(vehicleid, 1010);
 
    format(msg, 128, "Now your %s has nitro, enjoy!", vname);
    SendClientMessage(playerid, -1, msg);
}

VehicleSupportsComponent

Description:

Checks if a vehicle model supports a component.


Parameters:
(modelid)
modelidThe vehicle model ID to check.
componentidThe ID of the component you're going to check.


Return Values:

1 if the vehicle model supports the component or 0 if it doesn't.


Image:32px-Ambox_warning_orange.png

Note

There are internal checks for OnVehicleMod and AddVehicleComponent, use this function wherever you need it.


Example Usage:

new vehicleid = GetPlayerVehicleID(playerid);
new modelid = GetVehicleModel(vehicleid);
 
if(VehicleSupportsComponent(modelid, 1003))
{
    new msg[128];
    new vname[MAX_VEHICLE_NAME];
    GetVehicleName(newveh, vname, MAX_VEHICLE_NAME);
 
    AddVehicleComponent(vehicleid, 1003);
 
    format(msg, 128, "Alpha Spoiler added to your %s.", vname);
    SendClientMessage(playerid, -1, msg);
}

Modified Functions

Component ID Slot Type Car
1109 CARMODTYPE_REAR_BULLBAR Chrome Slamvan
1110 CARMODTYPE_REAR_BULLBAR Slamin Slamvan
1115 CARMODTYPE_FRONT_BULLBAR Chrome Slamvan
1116 CARMODTYPE_FRONT_BULLBAR Slamin Slamvan
1100 CARMODTYPE_FRONT_BULLBAR Chrome Grill Remington
1123 CARMODTYPE_FRONT_BULLBAR Bullbar Chrome Bars Remington
1125 CARMODTYPE_FRONT_BULLBAR Bullbar Chrome Lights Remington

New Callbacks

OnVehicleCreated

Description:

Called when a vehicle is created.


Parameters:
(vehicleid)
vehicleidThe ID of the vehicle which has been created.


Return Values:

This callback does not handle returns.


Image:32px-Ambox_warning_orange.png

Note

This callback is not called when a vehicle respawns.


Example Usage:

public OnVehicleCreated(vehicleid)
{
    SetVehicleNumberPlate(vehicleid, "{FF0000}RIDE2DAY");
    return 1;
}

OnVehicleChangePaintjob

Description:

Called when a player buys a paintjob inside a mod shop.


Parameters:
(playerid, vehicleid, paintjobid)
playeridThe ID of the player that bought the paintjob.
vehicleidThe ID of the vehicle which the paintjob was applied to.
paintjobidThe ID of the new paintjob.


Return Values:

This callback does not handle returns.


Example Usage:

public OnVehicleChangePaintjob(playerid, vehicleid, paintjobid)
{
    new msg[128];
    format(msg, 128, "The ID of the paintjob you just bought is %d.", paintjobid);
    SendClientMessage(playerid, -1, msg);
    return 1;
}

Notes

  • You might use INVALID_PAINTJOB_ID with ChangeVehiclePaintjob to remove a paintjob.
  • When a vehicle respawns it returns to its original colors (those which had when was created), that's how it works by default.
  • When a vehicle respawns all its mods are removed, that's how it works by default.
  • This scripts uses y_hooks or the ALS hooking method.
  • Functions hooked:
    • CreateVehicle
    • DestroyVehicle
    • AddStaticVehicle
    • AddStaticVehicleEx
    • SetVehicleNumberPlate
    • LinkVehicleToInterior
    • ChangeVehicleColor
    • ChangeVehiclePaintjob
    • GetVehicleComponentType
    • GetVehicleComponentInSlot
    • AddVehicleComponent
    • RemoveVehicleComponent
  • Callbacks hooked:
    • OnPlayerConnect
    • OnPlayerUpdate
    • OnPlayerKeyStateChange
    • OnEnterExitModShop
    • OnVehiclePaintjob
    • OnVehicleRespray
    • OnVehicleSpawn
    • OnVehicleMod
  • Vehicles with NeonOffsetX = NeonOffsetY = NeonOffsetZ = 0.0 don't support neon lights, you're free to modify those offsets if you wish. Here you have list with those vehicles.
  • Now AddVehicleComponent has internal checks, you don't have to check anymore if a component is valid when using this function.
Personal tools
Navigation
Toolbox