Code:
function shoot_with_mouse() 
{  
  VECTOR to;
  vec_set(to,mouse_dir3d);
  vec_scale(to,1000); // set a range
  vec_add(to,mouse_pos3d);
  c_trace(mouse_pos3d,to,ACTIVATE_SHOOT);
  vec_set(to,mouse_dir3d);
  vec_scale(to,result); // set the range to the result of the trace
  vec_add(to,mouse_pos3d);//'to' contains now the position on the grid
}