Jump to content

Photo

SCRIPT: Day/Night Transitions

day night cset dmap

  • Please log in to reply
26 replies to this topic

#16 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 26 August 2014 - 10:40 AM

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.



#17 Shosci

Shosci

    Gaming Topics and Live Streams

  • Members
  • Real Name:Eshaan

Posted 26 August 2014 - 07:13 PM

Not too bad, but the enemy respawning in different areas because I killed one enemy before the Dmap changed gets in the way sometimes, Like you said, this might be worked around. 

 

One question: does the 4 Dmaps have to be listed consecutively? Ex: Does Dmap 5 have to be above Dmap 6, 7, and 8 or can the script also decide which Dmap I enter? I am only asking because I have a lot of Dmaps listed after the Overworld...



#18 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 26 August 2014 - 11:50 PM

You can fix the issue with the enemies by checking the screen flag Sprites Carry Over In Warps, but as I said before, that comes with its own share of problems.

 

The DMaps do need to be arranged consecutively. It might be a good idea to just make new overworld DMaps at the end of your current list instead of shifting your DMaps down and having to reassign every warp in the quest.



#19 Shosci

Shosci

    Gaming Topics and Live Streams

  • Members
  • Real Name:Eshaan

Posted 27 August 2014 - 09:05 AM

Okay, so I made new Dmaps so they can consecutive, and the script compiled successfully since it's running from the same .z file. However, beyond there, I don't know what else to do to get the script working. 

 

I changed int DayNightDMaps to [4] = {14, 17}, assuming that's where I enter how much Dmaps is being used and in the curly brace is what Dmaps I am using, unless it's supposed to be entered as {14, 15, 16, 17}

 

What else did I need to do or change?



#20 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 27 August 2014 - 09:26 AM

You actually only need to enter the first of the four. So the line should read:

int DayNightDMaps[1] = {14};

After that you'll want to make a new save file because you changed the value of a global variable. Other than that, you shouldn't need to do anything for now. You'll eventually want to change DAYNIGHT_CYCLE_LENGTH to something like 43200 so your days last 12 minutes instead of 12 seconds. For the purpose of testing, I find 12 seconds much easier. Fortunately DAYNIGHT_CYCLE_LENGTH is a constant so you don't have to make a new save file when editing it.



#21 Shosci

Shosci

    Gaming Topics and Live Streams

  • Members
  • Real Name:Eshaan

Posted 27 August 2014 - 05:18 PM

Darn I should have mentioned before, but the Active Compiled Script window, what needs to be done there? I am not familiar with Globals so I only transferred the script to active.



#22 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 27 August 2014 - 05:28 PM

If you have only one global script you can just use the IWarnedYouMan script as it is and it should work. If you have more, you'll need to combine them. To combine my script with an existing global is actually pretty simple. Just add an extra line before the waitframe in your existing global and add:

DayNight(DayNightDMaps);

(I realize now that this function still has an argument left over from when DayNightDMaps wasn't a global variable, but it shouldn't cause any problems)



#23 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 27 August 2014 - 08:56 PM

What about using DrawScreen/DrawLayer, to copy the visual datum from another map, to the current screen? That may work better, in a limited manner; or would that default to the current CSet?

#24 Shosci

Shosci

    Gaming Topics and Live Streams

  • Members
  • Real Name:Eshaan

Posted 27 August 2014 - 09:30 PM

Don't worry ZoriaRPG, Moosh and I got it to work. Four consecutive Dmaps all looping between each other in a 2 minute interval. It works great, all I need to do is check Sprites Carry Over for the screens.



#25 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 27 August 2014 - 10:03 PM

Aye, however I was mainly directing that at Moosh, as if DrawScreen (or DrawLayer, based on application) copies a screen, without consideration to CSet, it could indeed be a powerful tool for this sort of thing.

My own methods aren't ideal, as they're designed to tint the screen, however they don't require additional tiles, or DMAPs. Assuming that other draw commands would work in this area, I may work towards that sort of thing in the future.

I'd frankly prefer running draw commands, over warping, in some circumstances; however, I don't utilise CSets in my present projects--all of my tiles will eventually be fully-8-bit, on one master CSet, so my position is a bit different.

I would say though, that you may want to give the interval a longer delay, as a two-minute period is rather fast, in contrast to other games that have this sort of thing, so it may be a tad disorientating. The full circuit happens every eight minutes, and I'd normally expect it to take about ten to fifteen minutes for a single transition, at the least. (I'd need to see it in action, to judge that.)

Edited by ZoriaRPG, 27 August 2014 - 10:04 PM.


#26 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 28 August 2014 - 08:58 AM

Aye, however I was mainly directing that at Moosh, as if DrawScreen (or DrawLayer, based on application) copies a screen, without consideration to CSet, it could indeed be a powerful tool for this sort of thing.

My own methods aren't ideal, as they're designed to tint the screen, however they don't require additional tiles, or DMAPs. Assuming that other draw commands would work in this area, I may work towards that sort of thing in the future.

I'd frankly prefer running draw commands, over warping, in some circumstances; however, I don't utilise CSets in my present projects--all of my tiles will eventually be fully-8-bit, on one master CSet, so my position is a bit different.

Unfortunately, DrawScreen and DrawLayer don't work quite like you think they do. They draw the specified screen in the current DMap's palette, meaning they can't be used to get around the palette restrictions. This method could possibly work with 8-bit color, but that would require four times the maps, four times the tiles, four times the everything.



#27 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 29 August 2014 - 04:15 AM

Moosh, on 28 Aug 2014 - 06:58 AM, said:
Unfortunately, DrawScreen and DrawLayer don't work quite like you think they do. They draw the specified screen in the current DMap's palette, meaning they can't be used to get around the palette restrictions. This method could possibly work with 8-bit color, but that would require four times the maps, four times the tiles, four times the everything.

That essentially sums up my planned tileset. It's not at all user-friendly, but it allows me to do some things that normally would be difficult with ZC. The main reason that I didn't know if DrawScreen uses the source, or destination CSet, is because I avoid any CSet changing, and thus, all the screens that would replace other screens, all use CSet/LSet 0.



Also tagged with one or more of these keywords: day, night, cset, dmap

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users