Advertisement
daixso

brp-towing

Feb 7th, 2021
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. local lastVeh = 0
  2. local towTruck = 0
  3.  
  4. RegisterCommand("tow", function(src, args)
  5.     --@TODO: Job check?
  6.     local ped = PlayerPedId()
  7.  
  8.     if checkTowTarget() and checkTowRange() then
  9.         print('success')
  10.     end
  11. end)
  12.  
  13. Citizen.CreateThread(function()
  14.     local ped = PlayerPedId()
  15.     while true do
  16.         if IsPedInAnyVehicle(ped, false) then
  17.             print('Ped is in any vehicle')
  18.             local veh = GetVehiclePedIsIn(ped, true)
  19.             -- Player in a new vehicle
  20.             if lastVeh ~= veh then
  21.                 -- Player is in a vehicle check if it is a towtruck
  22.                 lastVeh = veh
  23.                 local hash = GetEntityModel(veh)
  24.                 local model = GetDisplayNameFromVehicleModel(hash)
  25.                 for i = 1, #Config.TowTrucks do
  26.                     if model == Config.TowTrucks[i] then
  27.                         towTruck = veh
  28.                     end
  29.                 end
  30.             end
  31.         end
  32.         Citizen.Wait(1000)
  33.     end
  34. end)
  35.  
  36. function checkTowTarget()
  37.     if lastVeh == towTruck then return false end
  38.     return true
  39. end
  40.  
  41. -- @TODO: Use offset behind towtruck for dist instead of Vdist2
  42. -- Vehicle can be towed by pointing the nose of the towtruck at the vehicle
  43. -- But the vehicle being towed should only be able to be put on from behind the bed
  44. function checkTowRange()
  45.     local towPos = GetEntityCoords(towTruck)
  46.     local vehPos = GetEntityCoords(lastVeh)
  47.     local dist = Vdist2(towPos, vehPos)
  48.  
  49.     if dist < 125 then
  50.         return true
  51.     else
  52.         return false
  53.     end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement