the AIGotoPosition() calculates the pathing but you can't get any info from it - hence why i say GG does it backwards
with a few tweaks amen's edit of your script works fine (most notably it got stuck in the 'runtoplayer' state so i moved it further down the list and it now attacks correctly)
p.s. the stock AI is not really a good place for a tutorial as if you look at the code it actually uses way more logic than it needs to and some is broken... i.e.
the above command only accepts 3 parameters not 4 (no Y) and actually does nothing because of this but it's used many times in the core AI scripts.
however it does hold the secret to using manual movement with pathing