Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. local stickyEnabled = false
  2. local me = getLocalPlayer()
  3. local testMode
  4. local oldMad=10010101099023980
  5. function findRotation(x1,y1,x2,y2)
  6.  
  7. local t = -math.deg(math.atan2(x2-x1,y2-y1))
  8. if t < 0 then t = t + 360 end;
  9. return t;
  10.  
  11. end
  12. function isNumberBetweenPoints(number, pointa, pointb)
  13. return (number>pointa) and (number<pointb)
  14. end
  15. function isVehicleOnSteepSurface(veh)
  16. local x,y,z = getElementPosition(veh)
  17. local steepSurface,_,_,_,_,normalx,normaly,normalz=processLineOfSight(x,y,z+1,z,y,z-10,true,false,false,true,false,false,false,false,veh) --i suppose u know what to put in the veh arugments? yes i do =D
  18. if steepSurface then
  19. steepSurface = getDistanceBetweenPoints2D(normalx,normaly,0,0)>normalz
  20. else
  21. steepSurface = true
  22. end
  23. return steepSurface
  24. end
  25. function onRender()
  26. local veh = getPedOccupiedVehicle(me)
  27. if not veh then
  28. removeEventHandler("onClientRender",root,onRender)
  29. stickyEnabled = false
  30. outputChatBox("[VEH] Sticky wheels turned to: "..tostring(stickyEnabled))
  31. return
  32. end
  33. local vehicleIsSurfaced, gX,gY,gZ = isSurfaced(veh)
  34. local steepSurface = isVehicleOnSteepSurface(veh)
  35. if testMode ~= vehicleIsSurfaced then
  36. testMode = vehicleIsSurfaced
  37. outputDebugString("Is vehicle on a surface? : "..tostring(testMode))
  38. end
  39. if oldMad ~= steepSurface then
  40. oldMad = steepSurface
  41. outputDebugString("If on surface, is it steep? : "..tostring(oldMad))
  42. end
  43. if vehicleIsSurfaced and steepSurface then
  44. setVehicleGravity(veh, gX,gY,gZ)
  45. else
  46. setVehicleGravity(veh,0,0,-1)
  47. end
  48. end
  49.  
  50. function getPositionBelowElement(element)
  51. local matrix = getElementMatrix (element)
  52. local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1]
  53. local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2]
  54. local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3]
  55. return offX,offY,offZ
  56. end
  57.  
  58. function isSurfaced(element)
  59. local x,y,z = getElementPosition(element)
  60. local bX,bY,bZ = getPositionBelowElement(element)
  61. local nX,nY,nZ = bX-x,bY-y,bZ-z
  62. local isSurface, sX, sY, sZ, surfaceObj = processLineOfSight(x, y, z, bX,bY,bZ, true, false, false, true, false)
  63. return isSurface, nX,nY,nZ
  64. end
  65.  
  66. function stopSticky()
  67. if stickyEnabled then
  68. removeEventHandler("onClientRender",root,onRender)
  69. veh = getPedOccupiedVehicle(me)
  70. if veh then
  71. setVehicleGravity(veh,0,0,-1)
  72. end
  73. else
  74. addEventHandler("onClientRender",root,onRender)
  75. end
  76. stickyEnabled = not stickyEnabled
  77. outputChatBox("[VEH] Sticky wheels turned to: "..tostring(stickyEnabled))
  78. end
  79.  
  80. addCommandHandler("sticky",stopSticky)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement