The present perfect is usually used to describe actions or situations that started or occurred in the past and are connected to the present:
I have lived here for three years. (From three years ago up to now)
The past perfect therefore refers to an action or situation that happened in the past but started ‘before’; further back in the past.
I had lived there for three years before I found a job.
I didn’t go to see the film with Peter because I had seen it before.
The past perfect can also be used to describe a situation that started before the past time you are talking about but still happens or exists up to the point being referred to.
He was my closest friend. We had known each other since kindergarten.
To describe a sequence of events in chronological order; in the sequence that they happened then we use the past simple;
I woke up early, had a shower, had breakfast and went out to meet Sarah at a cafe.
But if we change the sequence of events and refer back to an event we use the past perfect.
I woke up early, had a shower and went out to meet Sarah. I didn’t eat anything at the cafe because I had already eaten breakfast (before).
To talk about actions that happen just before a main event in the past the past perfect can be used;
They had just started the meeting when I walked in.
He was really excited because he had just received his exam results.
The past perfect can be used with the continuous form;
I had been living there for three years before I found a job.
The past perfect continuous is usually used to talk about an action that started before the time mentioned and ‘continued’ up to the point in the past that the speaker is referring to.
It is also used to focus on the duration of the activity or situation.
We had been walking for only thirty minutes before it started raining.