Furthermore, how is it possible that sometimes the cursor is at a distance of for instance 2413 or 4186 pixels from the player? I strongly doubt it's because of this simple calculation in which nothing should go wrong:
1
math.floor( math.sqrt(((player(id, "x") - x) ^ 2) + ((player(id, "y") - y) ^ 2)) + 0.5 )