//////////////////////// /// ScreenChanged.zh /// /// By: ZoriaRPG /// /// v0.4 /// /// 18th Sept, 2016 /// //////////////////////// const int LINK_MISC_SCREENCHANGES = 10; //Link->Misc[index] that we're using to track screen changes. ////////////////////// /// CORE FUNCTIONS /// ////////////////////// //Returns if the screen has changed, and we use that in the global active while loop, //before Waitdraw() to automate the process. bool ScreenChanged(){ int a[3]; a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] ) return true; return false; } //Call before the while loop in the global active script. //This is also called with ScreenChanged() to update the screen information. void UpdateScreenChanges(){ a[0] = Game->GetCurScreen(); a[1] = Game->GetCurDMap(); a[2] = a[0] + ( a[1] / 10000 ); Link->Misc[LINK_MISC_SCREENCHANGES] = a[2]; } ///////////////////////// /// UTILITY FUNCTIONS /// ///////////////////////// //! Functions to call in scripts, to perform actions based on if the screen has changed. //! You may optionally check how it changed (scrolling, or warp), and you may optionally force an update. //Returns if the screen has changed in general, and optionally forces an update. bool ScreenChanged(bool update){ int a[3]; a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] ) { if ( update ) UpdateScreenChanges(LINK_MISC_SCREENCHANGES); return true; } return false; } //Returns if the screen changed by scrolling, and optionally forces an update. bool ScreenScrolled(bool update){ int a[3]; a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action == LA_SCROLLING ) { if ( update ) UpdateScreenChanges(LINK_MISC_SCREENCHANGES); return true; } return false; } //Returns if the screen changed without scrolling, and optionally forces an update. bool ScreenChangedWarp(bool update){ int a[3]; a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action != LA_SCROLLING ) { if ( update ) UpdateScreenChanges(LINK_MISC_SCREENCHANGES); return true; } return false; } //Returns if the screen changed by scrolling. bool ScreenScrolled(bool update){ int a[3]; a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action == LA_SCROLLING ) return true; return false; } //Returns if the screen changed without scrolling. bool ScreenChangedWarp(bool update){ int a[3]; a[0] = Link->Misc[LINK_MISC_SCREENCHANGES] << 0; //CurScreen a[1] = ( Link->Misc[LINK_MISC_SCREENCHANGES] - ( Link->Misc[LINK_MISC_SCREENCHANGES] << 0 ) ) *10000; //CurDMap if ( Game->GetCurScreen() != a[0] && Game->GetCurDMap() != a[1] && Link->Action != LA_SCROLLING ) return true; return false; } //! Example Global Active Script global script ChangedScreen{ void run(){ UpdateScreenChanges(); //Initialise the values at the start of each game. while(true){ if ( ScreenChanged() ) UpdateScreenChanges(); Waitdraw(); Waitframe(); } } }Essentially untested, but barring typos, it should work, and I'll eventually drop it to the database.
Edited by ZoriaRPG, 18 September 2016 - 08:06 AM.