int DayNightCounter = 0; //This is the counter used for the int DayNightDMaps[2] = {0, 0}; //This array tells the script which DMaps to check for. Put the first DMap of every set of states separated by a comma inside the {}. Put the number of things inside the {} inside the []. You'll want to make a new save file every time you change this. const int DAYNIGHT_NUM_STATES = 4; //Set this to the number of states you want to use. By default uses 4: Sunrise, Daytime, Sunset, Nighttime. All states last an equal length of time. const int DAYNIGHT_CYCLE_LENGTH = 720; //Set this to the number of frames (60ths of a second) a full cycle should last. Typically this would be the number of frames per state times the number of states. 12 seconds by default for testing purposes. //This is the function that handles the Day/Night script. Put it before the Waitframe() in your global script. void DayNight(int DayNightDMaps){ DayNightCounter++; if(DayNightCounter>=DAYNIGHT_CYCLE_LENGTH) DayNightCounter = 0; int DayNightDMap = -1; for(int i=0; i<SizeOfArray(DayNightDMaps); i++){ if(Game->GetCurDMap()>=DayNightDMaps[i]&&Game->GetCurDMap()<DayNightDMaps[i]+DAYNIGHT_NUM_STATES) DayNightDMap = DayNightDMaps[i]; } if(DayNightDMap==-1) return; if(Game->GetCurDMap()!=DayNightDMap+Floor(DayNightCounter/(DAYNIGHT_CYCLE_LENGTH/DAYNIGHT_NUM_STATES))) Link->PitWarp(DayNightDMap+Floor(DayNightCounter/(DAYNIGHT_CYCLE_LENGTH/DAYNIGHT_NUM_STATES)), Game->GetCurDMapScreen()); } //Here's a very simple global script with just the Day/Night script global script IWarnedYouMan{ void run(){ while(true){ DayNight(DayNightDMaps); Waitframe(); } } }
Here's a very simple Day/Night script. In order for it to work, you need to arrange your DMaps into sets of four, like: 13-Overworld (Day), 14-Overworld (Sunset), 15-Overworld (Night), 16-Overworld (Sunrise). Then you put the first of each set of four into the DayNightDMaps array so the script knows to treat those four DMaps as a set. You can change DAYNIGHT_NUM_STATES to something other than 4 if you want to have more or less states. DAYNIGHT_CYCLE_LENGTH should be set to the time it takes for a full day to pass in frames (60ths of a second).
Here is the example quest I tested the script in. You can see the enemies constantly respawn as the time of day changes. This is less noticeable when each state lasts longer than three seconds, but still will be a problem we'll want to work around.