As I mentioned above guns just don't make sense in fantasy worlds, but that doesn't have to mean that people can't play cool ass gunslinger characters!
Below you will find rules how to do guns and gun like weapons using nothing but fantasy elements! How frickin cool is that?
Casters, or Spells in Shells
Casters are "guns" that fire pre prepared spells, which are stored in special shells. In game terms, this seems to be a version of the Ring of Spell Storing, except it is cool as heck.
Casters can be gnome crafted curiosities, carefully rune-carved, exceptional works of art, the love child of Magic and innovation. Casters are powerful and versatile, so be careful when handing them out to your players.
Wondrous (gun), Rare (requires attunement)
A gnome crafted Caster with dragon motives
These weapons come with a set of magical cartridges, usually 6 of them. Each cartridge can store 1 spell up to level 3. Only spells that require a ranged attack roll can be stored in the cartridges. Any creature can touch a cartridge and cast a spell of 1st through 3rd level into the gun. The spell has no effect other than to be stored in a cartridge.
While attuned to the Caster, you can pull the trigger to cast any spell stored in any of the cartridges of the gun. The spell uses the slot level, spell save DC, spell attack bonus and spellcasting ability of the original magic user.
Once the stored spell is cast, the cartrdige becomes void of magical energy, and can be refilled.
Cartridge for Caster
Wondrous Item (ammunition), Uncommon
As detailed above, empty cartridges, (or in some cases, filled cartridges) can be found as loot. Unlike the Caster, these do not require attunement, therefore a single person can store up many different spells, becoming a much more versatile than most magic users.
The Casters are cool, but they don't fill any special role in, they are not doing anything new. They don't break conventions, they don't do anything brave. These weapons on the other hand, are something different. Arcane guns are weapons that use magical energy to wreak havoc upon foes!
Arcane guns can be crafted from a single piece of magical material, or utilize magical gems as their powersource. They are highly powerful arcane instruments deadly in the right hands.
Weapon (gun), uncommon (requires attunement)
A Holy Arcane Gun, blessed by a deity. It shoots radiant energy.
Arcane guns are strange magical items, closely resembling wands in their usage. An arcane gun has 12 charges, regaining 2d6-1 charge at each dawn. An arcane gun can be used to fire bolts of energy until it runs out of its charges. There are many different type of arcane guns, each fires a different type of energy bolt of 2d6 damage (Fire, Cold, Acid, Lightning, Radiant, Necrotic).
The user doesn't have to be a magic user, or know anything of magic, and it is treated as a normal ranged weapon that doesn't require reloading. (range 30/90)
However, if the user is a caster, they can spend a short rest concentrating their magical energies on the gun. Doing so will restore 1d6 charge to the Arcane Gun.