// ------------------------------------------
// Adventures of Link style random encounters
// version 1.0
// ------------------------------------------
//
// Script Setup
// ------------
// 1. Set the following constants
// 2. Input the dmaps and screens for the battle screens into the aol_re_screens[] array.
// 3. Compile and import the scripts.
// 4. Assign the Slot2 to your global slot2.
// Or combine it with your existing global script by adding AOL_Random_Encounter(); to somewhere before your Waitdraw();
//
// Battle Screen Setup
// -------------------
// 1. Create your battle screens. I've set it up so they can have individual dmaps for unique palettes, music, etc.
// They don't have to have individual dmaps if you don't want. But each battle screen type does need to be on the same dmap.
// You requested four of each battle screen type, so that's how the script is setup. They are randomly selected.
//
// 2. Make sure you place a warp arrival square on the battle screen.
// 3. Create a blank screen on any dmap, and place the AOL_RE_Return ffc script on that screen.
// 4. Have all your battle screen's sidewarps send you to the same blank screen created above. That screen handles the return.
//
// Enemy Trigger Setup
// -------------------
// 1. Create an enemy (or multiple) to trigger the random encounters
// 2. Make the enemy invinicible with ignore all defenses. And give it no attack or weapon damage.
// 3. Place the enemy on the overworld screens where random encounters can happen.
// 4. Link's step speed is 150 if you want to take that into account with how fast they should move.
//
const int AOL_RE_CHECKFREQ = 0; // check for random encounter collisons every this many frames
const int AOL_RE_DMAP1 = 001; // the dmap numbers where random encounters can happen
const int AOL_RE_DMAP2 = 002;
const int AOL_RE_DMAP3 = 003;
const int AOL_RE_DMAP4 = 004;
const int AOL_RE_SFX_BATTLEIN = 147; // sfx# for warping into random encounter battle
const int AOL_RE_SFX_BATTLEOUT = 148; // sfx# for warping out
const int AOL_RE_COMBO_PRAIRIE = 21010; // set these to the COMBO numbers of the various overworld encounter environs
const int AOL_RE_COMBO_BEACH = 21008;
const int AOL_RE_COMBO_FOREST = 21014;
const int AOL_RE_COMBO_DESERT = 21009;
const int AOL_RE_COMBO_SWAMP = 21012;
const int AOL_RE_COMBO_CEMETERY = 21013;
const int AOL_RE_COMBO_DRYLAND = 21011;
const int AOL_RE_INDEX_PRAIRIE = 0; // indexes to the aol_re_screens[] array below, the array position of the first element of each row
const int AOL_RE_INDEX_BEACH = 5; // currently set based on array size below
const int AOL_RE_INDEX_FOREST = 10; // arrays are counted from zero, so since there are currently 5 elements in
const int AOL_RE_INDEX_DESERT = 15; // each row these index numbers start at zero and go up by 5.
const int AOL_RE_INDEX_SWAMP = 20;
const int AOL_RE_INDEX_CEMETERY = 25;
const int AOL_RE_INDEX_DRYLAND = 30;
int aol_re_screens[] =
// DMap, Scrn1, Scrn2, Scrn3, Scrn4
{ 005 , 01 , 17 , 33 , 49 , // Prairie
005 , 68 , 84 , 100 , 216 , // Beach
005 , 65 , 81 , 97 , 113 , // Forest
005 , 04 , 20 , 36 , 52 , // Desert
005 , 10 , 26 , 42 , 58 , // Swamp
005 , 71 , 87 , 103 , 119 , // Cemetary
005 , 07 , 23 , 39 , 55 // Dryland
};
int aol_re_screens2[] =
// DMap, Scrn1, Scrn2, Scrn3, Scrn4
{ 006 , 01 , 17 , 33 , 49 , // Prairie
006 , 68 , 84 , 100 , 216 , // Beach
006 , 65 , 81 , 97 , 113 , // Forest
006 , 04 , 20 , 36 , 52 , // Desert
006 , 10 , 26 , 42 , 58 , // Swamp
006 , 71 , 87 , 103 , 119 , // Cemetary
006 , 07 , 23 , 39 , 55 // Dryland
};
int aol_re_screens3[] =
// DMap, Scrn1, Scrn2, Scrn3, Scrn4
{ 007 , 01 , 17 , 33 , 49 , // Prairie
007 , 68 , 84 , 100 , 216 , // Beach
007 , 65 , 81 , 97 , 113 , // Forest
007 , 04 , 20 , 36 , 52 , // Desert
007 , 10 , 26 , 42 , 58 , // Swamp
007 , 71 , 87 , 103 , 119 , // Cemetary
007 , 07 , 23 , 39 , 55 // Dryland
};
int aol_re_screens4[] =
// DMap, Scrn1, Scrn2, Scrn3, Scrn4
{ 008 , 01 , 17 , 33 , 49 , // Prairie
008 , 68 , 84 , 100 , 216 , // Beach
008 , 65 , 81 , 97 , 113 , // Forest
008 , 04 , 20 , 36 , 52 , // Desert
008 , 10 , 26 , 42 , 58 , // Swamp
008 , 71 , 87 , 103 , 119 , // Cemetary
008 , 07 , 23 , 39 , 55 // Dryland
};
// Screen#s can be inputted as their hex value (as shown in zquest) by putting 0x before the number. Eg, 0x20 is 20 in hex.
// other global variables that are set by script
int aol_re_counter = 0;
int aol_re_retdmap = -1;
int aol_re_retscrn = -1;
int aol_re_retx = -1;
int aol_re_rety = -1;
global script Slot2
{
void run()
{
while(true)
{
AOL_Random_Encounter();
Waitdraw();
Waitframe();
}
}
}
void AOL_Random_Encounter()
{
if(aol_re_counter != 0) return;
aol_re_counter = (aol_re_counter +1) % AOL_RE_CHECKFREQ;
int curdmap = Game->GetCurDMap();
if( !(curdmap == AOL_RE_DMAP1 || curdmap == AOL_RE_DMAP2) ) return;
npc e;
for(int i = Screen->NumNPCs(); i > 0; i--)
{
e = Screen->LoadNPC(i);
if(LinkCollision(e))
{
Game->PlaySound(AOL_RE_SFX_BATTLEIN);
aol_re_retdmap = curdmap;
aol_re_retscrn = Game->GetCurScreen();
aol_re_retx = Link->X;
aol_re_rety = Link->Y;
int underLink = Screen->ComboD[ ComboAt(Link->X+8,Link->Y+8) ];
int index = -1;
if (underLink == AOL_RE_COMBO_PRAIRIE) index = AOL_RE_INDEX_PRAIRIE;
else if (underLink == AOL_RE_COMBO_BEACH) index = AOL_RE_INDEX_BEACH;
else if (underLink == AOL_RE_COMBO_FOREST) index = AOL_RE_INDEX_FOREST;
else if (underLink == AOL_RE_COMBO_DESERT) index = AOL_RE_INDEX_DESERT;
else if (underLink == AOL_RE_COMBO_SWAMP) index = AOL_RE_INDEX_SWAMP;
else if (underLink == AOL_RE_COMBO_CEMETERY) index = AOL_RE_INDEX_CEMETERY;
else if (underLink == AOL_RE_COMBO_DRYLAND) index = AOL_RE_INDEX_DRYLAND;
if(index == -1) return;
Link->Warp( aol_re_screens[index], Choose( aol_re_screens[index+1], aol_re_screens[index+2], aol_re_screens[index+3], aol_re_screens[index+4]) );
break;
}
}
}
ffc script AOL_RE_Return
{
void run()
{
Game->PlaySound(AOL_RE_SFX_BATTLEOUT);
Link->X = aol_re_retx;
Link->Y = aol_re_rety;
Link->PitWarp( aol_re_retdmap, aol_re_retscrn);
}
}