Find the ordinary generating function $h(z)$ for a Gambler's Ruin variation. Assume we have a random walk starting at 1 with probability of moving left one space $q$, moving right one space $p$, and staying in the same place $r=1-p-q$. Let $T$ be the number of steps to reach 0. Find $h(z)$, the ordinary generating function.
My idea was to break $T$ into two variables $Y_1,Y_2$ where $Y_1$ describes the number of times you stay in place and $Y_2$ the number of times we move forward or backward one. Then try to find a formula for $P(T=n)=P(Y_1+Y_2=n)=r_n$, but I'm getting really confused since there are multiple probabilities possible for each $T=n$ for $n\geq 3$. Once I have $r_n$ I can then use $h_T(z)=\sum_{n=1}^\infty r_n z^n$, but I'm not sure where to go from here.

This isn't another answer, but something that seems worth adding and is too long for a comment.
What makes the probabilities for hitting times nice to work with is that their generating functions combine by multiplication, due to a sort of transitivity: If $A\gt B\gt C$, then to get from $A$ to $C$ for the first time, you have to get from $A$ to $B$ for the first time and then get from $B$ to $C$ for the first time. Summing over the hitting time for $B$ yields a convolution, and thus multiplication of the generating functions.
This leads to the simple equation $h=z(q+rh+ph^2)$ (see the other answers and my comments under Brian's). The generating functions for the probabilities of ending up somewhere at some time, but not necessarily for the first time, don't have this nice property, but we can obtain them from the ones for the hitting times.
The generating function $f$ for the probabilities for the return time (the first time to return to the same place) satisfies
$$f=z(qg+r+ph)\;,$$
where $g$ is the generating function for the hitting time for first hitting the origin starting at $-1$. This equation arises just like the one for $h$: We go left with probability $q$ and then have to hit the origin starting at $-1$, or we stay at the origin with probability $r$ and thus "return" in one step, or we go right with probability $p$ and then have to hit the origin starting at $1$.
The numerator of $h$ is invariant with respect to interchange of $p$ and $q$, so $g$ is $h$ with $p$ in the denominator replaced by $q$. Thus $f$ takes the simple form
$$f=1-\sqrt{(1-rz)^2-4pqz^2}\;.$$
We can get the generating function $F$ for the probabilities of ending up where we started (not necessarily for the first time) from $f$ via
$$F=\frac1{1-f}\;.$$
This can be derived either as in this answer, or by noting that the probability for returning to the same place is the sum over all $n$ of the probabilities for returning there for the $n$-th time, and the generating function for returning for the $n$-th time is obtained by an $n$-fold convolution as $f^n$, so
$$F=1+f+f^2+\dotso=\frac1{1-f}\;.$$
Thus we have
$$F=\frac1{\sqrt{(1-rz)^2-4pqz^2}}\;.$$
Finally, we can get the generating function $H$ for ending up at $0$ starting from $1$, not necessarily for the first time, as the product
$$H=hF=\frac1{2pz}\left(\frac{1-rz}{\sqrt{(1-rz)^2-4pqz^2}}-1\right)\;.$$
