nice1.
I've the same issues with my little bot test with blindbot.lua on SLiP but I've solved it by having not 1 target but at least 3 (array of 3 unsigned int).
...recently I've found that you can use the autoselect routines without touching any pk2 file and just by a loader,
(
).
and before that you can see explanations of it from pushedx and others.
but well, that post in that thread with those explanations might improve your bot.
Edit: I know it might not have it anymore but if you've read that thread you will notice by pushedx comments how to rewrite it (you can even use the pickup routine because it has a similar logic).
Hope it helps.