This will only work if both vehicles are streamed in for a player (check IsVehicleStreamedIn).
(trailerid, vehicleid)
trailerid
The ID of the vehicle that will be pulled.
vehicleid
The ID of the vehicle that will pull the trailer.
new vehicleid = CreateVehicle(...);
new trailerid = CreateVehicle(...);
AttachTrailerToVehicle(trailerid, vehicleid);
The following functions may be useful, as they are related to this function in one way or another.