Cellarius wrote a really good article for help on preregistering the variables -
[vB4] Rendering templates and registering variables - a short guide
As for writing a plugin, there are articles in the articles forums for that or the manual shows the basics -
http://www.vbulletin.com/docs/html/add_plugin
I've always found the best way to start is to download a simple product and read their code to see how they did things.