I had to make a couple changes to get these working for me. I don't know if it's a FireRed thing or not.
For the trainer parties, I had to define the variables for max, min, range, and rand. I defined them all as u8, and that's been working. Also, the section that's labelled "right before those...