Gaborboy95 Posted April 6, 2018 Share Posted April 6, 2018 (edited) Hi. I want to make a script that opens the nearest door on the car when right clicking. But i don't know ho to start. My explanation is not very good, i know. If needed i will somehow explain further. But here's a video : https://www.youtube.com/watch?v=yr4PBGSawhY Edited April 6, 2018 by Gaborboy95 Expanded Link to comment
William147 Posted April 11, 2018 Share Posted April 11, 2018 Hi. Use bindKey and getVehicleComponentPosition with world argument. Link to comment
Gaborboy95 Posted April 15, 2018 Author Share Posted April 15, 2018 On 2018. 04. 11. at 19:27, XricsmondX said: Hi. Use bindKey and getVehicleComponentPosition with world argument. Can you make me an example for 1 door? Link to comment
William147 Posted April 16, 2018 Share Posted April 16, 2018 I writed a half script, you can see the method. function getNearestVehicle(player,distance) local tempTable = {} local lastMinDis = distance-0.0001 local nearestVeh = false local px,py,pz = getElementPosition(player) local pint = getElementInterior(player) local pdim = getElementDimension(player) for _,v in pairs(getElementsByType("vehicle")) do local vint,vdim = getElementInterior(v),getElementDimension(v) if vint == pint and vdim == pdim then local vx,vy,vz = getElementPosition(v) local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) if dis < distance then if dis < lastMinDis then lastMinDis = dis nearestVeh = v end end end end return nearestVeh end bindKey("mouse2","down",function() nVeh = getNearestVehicle(localPlayer,5) door_rf_dummyX,door_rf_dummyY,door_rf_dummyZ = getVehicleComponentPosition ( nVeh, "door_rf_dummy", "world" ) door_lf_dummyX,door_lf_dummyY,door_lf_dummyZ = getVehicleComponentPosition ( nVeh, "door_lf_dummy", "world" ) door_rb_dummyX,door_rb_dummyY,door_rb_dummyZ = getVehicleComponentPosition ( nVeh, "door_rb_dummy", "world" ) or 0,0,0 door_lb_dummyX,door_lb_dummyY,door_lb_dummyZ = getVehicleComponentPosition ( nVeh, "door_lb_dummy", "world" ) or 0,0,0 px,py,pz = getElementPosition(localPlayer) distances = { {getDistanceBetweenPoints3D(px,py,pz,door_rf_dummyX,door_rf_dummyY,door_rf_dummyZ),"door_rf_dummy"}, {getDistanceBetweenPoints3D(px,py,pz,door_lf_dummyX,door_lf_dummyY,door_lf_dummyZ),"door_lf_dummy"}, {getDistanceBetweenPoints3D(px,py,pz,door_rb_dummyX,door_rb_dummyY,door_rb_dummyZ),"door_rb_dummy"}, {getDistanceBetweenPoints3D(px,py,pz,door_lb_dummyX,door_lb_dummyY,door_lb_dummyZ),"door_lb_dummy"}, } table.sort(distances,function(a, b) return a[1] < b[1] end) outputChatBox(distances[1][2]) setVehicleComponentRotation(nVeh,distances[1][2],0,0,-45) end) Link to comment
Gaborboy95 Posted April 16, 2018 Author Share Posted April 16, 2018 Okay, got it fully working, but one more question. How do I make the door opening "smooth" ? Link to comment
Verius Posted April 16, 2018 Share Posted April 16, 2018 39 minutes ago, Gaborboy95 said: Okay, got it fully working, but one more question. How do I make the door opening "smooth" ? You should use: interpolateBetween() Link to comment
Gaborboy95 Posted April 17, 2018 Author Share Posted April 17, 2018 Thank you all for your help! Link to comment
Gaborboy95 Posted April 17, 2018 Author Share Posted April 17, 2018 I can't get interpolateBetween working. Link to comment
Verius Posted April 17, 2018 Share Posted April 17, 2018 (edited) Here's example (based of XricsmondX code): local distances = {} local currentVeh = nil local startTick = nil local animTime = 1000 -- in miliseconds local toRotation = nil local fromRotation = nil function getNearestVehicle(player,distance) local tempTable = {} local lastMinDis = distance-0.0001 local nearestVeh = false local px,py,pz = getElementPosition(player) local pint = getElementInterior(player) local pdim = getElementDimension(player) for _,v in pairs(getElementsByType("vehicle")) do local vint,vdim = getElementInterior(v),getElementDimension(v) if vint == pint and vdim == pdim then local vx,vy,vz = getElementPosition(v) local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) if dis < distance then if dis < lastMinDis then lastMinDis = dis nearestVeh = v end end end end return nearestVeh end local function interpolate() local progress = (getTickCount() - startTick) / animTime local rotZ = interpolateBetween(fromRotation, 0, 0, toRotation, 0, 0, progress, "Linear") setVehicleComponentRotation(currentVeh, distances[1][2], 0, 0, rotZ) end bindKey("mouse2","down",function() nVeh = getNearestVehicle(localPlayer,5) door_rf_dummyX,door_rf_dummyY,door_rf_dummyZ = getVehicleComponentPosition ( nVeh, "door_rf_dummy", "world" ) door_lf_dummyX,door_lf_dummyY,door_lf_dummyZ = getVehicleComponentPosition ( nVeh, "door_lf_dummy", "world" ) door_rb_dummyX,door_rb_dummyY,door_rb_dummyZ = getVehicleComponentPosition ( nVeh, "door_rb_dummy", "world" ) or 0,0,0 door_lb_dummyX,door_lb_dummyY,door_lb_dummyZ = getVehicleComponentPosition ( nVeh, "door_lb_dummy", "world" ) or 0,0,0 px,py,pz = getElementPosition(localPlayer) distances = { {getDistanceBetweenPoints3D(px,py,pz,door_rf_dummyX,door_rf_dummyY,door_rf_dummyZ),"door_rf_dummy"}, {getDistanceBetweenPoints3D(px,py,pz,door_lf_dummyX,door_lf_dummyY,door_lf_dummyZ),"door_lf_dummy"}, {getDistanceBetweenPoints3D(px,py,pz,door_rb_dummyX,door_rb_dummyY,door_rb_dummyZ),"door_rb_dummy"}, {getDistanceBetweenPoints3D(px,py,pz,door_lb_dummyX,door_lb_dummyY,door_lb_dummyZ),"door_lb_dummy"}, } table.sort(distances,function(a, b) return a[1] < b[1] end) outputChatBox(distances[1][2]) currentVeh = nVeh fromRotation = 0 --here's start rotation of door toRotation = -45 --here's end rotation startTick = getTickCount() addEventHandler("onClientRender", getRootElement(), interpolate) --setVehicleComponentRotation(nVeh,distances[1][2],0,0,-45) end) Or you also can use deltaTime(timeSlice) from onClientPreRender. But in my opinion interpolateBetween is better idea. I forgot - you also should check if progress == 1 and use removeEventHandler in interpolate function. Edited April 17, 2018 by Verius tip 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