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:
local bx, by, bz = pxp + xo, pyp + yo, pzp + zo
ParticlesSpawnParticle( pe, bx, by, bz )
xo, yo, zo = U.Rotate3D( 0, 0, 10000, pax, pay, paz )
local ex, ey, ez = pxp + xo, pyp + yo, pzp + zo
local hitObj = IntersectAll( bx, by, bz, ex, ey, ez, 0 )
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!