In src/battle_util.c
here (at line 2473) add the following right before the if statement:
C:
if (!FlagGet(FLAG_DO_NORMAL_WEATHER))
{
u16 random = Random();
int randweather = (random % 199); //sets a random number between 0 and 199
if(randweather < 50)
{
gWeatherPtr->currWeather = WEATHER_DOWNPOUR;
}
else if(randweather < 100)
{
gWeatherPtr->currWeather = WEATHER_DROUGHT;
}
else if(randweather < 150)
{
gWeatherPtr->currWeather = WEATHER_SANDSTORM;
}
else
{
gWeatherPtr->currWeather = WEATHER_SNOW;
}
}
Then, still in battle_util.c, add the following code
here (the new line will be 2529) immediately after the break:
C:
case WEATHER_SNOW: //adds the ability for battles to start with hail active
gBattleWeather = B_WEATHER_HAIL;
gBattleScripting.animArg1 = B_ANIM_HAIL_CONTINUES;
gBattleScripting.battler = battler;
effect++;
break;
In src/battle_message.c, add the following code
here (at line 481) right after the sandstorm line:
C:
static const u8 sText_ItIsHailing[] = _("Hail is falling down.");
You can change what is inside the quotes to whatever you want it to say when a battle starts with hail. You don't have to keep the wording I used. Up to you.
In that same file, add the following code
here (the new line will be 782) after the line for sandstorm:
C:
[STRINGID_ITISHAILING - BATTLESTRINGS_TABLE_START] = sText_ItIsHailing,
Still in battle_message.c,
REPLACE the line
here (the new line will be 1164) with this:
C:
[WEATHER_SNOW] = STRINGID_ITISHAILING,
In include/constants/battle_string_ids.h, add the following
here (at line 381) after STRINGID_TRAINER2WINTEXT:
C:
#define STRINGID_ITISHAILING 381
Make sure to change the value of BATTLESTRINGS_COUNT (right after the line you just added) to 382.
Lastly, in include/constants/flags.h,
REPLACE the line
here (line 1220) with the following (this can replace one of the other unused flags instead, if you prefer):
C:
#define FLAG_DO_NORMAL_WEATHER 0x493 // Disables random weather in battle
Save all of the files and run a make command. You now have a ROM of Pokemon Emerald that has a random weather effect in every battle!
I tied this mechanic to the flag FLAG_DO_NORMAL_WEATHER. Therefore, if you wanted to turn it off and back on again with scripts, it is as easy as using setflag or clearflag as needed. But I set it up so the random weather happens by default, in case you don't want to do anything with scripting.