You can try the coding that I have included. This seems to work quite well, but is also quite basic, so I'm sure you could improve on it.
You need to attach a "muzzle" to the end of the cannon and reduce its opacity to zero, this basically works as a loading area. Then group a "target" to the pirate ship and place it in the position that you would like the cannon ball to shoot.
This is the space I quickly built so you can see how it works.
https://cospac.es/ZG1iThanks