Jump to content

Photo

how to use setsidewarp


  • Please log in to reply
15 replies to this topic

#16 justin

justin

    Adept

  • Members

Posted 13 November 2014 - 09:23 PM

cool.  works like a charm!

 

here's the code if anyone cares...  (I'll also accept ways of improving it since I suck at scripting.)

// Script initially written by Moosh.  Heavily modified with help from MoscowModder and Jamian.

const int DAYNIGHT_NUM_STATES = 3; // Set this to the number of states in each full cycle. i.e. Morning, Daytime, Night.

const int DAYNIGHT_STATE_LENGTH = 180; //Set this to the number of frames (60ths of a second) each state will last.


int DayNightCounter = 0; // A counter used to keep track of the "time" in each state.

int DayNightCurrentState = 0; // A counter keeping track of which state you are currently on in the cycle.

bool DayNightNewState = false; // Whether the state has been changed, it'll change on next screen change.

// This array tells the script which DMaps are involved in the DayNight system.
// Inside the [] brackets is how many sets of DMaps are involved.
// Inside the {} brackets is the first DMap in each set.
int DayNightDMaps[2] = {0, 3}; 


// This function is a check that you're still on the correct DayNight DMap in case your DMap was changed by another warp.
// Run it at the top of your Global script or else the DMap switch will be more noticeable.
void CheckCorrectDayNight(){
	if(DayNightNewState == false && getDayNightDMap() != Game->GetCurDMap())
		Link->PitWarp(getDayNightDMap(), Game->GetCurDMapScreen());
}


// This is the function that handles the Day/Night script. Put it before the Waitframe() in your global script.
void DayNight(){
 	DayNightCounter++;
	if(DayNightCounter>=DAYNIGHT_STATE_LENGTH){
		DayNightCounter = 0;

		DayNightCurrentState++;
		if(DayNightCurrentState>=DAYNIGHT_NUM_STATES)
			DayNightCurrentState = 0;
		DayNightNewState = true;

	}


	// Checks to see if the State has changed, and if Link is scrolling to a new screen.  
	// If both are true it'll warp Link instantly after scrolling to new DMap.
	if(DayNightNewState == true && Link->Action == LA_SCROLLING){
		while(Link->Action == LA_SCROLLING)
	        	Waitframe();
   
		Link->PitWarp(getDayNightDMap(), Game->GetCurDMapScreen());
		DayNightNewState = false;
	}
}

// Returns the DMap that you are currently on in the DayNight cycle.
int getDayNightDMap(){
	for(int i=0; i<SizeOfArray(DayNightDMaps); i++){
		if(Game->GetCurDMap()>=DayNightDMaps[i]&&Game->GetCurDMap()<DayNightDMaps[i]+DAYNIGHT_NUM_STATES)
			return (DayNightDMaps[i] + DayNightCurrentState);
	}
}


global script active{
   void run(){
	while(true){
		CheckCorrectDayNight();
		DayNight();

	        Waitframe();
	}
    }
}



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users