Advertisement
Guest User

seatbelt test

a guest
Jun 17th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. =====================================================
  2. ===================Client.lua========================
  3. =====================================================
  4.  
  5. local speedBuffer = {}
  6. local velBuffer = {}
  7. local beltOn = false
  8. local wasInCar = false
  9.  
  10. IsCar = function(veh)
  11. local vc = GetVehicleClass(veh)
  12. return (vc >= 0 and vc <= 7) or (vc >= 9 and vc <= 12) or (vc >= 17 and vc <= 20)
  13. end
  14.  
  15. Fwv = function (entity)
  16. local hr = GetEntityHeading(entity) + 90.0
  17. if hr < 0.0 then hr = 360.0 + hr end
  18. hr = hr * 0.0174533
  19. return { x = math.cos(hr) * 2.0, y = math.sin(hr) * 2.0 }
  20. end
  21.  
  22. Citizen.CreateThread(function()
  23. Citizen.Wait(500)
  24. while true do
  25.  
  26. local ped = GetPlayerPed(-1)
  27. local car = GetVehiclePedIsIn(ped)
  28.  
  29. if car ~= 0 and (wasInCar or IsCar(car)) then
  30.  
  31. wasInCar = true
  32.  
  33. if beltOn then DisableControlAction(0, 75) end
  34.  
  35. speedBuffer[2] = speedBuffer[1]
  36. speedBuffer[1] = GetEntitySpeed(car)
  37.  
  38. if speedBuffer[2] ~= nil
  39. and not beltOn
  40. and GetEntitySpeedVector(car, true).y > 1.0
  41. and speedBuffer[1] > Cfg.MinSpeed
  42. and (speedBuffer[2] - speedBuffer[1]) > (speedBuffer[1] * Cfg.DiffTrigger) then
  43.  
  44. local co = GetEntityCoords(ped)
  45. local fw = Fwv(ped)
  46. SetEntityCoords(ped, co.x + fw.x, co.y + fw.y, co.z - 0.47, true, true, true)
  47. SetEntityVelocity(ped, velBuffer[2].x, velBuffer[2].y, velBuffer[2].z)
  48. Citizen.Wait(1)
  49. SetPedToRagdoll(ped, 1000, 1000, 0, 0, 0, 0)
  50. end
  51.  
  52. velBuffer[2] = velBuffer[1]
  53. velBuffer[1] = GetEntityVelocity(car)
  54.  
  55. if IsControlJustReleased(0, 48) then -- z
  56. beltOn = not beltOn
  57. if beltOn then TriggerEvent('chatMessage', Cfg.Strings.belt_on)
  58. else TriggerEvent('chatMessage', Cfg.Strings.belt_off) end
  59. end
  60.  
  61. elseif wasInCar then
  62. wasInCar = false
  63. beltOn = false
  64. speedBuffer[1], speedBuffer[2] = 0.0, 0.0
  65. end
  66. Citizen.Wait(0)
  67. end
  68. end)
  69.  
  70. ===========================================================
  71. =======================Config.lua==========================
  72. ===========================================================
  73.  
  74. Cfg = {}
  75. Cfg.DiffTrigger = 0.255
  76. Cfg.MinSpeed = 19.25 --THIS IS IN m/s
  77. Cfg.Strings = { belt_on = 'Seatbelt ^5 buckled^0.', belt_off = 'Seatbelt ^1 unbuckled^0.' }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement