RegisterNetEvent('txos_trucking:startJobClient') AddEventHandler('txos_trucking:startJobClient', function(data, jobid, timer) working = true StateID = jobid timeRemain = tonumber(timer) truck, trailer = loadVehicle(data.vehicles[1], data.start[1], data.start[2]), loadVehicle(data.vehicles[2], data.trailer[1], data.trailer[2]) SetVehicleEngineOn(truck,true,true) destinationBlip, truckBlip, trailerBlip = addBlip(data.arrive, 38, 3, Strings['destination']) RemoveBlip(startBlip) while working do local sleepTimer, distance = 250, GetDistanceBetweenCoords(data.arrive, GetEntityCoords(trailer), true) if not IsPedInVehicle(GetPlayerPed(-1), truck, false) then screenText(Strings['get_to_truck'], 250) if not DoesBlipExist(truckBlip) then truckBlip = addBlip(GetEntityCoords(truck), 477, 5, Strings['truck']) SetBlipRoute(truckBlip, true) end if DoesBlipExist(trailerBlip) then RemoveBlip(trailerBlip) end if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end else if not IsVehicleAttachedToTrailer(truck, trailer) then screenText(Strings['get_to_trailer'], 250) if not DoesBlipExist(trailerBlip) then trailerBlip = addBlip(GetEntityCoords(trailer), 479, 5, Strings['trailer']) SetBlipRoute(trailerBlip, true) end if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end else if DoesBlipExist(trailerBlip) then RemoveBlip(trailerBlip) end if not DoesBlipExist(destinationBlip) then destinationBlip = addBlip(data.arrive, 38, 3, Strings['destination']) SetBlipRoute(destinationBlip, true) end end if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end end if distance <= 45.0 and IsPedInVehicle(GetPlayerPed(-1), truck, false) and IsVehicleAttachedToTrailer(truck, trailer) then sleepTimer = 0 DrawMarker(1, data.arrive, vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 255, 50, 150, false, false, 2, false, false, false) if distance <= 10.0 then while IsVehicleAttachedToTrailer(truck, trailer) do screenText(Strings['detach'], 250) Citizen.Wait(250) end break else screenText(Strings['park']) end else if IsPedInVehicle(GetPlayerPed(-1), truck, false) and IsVehicleAttachedToTrailer(truck, trailer) then screenText(Strings['drive_destination'], 250) end end Citizen.Wait(sleepTimer) end RemoveBlip(truckBlip) RemoveBlip(destinationBlip) RemoveBlip(trailerBlip) if timeRemain == 0 then DeleteVehicle(trailer) else deleteVehDelay(trailer) end while working do local sleepTimer, distance = 250, GetDistanceBetweenCoords(GetEntityCoords(truck), data.start[1], true) if not IsPedInVehicle(GetPlayerPed(-1), truck, false) and distance >= 10.0 then screenText(Strings['get_to_truck'], 250) if not DoesBlipExist(truckBlip) then truckBlip = addBlip(GetEntityCoords(truck), 477, 5, Strings['truck']) SetBlipRoute(truckBlip, true) end if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end else if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end if not DoesBlipExist(destinationBlip) then destinationBlip = addBlip(data.start[1], 38, 3, Strings['destination']) SetBlipRoute(destinationBlip, true) end if distance <= 30.0 then sleepTimer = 0 DrawMarker(1, data.start[1], vector3(0.0, 0.0, 0.0), vector3(0.0, 0.0, 0.0), vector3(1.0, 1.0, 1.0), 255, 255, 50, 150, false, false, 2, false, false, false) if distance <= 10.0 then if IsPedInVehicle(GetPlayerPed(-1), truck, false) then screenText(Strings['get_out']) else if DoesBlipExist(destinationBlip) then RemoveBlip(destinationBlip) end if DoesBlipExist(truckBlip) then RemoveBlip(truckBlip) end break end else screenText(Strings['park_truck']) end else screenText(Strings['drive_back'], 250) end end Citizen.Wait(sleepTimer) end local damages = {['windows'] = {}, ['tires'] = {}, ['doors'] = {}, ['body_health'] = GetVehicleBodyHealth(truck), ['engine_health'] = GetVehicleEngineHealth(truck)} for i = 0, GetVehicleNumberOfWheels(truck) do if IsVehicleTyreBurst(truck, i, false) then table.insert(damages['tires'], i) end end for i = 0, 13 do if not IsVehicleWindowIntact(truck, i) then table.insert(damages['windows'], i) end end for i = 0, GetNumberOfVehicleDoors(truck) do if IsVehicleDoorDamaged(truck, i) then table.insert(damages['doors'], i) end end if timeRemain == 0 then working = false TriggerServerEvent('txos_trucking:jobComplete', jobid, damages, true) deleteVehDelay(truck) else working = false TriggerServerEvent('txos_trucking:jobComplete', jobid, damages, false) deleteVehDelay(truck) end end)