We all want our children to have loyal and good friends, that treat them right and won't hurt them; unfortunately even children have to learn somethings the hard way.
Using stories is a good way of influencing a smaller child. Winnie The Pooh and his friends work for me.
I also think your general approach to life and how you deal with things and the people that are mostly around your child will influence them. The most important thing is that your child feels complete confidence in you and will tell you how things are going. Always ask your child how they are and what things the enjoyed about their day and if there was anything not so good.
And remember: some experiences have to be experienced and you can't change that, but you can be there to wipe away the tears and give them a cuddle. Your love and support is what matters.