It is a relatively simple script.
When mouse pressed calculate a vector in the direction the player is looking, calculate the start position for the particles (i.e. the 'barrel' position) and generate a particle at that point with the vector as the 'speed' parameters.
Ray casting is reasonably easy to understand, the IntersectAll command is used with the start and end of the ray, it returns the object Id of the first object that the ray intersects or 0 if nothing is in the way.
The start position of the ray is the barrel position (i.e. the position we specified for the particle spawn) and to calculate the end position just do:
If hitObj is not 0 (or nil, best to test for nil just in case) then you can call the commands to get the hit location.
Been there, done that, got all the T-Shirts!