As mentioned above, see:
c_scan
c_trace

And also maybe:
vec_dist

Another possibility is to randomly spawn the pistol at the same time one of trees is spawned at a position beside the tree. Use a global variable to store whether or not the pistol has been spawned yet or not so that you do not spawn more pistols.