The US Attorney's Office of the Northern District of Texas announced on Friday that William Patrick Williams, from Lubbock, Texas, had been arrested.

announced on Friday that William Patrick Williams, from Lubbock, Texas, had been arrested. Officials said Williams was plotting a mass shooting, but was stopped when his grandmother learned about his plan and persuaded him to go to a hospital instead.

Police said in a criminal complaint seen by the US Attorney's Office said Williams had told his grandmother that he had bought an AK-47 rifle and had planned to "shoot up" a local hotel and then "then commit suicide by cop" on July 13.

then "then commit suicide by cop" on July 13. Officers found an AK-47 rifle, 17 magazines loaded with ammunition, knives, a black trench coat, black tactical pants, a black t-shirt that read "Let 'Em Come," and black tactical gloves in a hotel room rented by Williams.

Visit INSIDER's homepage for more stories.

A 19-year-old man in Texas who was plotting a mass shooting was stopped when his grandmother learned about his plan and persuaded him to go to a hospital instead, officials said.

The US Attorney's Office of the Northern District of Texas announced on Friday that William Patrick Williams, from Lubbock, Texas, had been arrested by special agents of the FBI and Bureau of Alcohol, Tobacco, Firearms and Explosives on Thursday, days before 29 people were killed in deadly shootings in the US over the weekend.

Police said in a criminal complaint seen by the US Attorney's Office that Williams had told his grandmother he had bought an AK-47 rifle and had planned to "shoot up" a local hotel and then "then commit suicide by cop" on July 13.

His grandmother sensed he was suicidal and homicidal, and was able to bring him to a local hospital instead, the US Attorney's Office of the Northern District of Texas said in its press release about Williams' arrest.

William Patrick Williams. Lubbock County Jail via AP

Williams was arrested after his hospitalization and gave police consent to search a hotel room he had rented. Officers found an AK-47 rifle, 17 magazines loaded with ammunition, knives, a black trench coat, black tactical pants, a black t-shirt that read "Let 'Em Come," and black tactical gloves.

Williams had purchased the AK-47 rifle on July 11. He listed a relative's address where he no longer lives on a firearms transaction form used to purchase the gun.

Read more: The FBI is warning there could by copycat attacks following the Dayton and El Paso shootings — and one man has already been arrested after police said he threatened to 'shoot up' another Walmart

"This was a tragedy averted," said US Attorney Nealy Cox. "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."

Williams has been charged with making false statements to a firearms dealer because of his claim that he lived at an address of a relative. If convicted, he faces up to five years in federal prison.

"The FBI worked closely with our partners at the ATF and Lubbock Police Department to prevent the defendant from potentially committing a violent act," Matthew DeSarno, Special Agent in Charge of the Dallas Field Office, said in a press release. "This case is a perfect example of law enforcement agencies coming together to find a solution that protected the public from harm."