Pouloud Posted February 24, 2016 Share Posted February 24, 2016 (edited) 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 February 25, 2016 by Guest Link to comment
tosfera Posted February 25, 2016 Share Posted February 25, 2016 You can always add a command to see if it can attach the vehicle. If your vehicles have any ID linked to them you can do it like; user uses a command with an ID check if the vehicle with the ID is close and the user is in a vehicle. attach them. Link to comment
Pouloud Posted February 25, 2016 Author Share Posted February 25, 2016 Thanks you for your reply Why not but the player must do the command for attach the trailer, right ? also can you help me for create this script ? thanks you Link to comment
Pouloud Posted February 26, 2016 Author Share Posted February 26, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now