SRD said:hooting or Throwing into a Melee
If you shoot or throw a ranged weapon at a target engaged in melee with a friendly character, you take a -4 penalty on your attack roll. Two characters are engaged in melee if they are enemies of each other and either threatens the other. (An unconscious or otherwise immobilized character is not considered engaged unless he is actually being attacked.)
If your target (or the part of your target you’re aiming at, if it’s a big target) is at least 10 feet away from the nearest friendly character, you can avoid the -4 penalty, even if the creature you’re aiming at is engaged in melee with a friendly character.
Precise Shot
If you have the Precise Shot feat you don’t take this penalty.
I'm reminded of Fiona telling Shrek "There's an arrow in your butt!"However if you want to get creative just in case somebody rolls a 1...
3.5 GMs, correct me if I'm wrong, but a character with the Precise Shot Feat have a 0% chance of hitting an ally when firing or throwing ranged weapons at targets engaged in melee.
That's the whole point of that feat, yes?
(And, it seems like a powerful Feat to me.)
Would you consider a target that is engaged in melee with your ally to be flatfooted with respect to you, even if he knows you're there?

(Dungeons & Dragons)
Rulebook featuring "high magic" options, including a host of new spells.