Nikolas Cruz, 19, described by fellow pupils as a “weird and racist” gun-obsessed loner, has been charged with murdering 17 people at his former school in Parkland, an affluent suburb north of Miami, Florida.

According to one of the group’s leaders, Cruz trained with Republic of Florida, which campaigns for a “white ethno-state”. The teenage gunman charged with unleashing one of America’s worst school shootings had been trained by a white supremacist paramilitary group, and may have chosen Valentine’s Day to strike after the end of a relationship with a girlfriend.

Jordan Jereb said Cruz had probably relied on his training to carry out the attack, but had not been told to do so by anybody at the organisation.

He said Cruz “acted on his own behalf” and was “solely responsible for what he just did”. Jereb also said Cruz had “trouble with a girl” and the Valentine’s Day timing was probably not a coincidence.

It also emerged that Cruz had previously been treated at a mental health clinic, but was still able to legally purchase an AR-15 rifle, and large amounts of ammunition, passing a background check in February 2017.

Melissa McNeil, Cruz’s lawyer, said he suffered from autism. She added: “The child is deeply troubled and he has endured significant trauma that stems from the loss of his mother.”

Immediately after the shooting Cruz went to a nearby Subway restaurant and bought a drink. Then he moved to a McDonald’s and “sat down for a short period of time,” local sheriff Scott Israel said. He then left and was arrested 40 minutes later.

Cruz was placed on suicide watch in jail.

Donald Trump delivered a sombre address from the White House after the 18th school shooting in the country this year, but he avoided any mention of curbing access to guns.

Instead, the US president said he would “tackle the difficult issue of mental health” and that there had been “so many signs” that Cruz was “mentally disturbed.”

He added on Twitter: “Neighbours and classmates knew he was a big problem. Must always report such instances to authorities, again and again!”

Jeff Sessions, the attorney general, said: “It cannot be denied that something dangerous and unhealthy is happening. We are going to take action. We must reverse these trends.”

And Rick Scott, the Florida governor, said: “If someone is mentally ill, they can’t have access to a gun.” Barack Obama, the former president, said on Twitter: “Until we can honestly say that we’re doing enough to keep them [our kids] safe from harm, including long overdue, common-sense gun-safety laws that most Americans want, then we have to change.”

Survivors of the mass shooting also demanded action. David Hogg, a pupil who witnessed it, said: “We’re children. You guys are the adults. You need to take some action and play a role. Work together, come over your politics, and get something done.”

Another pupil named Sarah wrote on Twitter: “Multiple of my fellow classmates are dead, Do something instead of sending prayers. Prayers won’t fix this. But gun control will prevent it from happening again.”