Does an invisible creature trigger an opportunity attack if it makes a ranged attack?
And if it does, is the opportunity attack -5 as it's against an invisible creature?
Where does the invisibility go down in the sequence?
No, Invisible Creatures Do Not Provoke Opportunity Attacks
(From Enemies That Can't See Them)
From page 221 of the Rules Compendium:
While it is true that attacking will cause a creature to no longer be hidden, it will still retain the benefits of being hidden (including not provoking an opportunity attack) until the attack resolves. On page 153:
As defined on pages 196-197, opportunity actions (such as the opportunity attack) are interrupts, and therefore occur before their triggering action resolves:
Putting all of this together, you can see that the opportunity attack would not be provoked by an invisible creature making a ranged attack against an adjacent creature. The invisible creature's "doesn't provoke opportunity attacks" benefit would not be lost until the attack resolves, but an opportunity attack would have to occur prior to that attack resolving, and therefore the opportunity attack never occurs.
To break it down into a sort of sequence of situational facts/events:
So, at the time that the opportunity attack would ordinarily trigger, the attacking creature still has the benefits of invisibility and no opportunity attack can trigger.