Three New Jersey officers trapped in floodwaters Wednesday evening were able to stay alive by clinging to trees and firing their duty pistols to alert rescuers to their location

NJ.com reports that Hopewell Township Officer James Hoffman was swept away in the floodwaters while responding to a report of a car trapped in the same hazard.

Hoffman’s patrol car started taking on water, then started floating away — sliding sideways about 100 yards into deeper water. He ditched his bulky duty vest, climbed through a window and started swimming. He found a tree and held on.

Two officers who went to look for Hoffman — Michael Makwinski and Robert Voorhees — were also swept into the raging waters and also had to leave their vehicle, the agency says.

They too found trees to anchor themselves.

As firefighters zeroed in on their exact location, the officers fired their guns to mark their location.

A crew from the Hamilton Fire Department, led by Battalion Chief Tim Sharpley, led the final rescue, bringing the three into boats.