#Madara Posted July 26, 2015 Share Posted July 26, 2015 Hi guys , i have a question , How i can attach vehicle with hunter if hunter go above the vehicle and the who into hunter press ( H ) the vehicle attached to the hunter and when the who in hunter press ( H ) again drop the vehicle who got attached . Link to comment
Perfect Posted July 27, 2015 Share Posted July 27, 2015 bindKey attachElements getDistanceBetweenPoints2D or getDistanceBetweenPoints3D -- Attach the vehicle, only if the hunter is above of the vehicle. Link to comment
#Madara Posted July 27, 2015 Author Share Posted July 27, 2015 bindKey attachElements getDistanceBetweenPoints2D or getDistanceBetweenPoints3D -- Attach the vehicle, only if the hunter is above of the vehicle. Can you give me an example, because I did not understand how if the hunter is above of the vehicle getDistanceBetweenPoints3D Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 I think it would be easier to use processLineOfSight since you can most easily place it and you don't need any calculations or so. local vehicle = getPedOccupiedVehicle(localPlayer) -- Your vehicle local x, y, z = getElementPosition(vehicle) -- Position of hunter local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) -- Gets ground of hunter, so the process line doesn't collide with hunter itself. local offset = 2 -- How much units under the hunter should it take to attach a vehicle? local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You can attach "..getVehicleName(hitElement)) -- Returns vehicle element and outputs vehicle name. end Put this in onClientRender or so. If you don't know where process line is, use dxDrawLine3D to see and test it. Link to comment
#Madara Posted July 27, 2015 Author Share Posted July 27, 2015 how i can attach any vehicle in server with hunter when i go above the vehicle i want attach it? Link to comment
#Madara Posted July 27, 2015 Author Share Posted July 27, 2015 attachElements i know but i mean how i know the vehicle i want to attach it to add it in arguments of function attachElements Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 The code I gave you. local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) hitElement is the element under the hunter. attachElements(hitElement, HUNTER) Link to comment
#Madara Posted July 27, 2015 Author Share Posted July 27, 2015 The code I gave you. local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) hitElement is the element under the hunter. attachElements(hitElement, HUNTER) i make this and it's dosen't work addEventHandler("onClientRender",root, function() bindKey("H","down", function() local vehicle = getPedOccupiedVehicle(localPlayer) -- Your vehicle local id = getElementModel (vehicle) local x, y, z = getElementPosition(vehicle) if ( vehicle ) and ( id == 425 ) then-- Position of hunter local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) -- Gets ground of hunter, so the process line doesn't collide with hunter itself. local offset = 2 -- How much units under the hunter should it take to attach a vehicle? local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) -- Returns vehicle element and outputs vehicle name. attachElements(hitElement, vehicle) else return end end end end end ) [/b] Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 bindKey("H", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel (vehicle) local x, y, z = getElementPosition(vehicle) if ( vehicle ) and ( id == 425 ) then local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) attachElements(hitElement, vehicle) end end end ) Link to comment
#Madara Posted July 28, 2015 Author Share Posted July 28, 2015 bindKey("H", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel (vehicle) local x, y, z = getElementPosition(vehicle) if ( vehicle ) and ( id == 425 ) then local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) attachElements(hitElement, vehicle) end end end ) it's work fine but the player i attached his vehicle to my hunter he can't see his vehicle got attached but me can see his vehicle attached by hunter Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 You have to sync it. Client: bindKey("H", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel (vehicle) local x, y, z = getElementPosition(vehicle) if ( vehicle ) and ( id == 425 ) then local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) triggerServerEvent("attachVehicle", hitElement, vehicle) end end end ) Server: function attachVehicles(vehicle) attachElements(source, vehicle) end addEvent("attachVehicle", true) addEventHandler("attachVehicle", root, attachVehicles) Link to comment
#Madara Posted July 28, 2015 Author Share Posted July 28, 2015 (edited) You have to sync it.Client: bindKey("H", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel (vehicle) local x, y, z = getElementPosition(vehicle) if ( vehicle ) and ( id == 425 ) then local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) triggerServerEvent("attachVehicle", hitElement, vehicle) end end end ) Server: function attachVehicles(vehicle) attachElements(source, vehicle) end addEvent("attachVehicle", true) addEventHandler("attachVehicle", root, attachVehicles) i try to drop it but it's dosen't work Client : bindKey("H", "down", function() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel (vehicle) local x, y, z = getElementPosition(vehicle) if ( vehicle ) and ( id == 425 ) and getElementData(vehicle"AttachElements",true) then triggerServerEvent("detachVehicle",hitElement,vehicle) setElementData(vehicle,"AttachElements",false) elseif ( vehicle ) and ( id == 425 ) and getElementData(vehicle"AttachElements",false) then local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) triggerServerEvent("attachVehicle", hitElement, vehicle) setElementData(vehicle,"AttachElements",true) end end end ) Server : * deleted . DebugScript : client.lua:6: attempt to call local 'vehicle' ( a userdata value ) Edited July 28, 2015 by Guest Link to comment
Saml1er Posted July 28, 2015 Share Posted July 28, 2015 if ( vehicle ) and ( id == 425 ) and getElementData(vehicle"AttachElements",true) then triggerServerEvent("detachVehicle",hitElement,vehicle) setElementData(vehicle,"AttachElements",false) elseif ( vehicle ) and ( id == 425 ) and getElementData(vehicle"AttachElements",false) then to if ( vehicle ) and ( id == 425 ) and getElementData(vehicle, "AttachElements",true) then triggerServerEvent("detachVehicle",hitElement,vehicle) setElementData(vehicle,"AttachElements",false) elseif ( vehicle ) and ( id == 425 ) and getElementData(vehicle, "AttachElements",false) then Link to comment
Buffalo Posted July 28, 2015 Share Posted July 28, 2015 Try this: bindKey("H", "down",function() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle and getElementModel (vehicle) == 425 then if getElementData(vehicle,"AttachElements") then local hitElement = getElementData(vehicle,"AttachElements") if not isElement(hitElement) then return end triggerServerEvent("detachVehicle",hitElement,vehicle) setElementData(vehicle,"AttachElements",false,false) else local x, y, z = getElementPosition(vehicle) local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) triggerServerEvent("attachVehicle", hitElement, vehicle) setElementData(vehicle,"AttachElements",hitElement,false) end end end end) Link to comment
#Madara Posted July 28, 2015 Author Share Posted July 28, 2015 Try this: bindKey("H", "down",function() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle and getElementModel (vehicle) == 425 then if getElementData(vehicle,"AttachElements") then local hitElement = getElementData(vehicle,"AttachElements") if not isElement(hitElement) then return end triggerServerEvent("detachVehicle",hitElement,vehicle) setElementData(vehicle,"AttachElements",false,false) else local x, y, z = getElementPosition(vehicle) local dist = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) local offset = 2 local hit, _, _, _, hitElement = processLineOfSight(x, y, z-dist, x, y, z-dist-offset, false, true, false, false, false) if hit and getElementType(hitElement) == "vehicle" then outputChatBox("You attach "..getVehicleName(hitElement)) triggerServerEvent("attachVehicle", hitElement, vehicle) setElementData(vehicle,"AttachElements",hitElement,false) end end end end) Thank you very much . 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