OnUnoccupiedVehicleUpdate

From SA-MP Wiki

Jump to: navigation, search

OnUnoccupiedVehicleUpdate was added in SA-MP 0.3c This callback was added in SA-MP 0.3c R3 and will not work in earlier versions!


Description:

This callback is called when a player's client updates/syncs the position of a vehicle they're not driving. This can happen outside of the vehicle or when the player is a passenger of a vehicle that has no driver.


Parameters:
(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z)
vehicleidThe ID of the vehicle that's position was updated.
playeridThe ID of the player that sent a vehicle position sync update.
passenger_seatThe ID of the seat if the player is a passenger. 0=not in vehicle, 1=front passenger, 2=backleft 3=backright 4+ is for coach/bus etc. with many passenger seats.
new_xThe new X coordinate of the vehicle. This parameter was added in 0.3z. Leave it out if using an earlier version.
new_yThe new Y coordinate of the vehicle. This parameter was added in 0.3z. Leave it out if using an earlier version.
new_zThe new Z coordinate of the vehicle. This parameter was added in 0.3z. Leave it out if using an earlier version.
vel_xThe new X velocity of the vehicle. This parameter was added in 0.3z R4. Leave it out if using an earlier version.
vel_yThe new Y velocity of the vehicle. This parameter was added in 0.3z R4. Leave it out if using an earlier version.
vel_zThe new Z velocity of the vehicle. This parameter was added in 0.3z R4. Leave it out if using an earlier version.


Return Values:

Returning 0 in this callback will stop the vehicle's position being synced to other players. Update is still sent to the updating player. Useful for combating vehicle teleport hacks.
  • It is always called first in filterscripts so returning 0 there also blocks other scripts from seeing it.


Image:32px-Circle-style-warning.png

Warning

Known Bug(s): This public is not called for trains.


Image:32px-Circle-style-warning.png

Important
Notes

  • This callback is called very frequently per second per unoccupied vehicle. You should refrain from implementing intensive calculations or intensive file writing/reading operations in this callback.
  • GetVehiclePos will return the old coordinates of the vehicle before this update.


Example Usage:

public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z)
{
    // Check if it moved far	
    if(GetVehicleDistanceFromPoint(vehicleid, new_x, new_y, new_z) > 50.0)
    {
        // Reject the update
        return 0;
    }
 
    return 1;
}

Related Callbacks

The following callbacks might be useful as well, as they are related to this callback in one way or another.

Personal tools
Navigation
Toolbox