onTrailerAttach | Multi Theft Auto: Wiki Skip to content

onTrailerAttach

Client-side
Server-side
Shared
This article needs checking:

Cancellation of event has no effect. detachTrailerFromVehicle in the event doesn't work either, 50 ms timer is effective.

This event is triggered when a trailer is attached to a truck or when a tow truck hooks on to a vehicle.

Canceling doesn't appear to work.

Parameters

vehicle theTruck
  • theTruck: the truck vehicle that got attached to this trailer.

Source

element: The source of this event is the trailer vehicle that the truck got attached to.

Canceling

If this event is canceled, the trailer will detach from the truck again.

Code Examples

server

This example removes a trailer from the truck it is attached to. Good if you do not want people attaching trailers to vehicles

function detachTrailer(theTruck)
--detachTrailerFromVehicle(theTruck, source) --detach the newly attached trailer
-- Immediate detatchment of the trailer through cancel event or this method doesn't seem to work so requires a timer:
setTimer(detachTrailer2, 50, 1, theTruck, source)
end
addEventHandler("onTrailerAttach", getRootElement(), detachTrailer)
function detachTrailer2(theTruck, trailer)
if (isElement(theTruck) and isElement(trailer)) then
detachTrailerFromVehicle(theTruck, trailer)
end
end

See Also

Vehicle Functions