Every country is different.
Check Noonsight https://www.noonsite.com/
for the information on each port.
But as good as that is you can still make mistakes.
In *Most* Ports of Entry:
Anchor with your Yellow Flag up
Jump in your dinghy and head to shore (see Google Earth to see where all the dinghies are.)
Find and clear in at:
But not necessarily in that order. They may be a bus ride away and a bus ride away from each other!
Take ALL your paperwork
Take NONE of your crew (But some places want all your crew)
At a port where theres a marina (not so often!) the marina will know where all the offices are to clear in or may arrange it themselves (be careful they can charge you hundreds of dollars for something you can do for free - Turkey)
In some places they will want you to stay on your boat and they will come and find you, This can take hours (or maybe even days, Ive heard)
In Galapagos I went to shore and was yelled at "Get back on your boat, we come to you!"
Indonesia took 4 DAYS to clear In and 2 DAYS to clear out and a hefty bribe.
Some countries you just ring them (UK)
Some countries its almost impossible to find the offices (USA New York they used to come visit now you need to go to 2 offices in New Jersey neither accessible by public transport, neither building marked etc etc etc just a frickin pain)
But you get used to ti and after a while it becomes one of the joys of cruising.
Always wear neat clean clothes and footwear LONG trousers and LONG sleeved shirts unless you know the place. Yes, even in the tropics, or more likeley, often in the tropics.
Always be ultra polite as theres some well known jerks - The BVIs are a classic for rudeness (in fake US accents - go figure)... and Jolly Harbour, Antigua has the "Three Doors of Hell"... you have to visit them all and behind one door, it changes each time you visit, is the utter jerk.
Finally, as for guns.. I really dont know but you MUST research it before if you are carrying weapons... some countries you must go ashore with them to the police... but other countries you leave them on the boat - one friend thinking he was doing the right thing jumped on a bus with a war full of guns and was arrested. Mexico hates shotguns and that gets you arrested... yada, yada.
Finally (maybe this should be up the top) Visas! Some countries you can not just swan into but you need a proper visa BEFORE you arrive (USA, Brazil, many asian countries) depending on your nationality.
Finally, some countries charge you extra to clear in on weekends - And weekends are Friday, Saturday and Sunday, and this can be very expensive (Thailand and Malaysia)
So theres lots of stuff you need to know