When rock-climbing, I need to set up a top-rope anchor so if I fall, it will minimize chance of injury.
So, how would I safely set one up?
First - Please do not only rely on answers in this site for creating top rope anchors. This is something that your life depends on, or the life of someone you care about, take it seriously.
Now with that our of the way...
Use the following acronym as a guide to anchor creation.
Equal tension - Multipoint anchors must have equal tension on all anchor points.
Angles appropriate - No angle of tension shall exceed 60 degrees
Redundant - No single anchor point failure shall cause the entire anchor to fail. Also no anchor point should share a primary connection to any other anchor point.
Non-Extending - No anchor point failure will cause other load points to be shock loaded.
Strong - Each individual anchor point could hold all climbers in the case of the worst possible fall
Timely - The anchor can be constructed and decontructed in a matter of time which does not cause a safety risk in itself.
Also John Long, the grandaddy or modern rock climbing has suggested the alternate acronym to use for mnemonics.
Please see this excellent article abour anchor building available at the link below.
More information from the master himself. A must read for a serious climber.
Rule number one: Assume that one piece of your equipment will break, there must be redundancy right up to the rope. At least two, preferably three, independent anchors should go to two opposing locked carabiners.
As for what to anchor to, if there's a bolted anchor that looks good, use it (but even then, not as the only anchor). If not, I've always found trees the easiest, and as long as they're not right on the edge, a healthy live tree should be the most stable. Rocks are generally not as good, because it's hard to guarantee that whatever you use to anchor won't slip off the top. If you have good cams and a good spot to put them, that would also be good, but if you can get a bolt or a tree, use that too.
Consider this general suggestions from a somewhat experienced but far from expert fellow climber. You should go with an expert, watch how they set it up once or twice, and then set one yourself and have them check it and give you feedback. It would also be good to read a book about it before you go, so you can apply what you read under supervision so you know you're doing it properly.