- 7
- Posts
- 2
- Years
- Seen Mar 27, 2025
Hey there!
This Code changes the Weather randomly after the player accumulates a specific number of steps (5 Steps in this example).
I added the script in src/overworld.c.
In include/overworld.h, fefore #endif // GUARD_OVERWORLD_H add:
In src/main.c, in the function "VBlankIntr" i added one line:
And as the last step in src/field_weather_effect.c i changed the following:
Thanks to Lunos for the help!
This Code changes the Weather randomly after the player accumulates a specific number of steps (5 Steps in this example).
I added the script in src/overworld.c.
Code:
void RandomWeather(void)
{
if (GetGameStat(GAME_STAT_STEPS) % 5 == 0 && IsMapTypeOutdoors(gMapHeader.mapType)) // Change the "5" to whatever amount you want the player to take
{
switch (Random() % 3) // 25% that the Weather changes
{
case 0:
{
switch (Random() % 3)
{
case 0:
if (GetCurrentWeather() != WEATHER_NONE)
SetWeather(WEATHER_NONE);
break;
case 1:
if (GetCurrentWeather() != WEATHER_RAIN)
SetWeather(WEATHER_RAIN);
break;
case 2:
if (GetCurrentWeather() != WEATHER_SHADE)
SetWeather(WEATHER_SHADE);
break;
case 3:
if (GetCurrentWeather() != WEATHER_RAIN_THUNDERSTORM)
SetWeather(WEATHER_RAIN_THUNDERSTORM);
break;
}
}
case 1:
break;
case 2:
break;
case 3:
break;
}
}
}
In include/overworld.h, fefore #endif // GUARD_OVERWORLD_H add:
Code:
void RandomWeather(void);
In src/main.c, in the function "VBlankIntr" i added one line:
Code:
static void VBlankIntr(void)
{
if (gWirelessCommType != 0)
RfuVSync();
else if (gLinkVSyncDisabled == FALSE)
LinkVSync();
gMain.vblankCounter1++;
if (gTrainerHillVBlankCounter && *gTrainerHillVBlankCounter < 0xFFFFFFFF)
(*gTrainerHillVBlankCounter)++;
if (gMain.vblankCallback)
gMain.vblankCallback();
gMain.vblankCounter2++;
CopyBufferedValuesToGpuRegs();
ProcessDma3Requests();
gPcmDmaCounter = gSoundInfo.pcmDmaCounter;
m4aSoundMain();
[B] [COLOR="Lime"]RandomWeather();[/COLOR][/B]
TryReceiveLinkBattleData();
if (!gMain.inBattle || !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_FRONTIER | BATTLE_TYPE_RECORDED)))
Random();
UpdateWirelessStatusIndicatorSprite();
INTR_CHECK |= INTR_FLAG_VBLANK;
gMain.intrCheck |= INTR_FLAG_VBLANK;
}
And as the last step in src/field_weather_effect.c i changed the following:
Code:
[COLOR="Lime"]#include "overworld.h"[/COLOR]
void SetSavedWeather(u32 weather)
{
[COLOR="Lime"]if(IsMapTypeOutdoors(gMapHeader.mapType)){[/COLOR]
u8 oldWeather = gSaveBlock1Ptr->weather;
gSaveBlock1Ptr->weather = TranslateWeatherNum(weather);
UpdateRainCounter(gSaveBlock1Ptr->weather, oldWeather);
[COLOR="Lime"]}[/COLOR]
}
u8 GetSavedWeather(void)
{
[COLOR="Lime"] if(IsMapTypeOutdoors(gMapHeader.mapType)){[/COLOR]
return gSaveBlock1Ptr->weather;
[COLOR="Lime"] }[/COLOR]
}
void SetSavedWeatherFromCurrMapHeader(void)
{
[COLOR="Lime"]if(IsMapTypeOutdoors(gMapHeader.mapType)){[/COLOR]
u8 oldWeather = gSaveBlock1Ptr->weather;
gSaveBlock1Ptr->weather = TranslateWeatherNum(gMapHeader.weather);
UpdateRainCounter(gSaveBlock1Ptr->weather, oldWeather);
[COLOR="Lime"] }[/COLOR]
}
void SetWeather(u32 weather)
{
[COLOR="Lime"]if(IsMapTypeOutdoors(gMapHeader.mapType)){[/COLOR]
SetSavedWeather(weather);
SetNextWeather(GetSavedWeather());
[COLOR="Lime"]}[/COLOR]
}
Thanks to Lunos for the help!
Last edited: