Copy to Clipboard Test

Password Slot Machine Code

const int SFX_PASSWORD_SLOT_START = 35;//Sound to play on pulling handle of slot machine
const int SFX_PASSWORD_SLOT_REEL_SPIN = 0;//Sound to play in loop during reel spinning, every aspeed frames.
const int SFX_PASSWORD_SLOT_REEL_STOP = 16;//Sound to play on reel stop.
const int SFX_PASSWORD_SLOT_FINISH = 46;//Sound to play on finishing Password Slot machine input.
const int SFX_PASSWORD_SLOT_BOOM = 3;//Sound to play, when password slot bomb goes boom.

const int PASSWORD_SLOT_COOLDOWN_BETWEEN_SPINS = 30;//Cooldown between spins, in frames.

const int CF_PASSWORD_SLOT_PIECE = 98; //Combo flag used to define password slot machine positions

const int CMB_PASSWORD_SLOT_DUMMY = 1;//Dummy combo used to replace combos under spinning reels.
const int CMB_PASSWORD_SLOT_CURSOR = 1030;//Combo used to render cursor on currently operated reel.
const int CMB_PASSWORD_SLOT_SIDEWARP_ON_BOOM = 1031;//Combo used for auto-side-warping to nuke boom scene on wrong password entry. Must be set as Auto-Side-Warp combo type.
const int CSET_PASSWORD_SLOT_CURSOR = 8;//CSet used to render cursor on currently operated reel.

const int FONT_PASSWORD_SLOT_TIMER = 0;//Font used to render timer

//Password Slot machine
//You are given a password puzzle. But symbols cannot be changed directly. Stand on FFC and Press EX1. This will cause those symbols to start changing like spinning slot machine. Time pressing EX1 to stop symbols changing one by one to input solution. Can be set to have time limit, which, if run out, nukes the whole quest for instant death.

//Set up sequence of combos forming alhabet for password.
//Place password string, flag it with CF_PASSWORD_SLOT_PIECE combo flag
//Set up script that checks puzzle solution based on combos placed in step 2.
//Place invisible FFC at control panel.
// Combo - 1st combo in sequence from step 1.
// CSet - CSet used to render spinning reels.
// D0 - number of symbols in sequence from step 1.
// D1 - delay between symbols changing during reel spinning, in frames.
// D2 - time limit, which, if run out, nukes the whole quest for instant death. In frames.
// D3 - >0 nukes the whole quest on wrong password entry.
// D4 - use CMB_PASSWORD_SLOT_SIDEWARP_ON_BOOM (auto-side warp) to warp Link to a nuke cutscene.

ffc script PasswordSlotMachine{
	void run (int numsymbols, int aspeed, int timelimit, int boomonwrong, int sidewarp ){		
		int State = 0;
		int cmb=-1;
		int pos = ComboAt(CenterX(this),CenterY(this));
		
		int slottimer = 0;
		int spintimer = 0;
		int stopslot=0;
		int cursymbol = this->Data;
		
		while(true){
			cmb = ComboAt (CenterLinkX(), CenterLinkY()-2);
			if (State==0){
				if (slottimer>0)slottimer--;
				cmb = ComboAt (CenterLinkX(), CenterLinkY()-2);
				if (cmb==pos){
					if (Link->PressEx1&& slottimer==0){
						Game->PlaySound(SFX_PASSWORD_SLOT_START);
						State=1;
						spintimer = aspeed;
						for (int i=0;i<176;i++){
							if (ComboFI(i,CF_PASSWORD_SLOT_PIECE))Screen->ComboD[i]=CMB_PASSWORD_SLOT_DUMMY;
						}
						cursymbol = this->Data;
						stopslot=0;
						while(true){							
							if (stopslot>=176){
								State=0;
								stopslot=0;
								slottimer = PASSWORD_SLOT_COOLDOWN_BETWEEN_SPINS;
								break;
							}
							if (ComboFI(stopslot,CF_PASSWORD_SLOT_PIECE)) break;
							stopslot++;
						}
						NoAction();
					}
				}
			}
			if (State==1){
				Screen->FastCombo(4, ComboX(stopslot), ComboY(stopslot),CMB_PASSWORD_SLOT_CURSOR, CSET_PASSWORD_SLOT_CURSOR,OP_OPAQUE);
				for (int i=0;i<176;i++){
					if (i<stopslot)continue;
					if (ComboFI(i,CF_PASSWORD_SLOT_PIECE))Screen->FastCombo(3, ComboX(i), ComboY(i),cursymbol, this->CSet,OP_OPAQUE);
				}
				spintimer--;
				
				if (spintimer<=0){
					Game->PlaySound(SFX_PASSWORD_SLOT_REEL_SPIN);
					cursymbol++;
					if (cursymbol>=(this->Data+numsymbols))cursymbol = this->Data;
					spintimer = aspeed;
				}
				if (Link->PressEx1){
					Game->PlaySound(SFX_PASSWORD_SLOT_REEL_STOP);
					Screen->ComboD[stopslot] = cursymbol;
					while(true){
						stopslot++;
						if (stopslot>=176){
							State=0;
							stopslot=0;
							Game->PlaySound(SFX_PASSWORD_SLOT_FINISH);
							slottimer = PASSWORD_SLOT_COOLDOWN_BETWEEN_SPINS;
							if (boomonwrong>0){
								Waitframes(3);
								if (!Screen->State[ST_SECRET]){
									Game->PlaySound(3);
									Screen->Quake=1000;
									Screen->Rectangle(7, 0, 0, 256, 175,1, 1,0, 0, 0,true, OP_OPAQUE);
									if (sidewarp)this->Data = CMB_PASSWORD_SLOT_SIDEWARP_ON_BOOM;
									Link->Invisible=true;
									Waitframes(3);
									Link->HP=0;
									Quit();
								}
							}
							break;
						}
						if (ComboFI(stopslot,CF_PASSWORD_SLOT_PIECE)) break;
					}
				}
				NoAction();
			}
			if (timelimit>0){
				Screen->DrawInteger	(7, this->X, this->Y-16, FONT_PASSWORD_SLOT_TIMER, Cond(timelimit<600, 0x81,1), 0,0, 0, timelimit, 0,OP_OPAQUE);
				if(!Screen->State[ST_SECRET])timelimit--;
				if (timelimit<=0){
					Game->PlaySound(3);
					Screen->Quake=1000;
					Screen->Rectangle(7, 0, 0, 256, 175,1, 1,0, 0, 0,true, OP_OPAQUE);
					if (sidewarp)this->Data = CMB_PASSWORD_SLOT_SIDEWARP_ON_BOOM;
					
					Link->Invisible=true;
					Waitframes(3);					
					Link->HP=0;
					Quit();
				}
			}
			Waitframe();
		}		
	}
}