When it comes to mass killings, the effort involved in one person killing 20 people with a cricket bat is significantly less than one person killing 20 people with an automatic weapon.
Let's not quibble over the purpose of the gun; let's restrict ourselves to guns that fire lots of bullets in a short space of time, as they're the real problem with these mass shootings. They were certainly invented to kill people in warfare. From Wikipedia:
--------------------------------------------------
https://en.wikipedia.org/wiki/Gun
The first successful rapid-fire firearm is the Gatling Gun, invented by Richard Gatling and fielded by the Union forces during the American Civil War in the 1860s.
The world's first sub-machine gun (a fully automatic firearm which fires pistol cartridges) able to be maneuvered by a single soldier is the MP18.1, invented by Theodor Bergmann. It was introduced into service in 1918 by the German Army during World War I as the primary weapon of the Stosstruppen (assault groups specialized in trench combat).
The first assault rifle was introduced during World War II by the Germans, known as the StG44. It was the first firearm which bridges the gap between long range rifles, machine guns, and short range sub-machine guns.