//Created by ZoriaRPG for NJF, Final Version 1.0 - 10th December, 2016
//D0: The combo ID of the combo that you want to use for this.
//D1: A timer, to ensure that messages don't repeat too quickly. I'd advice 60 or 80 for this.
//D2: The layer that you placed the combo onto.
//D3: The ZString that you want to display.
//D4: A sound effect ID that you wish to play, if any.
//D5: The direction to move Link: 0 = Up, 1 = Down, 2 = Left, 3 = Right
ffc script NotThisWayCombo{
void run(int comboID , int delay, int layer, int msg, int sfx, int dir){
ClearTrace();
int adj[10]; //x = 0, y = 1; dir = 2, timer = 3, 5 = q loop
//6 = adjacent combo, 7 = dest combo X, 8 = dest combo Y, 9 = move timer
while(true){
//! this could be good for solid damage combos
if ( adj[3] ) adj[3]--;
if ( adj[3] <= 0 ) adj[3] = 0;
if ( Link->Dir == DIR_LEFT ) { adj[0] = 2; adj[1] = 8;}
if ( Link->Dir == DIR_RIGHT ) { adj[0] = 7; adj[1] = 8;}
if ( Link->Dir == DIR_DOWN ) { adj[1] = 11; adj[0] = 8; }
if ( Link->Dir == DIR_UP ) { adj[1] = 6; adj[0] = 8; }
adj[2] = Link->Dir;
if ( ( ( GetLayerComboD(layer, ComboAt(Link->X+8, Link->Y+8)) == comboID ) || ( GetLayerComboD(layer, ComboAt(Link->X+adj[0], Link->Y+adj[1]) ) == comboID ) ) && adj[3] == 0 ) { //&& ComboAt(Link->X+8, Link->Y+8) != lastcombo ){
adj[3] = delay; //Set the initial delay/
adj[4] = ComboAt(Link->X+8, Link->Y+8); //Store the combo at Link's position to reuse.
//lastcombo = ComboAt(Link->X+8, Link->Y+8);
//Find the nearest combo in the direction specified.
for ( adj[5] = 1; adj[5] < 8; adj[5]++ ) {
adj[6] = ____AdjacentCombo(adj[4], dir, adj[5]);
if ( GetLayerComboD(layer, adj[6] ) != comboID ) break;
}
//Play the sound set, if any.
if ( sfx ) Game->PlaySound(sfx);
Screen->Message(msg); //Display the message.
adj[9] = 32*adj[5]; //Maths for the timer.
adj[7] = ComboX(adj[6]); adj[8] = ComboY(adj[6]); //Store the X and Y positions of the dest combos.
//...so that we know where to snap when we stop.
//Move Link based on the direction set in D5.
if ( dir == DIR_UP ) {
//Snap him to the grid, or to the nearest non-solid pixel.
while( Link->Y != adj[8] && CanWalk(Link->X, Link->Y, DIR_UP, 1, false) ) {
adj[9]--;
if ( adj[9]%4 == 0 ) Link->Y--; //Move him one pixel every four frames.
WaitNoAction();
}
adj[9] = 0; //Clear
}
//Repeat for other directions.
if ( dir == DIR_DOWN ) {
while( Link->Y != adj[8] && CanWalk(Link->X, Link->Y, DIR_DOWN, 1, false) ) {
adj[9]--;
if ( adj[9]%4 == 0 ) Link->Y++;
WaitNoAction();
}
adj[9] = 0;
}
if ( dir == DIR_LEFT ) {
while( Link->X != adj[7] ) {
Trace(Link->X); Trace(adj[7]);
adj[9]--;
if ( adj[9]%4 == 0 ) Link->X--;
WaitNoAction();
}
adj[9] = 0;
}
if ( dir == DIR_RIGHT ) {
while( Link->X != adj[7] && CanWalk(Link->X, Link->Y, DIR_RIGHT, 1, false) ) {
adj[9]--;
if ( adj[9]%4 == 0 ) Link->X++;
WaitNoAction();
}
adj[9] = 0;
}
}
Waitframe();
}
}
//! rETURNS THE COMBO id OF A COMBO BASED ON A LOCATION, IN A GIVEM DIRECTION, n COMBOS AWAY.
int ____AdjacentCombo(int cmb, int dir, int dist){
int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
if ( cmb % 16 == 0 ) combooffsets[9] = 1;
if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) {
return 0; //if the left columb
}
if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) {
return 0; //if the left columb
}
if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) {
return 0; //if the left columb
}
if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) {
return 0; //if the left columb
}
int cmbs[2];//needs a for loop to ensure that t returns the most valid combo
if ( cmb >= 0 && cmb < 176 ) {
cmbs[0] = cmb;
for ( cmbs[1] = 0; cmbs[1] < dist; cmbs[1]++ ) {
if ( dir == DIR_LEFT && ComboX(cmbs[0]) == 0 ) return cmbs[0];
if ( dir == DIR_RIGHT && ComboX(cmbs[0]) == 240 ) return cmbs[0];
if ( dir == DIR_UP && ComboY(cmbs[0]) == 0 ) return cmbs[0];
if ( dir == DIR_DOWN && ComboY(cmbs[0]) == 160 ) return cmbs[0];
cmbs[0] += (combooffsets[dir]);
if ( cmbs[0] < 0 || cmbs[0] > 175 ) return cmbs[0];
if ( cmb % 16 == 0 ) combooffsets[9] = 1;
if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) return cmbs[0]; //if the left columb
if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return cmbs[0]; //if the right column
if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) return cmbs[0]; //if the top row
if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return cmbs[0]; //if the bottom row
}
return cmbs[0];
}
else return -1;
}
}