detachTrailerFromVehicle | Multi Theft Auto: Wiki Skip to content

detachTrailerFromVehicle

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function detaches an already attached trailer from a vehicle.

Note

If 'theTrailer' is specified, it will only detach if this matches. If it is not specified, any trailer attached to 'theVehicle' will be detached.

OOP Syntax Help! I don't understand this!

  • Method:vehicle:detachTrailer(...)

Syntax

bool detachTrailerFromVehicle ( vehicle theVehicle, [ vehicle theTrailer = nil ] )
Required Arguments
  • theVehicle: The vehicle you wish to detach a trailer from.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • theTrailer (default: nil): The trailer you wish to be detached.

Returns

  • bool: value

Returns 'true' if the vehicle's were successfully detached, 'false' otherwise.

Code Examples

shared

Example 1:A command for players to detach a trailer attached to their vehicle:

-- the handler function for the "unhook" console command
function unhookTrailer(playerSource, commandName)
-- check if a player triggered this command and that they are in a vehicle
if (playerSource and isPedInVehicle(playerSource)) then
local theVehicle = getPedOccupiedVehicle(playerSource) -- get the vehicle the player is in
local success = detachTrailerFromVehicle(theVehicle) -- attempt to detach a trailer from this vehicle
-- report whether the operation waa a success
if (success) then
outputConsole("Trailer detached!", playerSource)
else
outputConsole("Failed to detach trailer.", playerSource)
end
end
end
-- make the function above handle the "unhook" command
addCommandHandler("unhook", unhookTrailer)

See Also

Vehicle Functions