Last year, a man who worked at a car dealership in San Diego told his co-workers that he would shoot up the place if he were fired, and he praised the man who had carried out the Las Vegas massacre.

Another man told his fiancée he wanted to shoot her in the head, and also threatened to kill her ex-boyfriend. Still another told co-workers that he wished his supervisors would die, and that he could invite them hunting so it would look like an accident.

In all three cases, the men owned firearms. In all three cases, those weapons were taken away after the San Diego city attorney obtained a gun violence restraining order, a measure the authorities or relatives can request from a judge to temporarily remove firearms from people deemed to be a threat to themselves or others.

California is one of 17 states with a “red flag” law authorizing those kinds of orders. Most of the laws were passed after the February 2018 massacre in Parkland, Fla., where a 19-year-old man used a semiautomatic assault weapon to kill 17 students and others.

Now, in the wake of two shootings last weekend that killed a total of 31 people in El Paso, Texas, and in Dayton, Ohio, momentum is building in Congress for legislation that would offer federal grants to states to help them pass and enforce red flag laws.

Research is still scant on how many shootings these laws may have averted, something that is essentially unknowable. But law enforcement officials in states with red flag laws say they have had a vital effect, including taking guns away from people who have posed a threat to schools. There is also strong evidence that the laws have averted some suicides.

“I’m confident we have saved lives,” said Geraldine Valentino-Smith, a Democratic state legislator in Maryland and lead sponsor of the state’s red flag law, which went into effect in October. Hundreds of firearms have been taken away under the law.

In Florida, where a red flag law was passed after the Parkland massacre, there are 1,707 active temporary or permanent protection orders in effect, according to the Florida Department of Law Enforcement.

In San Diego alone, the city attorney, Mara Elliott, has obtained about 300 orders in the past two years that have allowed the police to confiscate 400 firearms, including 40 military-style rifles. The city has been the most aggressive in California at exploiting the state’s three-year-old red flag law.

Of the first 100 restraining orders she obtained, 1 in 7 involved people who had threatened violence at a workplace or a school, and about 10% involved people who made threats on social media.

“Every time we hear about a mass shooting, the first thing that comes to mind is, had someone had the ability to obtain a gun violence restraining order, could that mass shooting have been prevented?” Elliott said. “Often the answer is yes.”

Of course, mass shootings still occur in places that have red flag laws, including California.

The laws also have one big limitation: They depend on people to call the authorities about someone before they act. Many mass shooters are never reported.

The gunman in Dayton had composed lists of people he wanted to kill or rape, according to the FBI. Ohio does not have a red flag law, but since the shooting, Gov. Mike DeWine, a Republican, has renewed his efforts to get one passed.

Even if Ohio had passed such a law, though, it might not have thwarted the rampage. Red flag restraining orders typically last no more than a year, unless they are renewed; an order issued when the 24-year-old shooter made threats in high school several years ago could well have expired by now.

Federal law has long prohibited the mentally ill from owning firearms. But that restriction does not come into play unless a person had been committed to a psychiatric facility, or a judge has ruled that the person is mentally ill. The state red flag laws have a lower threshold, generally requiring only that a judge find that a person presents a significant threat to himself or others.

Proposals to ban or curb ownership of assault weapons face steep opposition from Republicans in Congress, even though those are the weapons used in almost all of the deadliest mass shootings.

But many lawmakers in both parties have voiced support for red flag legislation, which is seen as having a better chance of passing than a weapons ban.

New York’s new law goes into effect this month. An earlier law, passed in 2013 as part of a sweeping set of gun regulations after 26 people, most of them children, were killed in the Sandy Hook massacre, created a database of people reported by mental health professionals to be unstable. That list is cross-checked with records of those who have applied for pistol permits. If there is any overlap, the state police ask local law enforcement officials to investigate and potentially revoke the permits.

Gun safety advocates praised that legislation, but critics, including mental health professionals, worried that the state’s database was overly broad and could compromise privacy. Since the law was enacted, 97,549 names have been listed in the database. (A name is dropped from the database after five years unless a new report has come in on that person.)

Roughly 800 people in the database were found to have gun permits. But in a possible blind spot, state officials could not say how many guns had been seized as a result of the law, since it is up to local police to collect the weapons, and the police are not required to tell the state whether they followed through.

In the past 10 months in Maryland, there have been 788 applications under the red flag law; almost half were denied or dismissed.

That so many applications were not upheld shows that considerable proof of someone’s danger to themselves or others is required before guns are taken away, said Valentino-Smith, the law’s sponsor. She added that in many of the denied or dismissed cases, the application alone had served the law’s purpose, by allowing for a cooling-off period, or for the subject to voluntarily transfer their guns to someone else.