Officers were called to a field off Westfield Lane, at 7.45pm, on July 5, where Robert Armstrong was firing at a bullseye target and a spinning chicken target.
An open laptop nearby was playing a Youtube lesson on how to calibrate the telescopic sight of the .22 rifle, the court heard.
Armstrong, 41, of Devon Road, Newark, admitted possessing the air weapon in a public place, when he appeared at Mansfield Magistrates Court, on Thursday.
Morgan Hogarth, mitigating, said Armstrong had borrowed the rifle from a friend.
“The owner knows that the air rifle can only be fired on a firing range or on private property. Mr Armstrong was ignorant of the law and was firing in a public field.”
He said Armstrong, a former heroin addict, had a “lengthy record” for shoplifting, which slowed to one offence a year between 2012 and 2014.
But when the case was adjourned for a probation report to be prepared, police officers arrived at the court house and took Armstrong into an interview room where he was strip searched.
A witness said: “He was clearly visible, even though the blinds were down.”
Court proceedings were delayed while the search took place, and Mr Hogarth said the search was “inappropriate”.
The police were called after someone alleged Armstrong was carrying drugs.
He was given a 12 month community order, with a three month curfew which will be monitored by electronic tag, between 8pm to 8am.
He must pay £85 court costs and an £85 victim surcharge.
Magistrates told him: “A bullet pinging off the spinning chicken could have injured someone. You ought to have been more thoughtful.”