Win32 API mouse input and trigger a mouse click in Windows when crosshair on enemy head (more likely when crosshair is within enemy head position).
or the game engine could track internally what the player is looking at (GTA does this).
It's a bit slow, but you could grab the player ID, then check if the player is on your team or not and then fire. Either by sending a mouse input, or if I remember correctly by writing to a specific address.
However, with enough knowledge (which is mostly documented online) you could actually pull out the hitbox, skeleton and animation data and just run the line-box intersection step yourself. Easier to do internally by hooking in-game functions though.