The crazed gunman who terrorized the campus of St. John’s University traveled all around the Big Apple in preparation for his bizarre appearance on campus wearing a mask and toting a musket-style rifle, according to court documents released yesterday.

Omesh Hiraman, 22, first made his way to a costume shop in Manhattan around noon Thursday to purchase a Fred Flintstone mask, he told detectives after being tackled by security on the Queens campus.

He then took a taxi back to his home in Jackson Heights where he picked up the gun – a muzzle-loaded, Wolf 209 Magnum rifle, according to the statement he made to police.

After loading the weapon into a plastic bag, Hiraman took another taxi to the school’s Jamaica campus, placed the mask atop his head and walked onto school grounds at the Union Turnpike entrance with the rifle in hand.

Hiraman walked around the school’s tennis courts, walked up some stairs near the Marillac Hall and towards St. John’s Hall where he pulled the mask down over his face.

Brandishing the rifle, he briefly entered the building but came back out again and started walking towards Council Hall where he was finally stopped but a member of the police cadet corps and campus security. School officials quickly alerted other students to what had happened by a campus-wide text message.

The statement came out in Queens County criminal court yesterday where Hiraman pleaded not guilty at his arraignment from the police ward at Bellevue Hospital via closed circuit television. Judge Debra Stephens Modica ordered him to undergo psychological evaluation; he will return to court Oct. 9.

Wearing pale blue hospital pajamas, Hiraman appeared somewhat dazed and his hands shook and his body rocked as he answered all the judge’s questions with simple “yes, ma’am,” or “yes, your honor.”

His attorney, Anthony Colleluori, described his client as “delusional” and said he had recently undergone back surgery that left him in great pain which had a bad reaction with the medication he takes for schizophrenia.

“He’s a paranoid schizophrenic and he was having a reaction to medication and to pain,” he said.

No one was hurt in the incident, and Colleluori said NYPD ballistics experts had test-fired the weapon his client was carrying and that it fired at a “very low velocity.”

“Whoever packed this gun didn’t know what they were doing,” he said.

Hiraman legally purchased the gun at a Poughkeepsie gun shop, as the weapon – which qualifies as an antique – didn’t require him to have a permit or even show identification.

So far, police have only charged Hiraman with two counts of criminal possession of a weapon – which is only punishable by a year in prison.