I suggest do some shorter events first - sounds like you are looking at a 6 hr enduro (ie everyone is out for as many laps as they can do in 6 hours), so do a few events when you are out for 3 or 4 hours first , riding in crap weather as well as fine. Riding an event is different to being out with friends because you dont stop .. so working out drinking and eating is important , as is finding out whether eg your back can stand 6 hrs continuous in the saddle without having to get off for 5 mins or so every hour . I find avoiding cramp is tricky , which probably just means I dont do long enough training stints!
and.. unless you are used to them suggest dont have too many gels - they can do horrible things to your guts!
Take a look at Joe Friel's Mountain Biker's Training Bible, it's full of great advice, then look at Training Peaks as that offers training plans that tie in with Joe's methods. Then commit to getting out on your bike every day (with the odd rest day) and make it happen. Endurance racing is not easy but it's very rewarding.
My first 6hr was and still is one of my favourite races that I've done, even without much training at the time I still loved it, although I wasn't really competitive then! Email me if you want some specific advice.