I can post an example
//This enemy behaves like a Leever, but homes in on Link whenever it's above ground.
// This approximately recreates the behavior of Leevers in Link's Awakening,
// among other games.
//
//Enemy Attributes Used:
// -Step Speed: Determines speed (standard: 50)
// -Misc. Attr. 1: Frames that the enemy will spend underground (default: 60)
// -Misc. Attr. 2: Frames that the enemy will spend aboveground (default: 120)
// -Misc. Attr. 11: Combo index for enemy graphics
// -Misc. Attr. 12: FFC Script Slot
//
//The combos must be four consecutive combos:
// 1. Initial surfacing combo
// 2. Second surfacing combo
// 3. Above ground combo
// 4. Below ground combo (usually blank)
//The combos play in the order 4-1-2-3-2-1-4-1-2-3... etc.
//Misc. Attribute Indexes
const int Z4LEEVER_COMBO_INDEX = 10;
const int Z4LEEVER_UNDER_TIME_INDEX = 0;
const int Z4LEEVER_ABOVE_TIME_INDEX = 1;
int angle;
ffc script Ghosted_Z4Leever {
void run(int enemyID) {
npc ghost;
int combo;
float step;
int belowTime;
int aboveTime;
float lastX; //<-- defined in the ffc script
//Initialize
ghost = Ghost_InitAutoGhost(this, enemyID);
Ghost_SetFlag(GHF_NORMAL);
combo = Ghost_GetAttribute(ghost, Z4LEEVER_COMBO_INDEX, 0);
step = ghost->Step/100;
belowTime = Ghost_GetAttribute(ghost, Z4LEEVER_UNDER_TIME_INDEX, 60);
aboveTime = Ghost_GetAttribute(ghost, Z4LEEVER_ABOVE_TIME_INDEX, 120);
while(true) {
//underground
Ghost_Data = combo+3;
ghost->CollDetection = false; //Make ghost intangible
Ghost_Waitframes(this, ghost, true, true, belowTime);
Change_Pos(this, ghost, Link->X, Link->Y, step);
//surfacing
Ghost_Data = combo;
Ghost_Waitframes(this, ghost, true, true, 10);
Ghost_Data = combo+1;
Ghost_Waitframes(this, ghost, true, true, 10);
//aboveground
Ghost_Data = combo+2;
ghost->CollDetection = true; //Make ghost tangible
for(int i=0; i<aboveTime + Rand(30, 60); i++) {
Ghost_MoveTowardLink(step, 0);
Ghost_Waitframe(this, ghost, true, true);
}
//digging
Ghost_Data = combo+1;
ghost->CollDetection = false; //Make ghost intangible
Ghost_Waitframes(this, ghost, true, true, 10);
Ghost_Data = combo;
Ghost_Waitframes(this, ghost, true, true, 10);
}
}
}
void Change_Pos(ffc this, npc ghost, int x, int y, int step)
{
bool canSurface = false;
lastX = 0; //<-- accessed in the external function
while(!canSurface)
{
if (Ghost_X > x - 32 && Ghost_X < x + 47) Ghost_X = Rand(0, 304);
if (Ghost_Y > y - 32 && Ghost_Y < y + 47) Ghost_Y = Rand(0, 160);
if (((Ghost_X < x - 32 || Ghost_X > x + 47) && (Ghost_Y < y - 32 || Ghost_Y > y + 48)) && (Ghost_CanMove(Ghost_Dir, step, 0)))
canSurface = true;
else
canSurface = false;
}
}
Edited by Shadowblitz16, 31 December 2016 - 02:47 PM.