Plainclothes and off-duty police officers have been killed by other officers. It is always a tricky situation when the on-duty crew shows up. Youd have to go into the details of each incident but its best to holster the weapon and show your hands.
That being said, it sure looks like theres an increasing tendency to shoot first and ask questions later. Maintaining cover and taking a couple of seconds to assess the situation would help.
Then there are incidents like this: