Armed police arrested a man outside a Yorkshire primary school after he dialled 999 and told them he was carrying a loaded gun.
Police marksmen found Darren Hyland in possession of three knives when they were called to the incident in front of the gates at Hovingham Primary School, Gipton.
Hyland refused to take his hands out of his pockets during a stand-off and told officers: "What will it take for you to shoot me?"
-> Watch woman stage supermarket fall over orange juice cartons as part of £3,000 scam
Stephen Welch, prosecuting, told Leeds Crown Court how police were sent the school on St Wilfrid's Drive just after 6am on March 11 this year.
Hyland contacted emergency services claiming he was in possession of a handgun and ammunition.
Officers arrived and found Hyland walking up and down and "extremely upset",
They instructed him to take his hands out of his pockets but he refused.
Mr Welch said: "He said 'this isn't going the way I thought it would be' and said that he needed to be sectioned before someone got killed or injured."
Hyland eventually agreed to take his hands out of his pockets and was handcuffed and searched.
-> Two men and 15-year-old boy jailed for automatic assault rifle shooting
The 24-year-old was found in possession of three kitchen knives which he claimed he had taken from his brother's kitchen.
Hyland was interviewed and admitted to officers that he had been trying to get himself shot.
The defendant said he had mental health issues but had been struggling to get NHS help.
He also admitted he had been thinking about committing the offence for ten months.
Hyland, of no fixed address, pleaded guilty to three offences of possession of a bladed article.
He has no previous convictions.
Joanna Shepherd, mitigating, said Hyland went to St James's Hospital in Leeds six months before the incident because he was "in crisis".
She said: "All too often in these type of cases he was turned away because he was not regarded as someone in sufficient need of the limited services available."
Miss Shephard said Hyland had been held in custody since the incident.
She added that Hyland had the full support of his family.
Hyland was given a four-month sentence, suspended for 12 months, and ordered to take part in a 20-day rehabilitation programme.
Judge Mushtaq Khokhar said: "You wanted to be shot. I accept that was the case otherwise it would have served no purpose whatsoever for you to make that call."
The judge added: "Why someone can be driven to such extremes, wanting to take one's own life can only be due to mental health."