Jump to content

How to Attach trailer for multiple vehicles ?


Pouloud

Recommended Posts

Hello

I would like to make a script for attach or detach trailers and specify what car can attach the trailer

i have make a searh on the mta wiki and i have found that

attachTrailerToVehicle

newvehicle = createVehicle ( 515, 0, 0, 4 ) -- create a trailer tower (roadtrain) 
setTimer( 
    function() 
        trailer = createVehicle ( 435, 0, 0, 4 )    -- create a trailer 
        attachTrailerToVehicle ( newvehicle, trailer )   -- attach them 
    end, 50, 1) 

but the problem is this function create a vehicle and i woul like to attach/detach trailers for any vehicles

anyone can help me ?

Edited by Guest
Link to comment

I have tried to make my own script for attach/detach trailer from a vehicle.

i can detach the trailer like that:

addEventHandler("[color=#BFBFFF]onPlayerLogin[/color]", root, 
   [color=#0000FF]function()[/color] 
       bindKey(source, "[color=#BFBFFF]o[/color]", "[color=#BFBFFF]up[/color]", unhookTrailer) 
    [color=#0000FF]end[/color] 
) 
  
addEventHandler("[color=#BFBFFF]onResourceStart[/color]", resourceRoot, 
   [color=#0000FF]function()[/color] 
       for _, v in ipairs(getElementsByType("[color=#BFBFFF]player[/color]")) do 
           bindKey(v, "[color=#BFBFFF]o[/color]", "[color=#BFBFFF]up[/color]", unhookTrailer) 
        [color=#0000FF]end[/color] 
    [color=#0000FF]end[/color] 
) 
  
[color=#0000FF]function[/color] unhookTrailer(thePlayer, commandName) 
   [color=#0000FF]if[/color] isPedInVehicle(thePlayer) [color=#0000FF]then[/color] 
      [color=#0000FF]local[/color] theVehicle = getPedOccupiedVehicle(thePlayer) 
      [color=#0000FF]local[/color] success = detachTrailerFromVehicle(theVehicle) 
      [color=#0000FF]local[/color] x, y, z = getElementPosition(theVehicle) 
      [color=#0000FF]if[/color] (success) [color=#0000FF]then[/color] 
          [color=#0000FF]if[/color] getElementType("[color=#BFBFFF]trailer[/color]") [color=#0000FF]then[/color] 
             setElementPosition(trailer, x+2, y, z) 
          [color=#0000FF]end[/color] 
             outputChatBox("[color=#BFBFFF]Trailer detached![/color]", thePlayer) 
      [color=#0000FF]else[/color] 
             outputChatBox("[color=#BFBFFF]Trailer not attatched[/color].", thePlayer) 
      [color=#0000FF]end[/color] 
    [color=#0000FF]end[/color] 
[color=#0000FF]end[/color] 
addCommandHandler("[color=#BFBFBF]unhook[/color]", unhookTrailer) 

is someone able to help me to make the attach function ?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...