OnTrailerAttach: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (See Also for server events)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server event}}
{{Server event}}
This event is triggered when a trailer is attached to a truck.
{{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.


==Parameters==
==Parameters==
Line 8: Line 9:
</syntaxhighlight>  
</syntaxhighlight>  


*'''theTruck''': The truck vehicle that got attached to this trailer
*'''theTruck''': the truck [[vehicle]] that got attached to this trailer.


==Source==
==Source==
Line 15: Line 16:
<!-- Only include this section below if cancelling the event has any effect. If you don't know if it does, ask a dev! -->
<!-- Only include this section below if cancelling the event has any effect. If you don't know if it does, ask a dev! -->
==Cancel effect==
==Cancel effect==
{{Warning|Doesn't appear to work.}}
If this event is [[Event system#Canceling|canceled]], the trailer will detach from the truck again.
If this event is [[Event system#Canceling|canceled]], the trailer will detach from the truck again.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
<!-- Explain what the example is in a single sentance -->
This example does...
This example removes a trailer from the truck it is attached to. Good if you do not want people attaching trailers to vehicles
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function detachTrailer(theTruck)
blah()
    --detachTrailerFromVehicle(theTruck, source) --detach the newly attached trailer
--This line does this...
    -- Immediate detatchment of the trailer through cancel event or this method doesn't seem to work so requires a timer:
mooo
    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
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Vehicle events}}
{{See also/Server event|Vehicle events}}


[[Category:Needs Example]]
[[ru:onTrailerAttach]]

Latest revision as of 15:52, 29 May 2019

Dialog-information.png This article needs checking.

Reason(s): 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.

Parameters

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

Source

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

Cancel effect

[[|link=|]] Warning: Doesn't appear to work.

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

Example

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 events


Event functions