28.11.2015, 11:48
Intriguing question. Something like this might work. Haven't tested it, though.
Important to note is that these custom callbacks will only get called if the player that sends those updates is actually in the driver's cabine. A trailer can also be connected by pushing it but in that case this custom callback will not fire until someone actually enters the driver's cabin.
PHP код:
public OnTrailerUpdate(playerid, vehicleid)
{
// vehicleid is the id of the trailer
new playerVehicle = GetPlayerVehicleID(playerid);
if(playerVehicle)
{
static attachedTrailer[MAX_VEHICLES];
new currentTrailer = GetVehicleTrailer(playerVehicle);
if(currentTrailer == vehicleid && attachedTrailer[playerVehicle] == 0)
{
OnVehicleTrailerAttached(playerVehicle, playerid, vehicleid);
attachedTrailer[playerVehicle] = vehicleid;
}
else if(currentTrailer == 0 && attachedTrailer[playerVehicle] == vehicleid)
{
OnVehicleTrailerDetached(playerVehicle, playerid, vehicleid);
attachedTrailer[playerVehicle] = 0;
}
}
return 1;
}
OnVehicleTrailerAttached(vehicleid, playerid, trailerid)
{
printf("new trailer with id %d attached to vehicle %d, driven by %d", trailerid, vehicleid, playerid);
}
OnVehicleTrailerDetached(vehicleid, playerid, oldtrailerid)
{
printf("old trailer with id %d detached from vehicle %d, driven by %d", oldtrailerid, vehicleid, playerid);
}