ZoriaRPG

ZC Nine Switch Combination Lock FFC

Nov 19th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. ffc script NineSwitchPuzzle{
  2.     void run(int layer, int solveSFX, int failSFX, int pressButtonSFX, int sens){
  3.         int orderPressed[9]; //Holds the actual order in which Link touches combos.
  4.         bool triggered;
  5.         bool triggeredFalse;
  6.         bool correctOrder;
  7.         int buttonsPressed;
  8.         bool done;
  9.         int pressedOrderRequired[9]={6040,6052,6048,6044,6056,6060,6064,6068,6072};
  10.         //Populate with the desired order of combos to press.
  11.        
  12.         while(true){
  13.             for ( int q = 0; q <= SizeOfArray(orderPressed); q++ ) {
  14.                
  15.                 int pos = orderPressed[q];
  16.                 if ( pos ) { //If the button was pressed.
  17.                     if ( pos == pressedOrderRequired[q] ) correctOrder = true;
  18.                     if ( pos != pressedOrderRequired[q] ) correctOrder = false;
  19.                     //If thre is a value in the index...
  20.                     //and it matches the required order, set the value of correctOrder true.
  21.                     //otherwise, set it false.
  22.                     buttonsPressed++; //Increase the count of presses.
  23.                 }
  24.             }
  25.            
  26.             if ( buttonsPressed == 9 && correctOrder ) triggered = true;
  27.             if ( buttonsPressed == 9 && !correctOrder ) triggeredFalse = true;
  28.  
  29.             if ( triggered ) {
  30.                 //Play the sound for solving properly.
  31.                 if ( solveSFX ) Game->PlaySound(solveSFX);
  32.                 //Effect of triggering properly.
  33.                 Screen->TriggerSecrets(); //Generic secrets triggered.
  34.                
  35.                 //Should the secrets be perm?
  36.                
  37.                 //Wait, or Quit
  38.                 done = true;
  39.                 Waitframe();
  40.             }
  41.            
  42.             //If pressed in the incorrect order.
  43.             if ( triggeredFalse ) {
  44.                 //Wipe the array of stored values.
  45.                 for ( int q = 0; q <= SizeOfArray(orderPressed); q++ ) {
  46.                     orderPressed[q] = 0;
  47.                 }
  48.                 //Reset all nine combos from a pressed, to unpressed state...
  49.                 for ( int q = 0; q < 176; q++ ) {
  50.                     int cmb = GetLayerComboD(layer,q);
  51.                     if ( cmb == 6041 || cmb == 6053 || cmb == 6049 || cmb == 6045
  52.                     || cmb == 6057 || cmb == 6061 || cmb == 6065 || cmb == 6069
  53.                     || cmb == 6074 )  {
  54.                         //change the combo to the previous one in the combo list...
  55.                         SetLayerComboD(layer,q,cmb-1);
  56.                     }
  57.                 }
  58.                 if ( failSFX ) Game->PlaySound(failSFX); //Play the failure sfx sound.
  59.                 //Reset the variables.
  60.                 buttonsPressed = 0;
  61.                 triggered = false;
  62.                 triggeredFalse = false;
  63.                 correctOrder = false;
  64.                 Waitframe();
  65.             }
  66.                
  67.            
  68.             //If we haven't triggered either event...
  69.             if ( !triggered && !triggeredFalse ) {
  70.                 for ( int q = 0; q < 176; q++ ) {
  71.                     int cmb = GetLayerComboD(layer,q);
  72.                     if ( ( cmb == 6040 || cmb == 6052 || cmb == 6048 || cmb == 6044
  73.                         || cmb == 6056 || cmb == 6060 || cmb == 6064 || cmb == 6068
  74.                         || cmb == 6072 ) && ( __LinkComboCollision(q,sens) )
  75.                     {
  76.                             //change the combo to the next in the combo list...
  77.                             SetLayerComboD(layer,q,cmb+1);
  78.                        
  79.                             //Play the sound for pressing a button...
  80.                             if ( pressButtonSFX ) Game->PlaySound(pressButtonSFX);
  81.                        
  82.                             //Look through the array orderPressed for a blank slot.
  83.                             for ( int q = 0; q <= SizeOfArray(orderPressed) q++ ) {
  84.                                 int pos = orderPressed[q];
  85.                                 //Fill the blank slot with the combo ID.
  86.                                 if ( ! pos ) orderPressed[q] = cmb;
  87.                             }
  88.                     }
  89.                 }
  90.             }
  91.            
  92.             if ( done ) {
  93.                 this->Data = 0;
  94.                 this->Script = 0;
  95.                 Quit();
  96.             }
  97.             Waitframe();
  98.         }
  99.     }
  100.     //Returns TRUE if Link touches a combo.
  101.     bool __LinkComboCollision(int loc, int sens){
  102.         int ax = Link->X;
  103.         int ay = Link->Y;
  104.         int bx = (Link->X)+(Link->HitWidth);
  105.         int by = (Link->Y)+(Link->HitHeight);
  106.         if(!(RectCollision( ComboX(loc), ComboY(loc), (ComboX(loc)+16), (ComboY(loc)+16), ax, ay, bx, by))) return false;
  107.         else if (!(Distance(CenterLinkX(), CenterLinkY(), (ComboX(loc)+8), (ComboY(loc)+8)) < (sens+8))) return false;
  108.         else return true;
  109.     }
  110. }
Add Comment
Please, Sign In to add comment