local lastVeh = 0 local towTruck = 0 RegisterCommand("tow", function(src, args) --@TODO: Job check? local ped = PlayerPedId() if checkTowTarget() and checkTowRange() then print('success') end end) Citizen.CreateThread(function() local ped = PlayerPedId() while true do if IsPedInAnyVehicle(ped, false) then print('Ped is in any vehicle') local veh = GetVehiclePedIsIn(ped, true) -- Player in a new vehicle if lastVeh ~= veh then -- Player is in a vehicle check if it is a towtruck lastVeh = veh local hash = GetEntityModel(veh) local model = GetDisplayNameFromVehicleModel(hash) for i = 1, #Config.TowTrucks do if model == Config.TowTrucks[i] then towTruck = veh end end end end Citizen.Wait(1000) end end) function checkTowTarget() if lastVeh == towTruck then return false end return true end -- @TODO: Use offset behind towtruck for dist instead of Vdist2 -- Vehicle can be towed by pointing the nose of the towtruck at the vehicle -- But the vehicle being towed should only be able to be put on from behind the bed function checkTowRange() local towPos = GetEntityCoords(towTruck) local vehPos = GetEntityCoords(lastVeh) local dist = Vdist2(towPos, vehPos) if dist < 125 then return true else return false end end