should add a sleep condition to check if you're attacking instead of a sleep(3000,6000); because that will cause it to click every 3-6 seconds
Also, i don't think you need to spin the camera to it as the client handles that when you attack it
Overall not a bad start