Copy to Clipboard Test

Sequentional Ambush nest Code

const int SPR_AMBUSH_SEQUENCE_SPAWN = 22;//Sprite to display, when enemy spawn from his hiding spot on ambush.

//Ambush, multiple enemies, sequential. Spawns an enemy, when Link is near. When the enemy is dead another enemy cap pop out. Once nest is emptied, it replaces with screen`s undercombo. Clear all the nests to trigger secrets.
//Place FFC at enemy hiding spot.
//D0 - ID of enemy
//D1  #####.____ - Detection radius.
//D1  _____.#### - cooldown between ambushes. Used to slowdown spawn camps.
//D2 & D3 - size offset for larger enemies.
//D4 - Set to -1 - replace combo underneath FFC with screen`s undercombo, or
//     positive number to replace destroyed combo with ID, using FFC`s CSet.
//D5 - Sound to play on ambush.
//D6 - Abs - Enemy jump when popping out of hiding spot on ambush. 0-3. <0 - Don`t count for secret trigger. If all nests set D6 to <0 - no secret trigger occur. 
//D7 - Number of enemies inside hiding spot.

ffc script AmbushSequence{
	void run (int enemyID, int radius, int sizex, int sizey, int undercombo, int sound, int jump, int number){
		int cmb = ComboAt(CenterX(this), CenterY(this));
		if (Screen->State[ST_SECRET]){
			if (undercombo>0){
				Screen->ComboD[cmb]= undercombo;
				Screen->ComboC[cmb] = this->CSet;
			}
			else if (undercombo==-1){
				Screen->ComboD[cmb]= Screen->UnderCombo;
				Screen->ComboC[cmb] = Screen->UnderCSet;
			}
			Quit();
		}
		if (sizex==0) sizex=1;
		if (sizey==0) sizey=1;
		int count = 0;
		int state = 0;
		int dist = 0;
		int cooldown = Abs(GetLowFloat(radius));
		radius = Abs(GetHighFloat(radius));
		int timer = cooldown;
		npc en;
		while(true){
			if (state==0){
				dist = Distance(Link->X, Link->Y, this->X, this->Y);
				if (dist<=radius){
					Game->PlaySound(sound);
					en = CreateNPCAt(enemyID, this->X-8*(sizex-1), this->Y-8*(sizey-1));
					en->Jump = Abs(jump);
					lweapon l = CreateLWeaponAt(LW_SPARKLE, this->X, this->Y);
					l->UseSprite(SPR_AMBUSH_SEQUENCE_SPAWN);
					l->NumFrames=3;
					l->ASpeed=30;
					l->CollDetection=false;
					state=1;					
					if (this->InitD[7]==1){
						if (undercombo>0){
							Screen->ComboD[cmb]= undercombo;
							Screen->ComboC[cmb] = this->CSet;
						}
						else if (undercombo==-1){
							Screen->ComboD[cmb]= Screen->UnderCombo;
							Screen->ComboC[cmb] = Screen->UnderCSet;
						}
					}
				}
			}
			if (state==1){
				if (!en->isValid()){
					this->InitD[7]--;
					if (this->InitD[7]==0){
						for(int i=1;i<=33;i++){
							if (Screen->State[ST_SECRET]) break;
							if (jump<0) break;
							if (i==33){
								Game->PlaySound(SFX_SECRET);
								Screen->TriggerSecrets();
								Screen->State[ST_SECRET]=true;
								break;
							}
							ffc n = Screen->LoadFFC(i);
							if (n->Script!=this->Script)continue;
							if (n->InitD[6]<0)continue;
							if (n->InitD[7] > 0) break;
						}
						timer = cooldown;
						state=2;
					}					
					else{ 
						state=2;
						timer = cooldown;
						if (timer<=0) state=0;
					}
				}
			}
			if (state==2){
				if (timer>0 && this->InitD[7]>0){
					timer--;
					if (timer<=0) state=0;
				}
			}
			Waitframe();
		}
	}
}