I tested that in Tanoa airfield with a pop-up target (400 m), a sniper and the player looking at the sequence.
So, don't say that doesn't work! It does. Or you have an addon or a script interfering with this small code.
Verify also, the sniper is in sight of the target. And for your info, setammo to 1 is not for one remaining mag but for one remaining bullet in the current mag. Otherwise, the sniper shoot every 3 seconds approx. Enjoy!