I got a $2$D triangle, each vertex has a $2$D coordinate with a $z$-index value (NOT a $z$ coordinate!). The $z$-index value indicates whether a vertex lays on, in front of, or behind your screen (viewing plane). Negative value is behind, 0 is exactly on the plane and positive value is in front. It looks like: ($x_{\text{coord}},y_{\text{coord}},z_{\text{index}})$. Note that it always remains a $2$D triangle, the $z$-index is needed for my $z$-buffer. Now the question: how would I find the $z_{\text{index}}$ of a pixel on any given $2$d point on the triangle? I know that it has to do with interpolation between the $z$-indices respectively to the triangle's coordinates. I just don't know how to.
For example:
$A=(12,36)$; $z_{\text{index}}=5$, or $B=(12,36,5)$
$B=(50,80)$; $z_{\text{index}}=8$, or $B=(50,80,8)$.
$C=(5,24)$; $z_{\text{index}}=15$, or $C=(5,24,15)$.
This sketch should give a clearer idea (not to scale):

At any given point $Q(x,y)$ (for example $Q(60,40)$ ), what would be the $z$-index ($z$') at that pixel? Is there a small formula for it?
After reading the theory behind "barycentric coordinates" and the term "weighted average", and with the help of the small answer to this question: Z-index of an arbitrary point on a flattened 3-dimensional triangle , I was able to construct a working pseudo code sample after many attempts: (v1, v2 and v3 are the triangle's vertices; p is a random point on or outside of the triangle; b contains the barycentric coordinates of p)
In this example, point P is the triangle center. The new_z_index value gives the result 11, which when checked by averaging the sum of the vertices: (10+18+5)/3 also equals 11.