scaryface87 Posted June 9, 2014 Share Posted June 9, 2014 Hello , I would like to attach an car on an DFT (so if ur near a car with ur dft and u use /load then the car gets on it for example) Im not sure how to start to be here functions i think i need to use attachElements addCommandHandler greets Link to comment
Den. Posted June 9, 2014 Share Posted June 9, 2014 Here: server-side: addEvent("dft:attach", true) addEventHandler("dft:attach", root, function(vehicle, ox, oy, oz) if isElement(source) and isElement(vehicle) then attachElements(vehicle, source, ox, oy, oz) --Attach both vehicles setElementRotation(vehicle, getElementRotation(source)) --Set rotation for our vehicle setElementData(vehicle, "dft:attached", true, false) --Set element data for unloading later. end end) addCommandHandler("unload", function(thePlayer) local veh = getPedOccupiedVehicle(thePlayer) if isElement(veh) and getElementData(veh, "dft:attached") then --If the vehicle is attached to a DFT detachElements(veh) --Detach it removeElementData(veh, "dft:attached") --Remove the elem data. end end) Client-side: function loadDFT() local x, y, z = getElementPosition(localPlayer) local veh = getPedOccupiedVehicle(localPlayer) if veh then local vehicles = getElementsByType("vehicle") for key, vehicle in ipairs(vehicles) do if getElementModel(vehicle) == 578 then local vx, vy, vz = getElementPosition(vehicle) if getDistanceBetweenPoints3D(x, y, z, vx, vy, vz) <= 15 then --He is close to a DFT local cx, cy, cz = getVehicleComponentPosition(vehicle, "chassis_dummy") --Get the DFT's back position local height = getElementDistanceFromCentreOfMassToBaseOfModel(veh) -- Get our vehicle's height triggerServerEvent("dft:attach", vehicle, veh, cx, cy-1.5, height - 0.235) --Trigger the server event to attach elements end end end end end addCommandHandler("load", loadDFT) This is a slightly longer script for a small task such as attaching elements, but I wanted to test some things while doing it. 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