Less than a month before two tragic mass shootings rocked the United States in just 13 hours, a man in Lubbock, Texas was plotting a different massacre. That plan was thwarted – thanks to the man's grandmother.

On August 2, the U.S. Attorney's Office for the Northern District of Texas put out a press release about the arrest of William Patrick Williams, a 19-year-old who was contemplating a mass shooting. The very next day, less than 500 miles away, a gunman opened fire at an El Paso Walmart, killing at least 21 people.

The difference between the two men is that Williams was stopped.

Get Breaking News Delivered to Your Inbox

On July 13, Williams allegedly told his grandmother he had purchased an AK-47 rifle. He told her he planned to "shoot up" a local hotel and then commit suicide by cop, according to a criminal complaint unsealed last week.

Williams' grandmother feared he was homicidal and suicidal and convinced him to go to a local hospital with her.

While in the hospital, Williams gave officers consent to search a hotel room he rented. It was there that the officers found an "AK-47 rifle, seventeen magazines loaded with ammunition, multiple knives, a black trench coat, black tactical pants, a black t-shirt that read 'Let 'Em Come,' and black tactical gloves with the fingers cut off," according to the U.S. Attorney's press release.

This undated photo from the Lubbock County Jail shows, William Patrick Williams, a Texas man whom investigators said was planning a mass shooting. / AP

According to the complaint, Williams was charged with making false statements to a federally-licensed firearms dealer, because he had listed his relatives' address where he no longer lives when purchasing the rifle.

"This was a tragedy averted," U.S. Attorney Nealy Cox said, according to the release. "I want to praise the defendant's grandmother, who saved lives by interrupting this plot, as well as the Lubbock police officers and federal agents who investigated his unlawful acquisition of a deadly weapon."

"If you suspect a friend or loved one is planning violence against themselves or others, do not hesitate to seek help immediately by calling law enforcement," Cox continued.

"The safety of our citizens is paramount," Lubbock Interim Police Chief Jerry Brewer said. "When events like this occur we greatly appreciate the cooperative relationships with our federal law enforcement partners that enhance our abilities to protect the community."

Williams faces up to five years in federal prison if convicted, according to the press release.