Facebook
From Shmirko, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 176
  1. import "std.zh"
  2.  
  3. ffc script real_npcV2 {
  4.   void run(int m, int gmitem, int f, int d, int def_dir, int npcissolid, int gm_min, int gm_max) {
  5.     int d_x;
  6.     int d_y;
  7.     int a_x;
  8.     int a_y;
  9.     int ir;
  10.     int tho=(this->TileHeight*16-16);
  11.     int orig_d = this->Data;
  12.     int Apressed2;  
  13.     int Appr2;
  14.     int onscreenedge;
  15.     if(d == 0) d = 48;
  16.  
  17.  
  18.     while(true) {
  19.         //This detects if link is on the edge of the screen
  20.         if (Link->X<8 || Link->Y<8 || Link->X>232 || Link->Y>152){onscreenedge=1;} else {onscreenedge=0;}
  21.  
  22.         //This checks if you're above or below the NPC to create an overhead effect
  23.         if (Link->Y<this->Y-8+tho && onscreenedge==0){this->Flags[FFCF_OVERLAY] = true;} else {this->Flags[FFCF_OVERLAY] = false;}
  24.  
  25.         //This detects if A was pressed, allowing you to exit messages with the A button
  26.         if (Link->InputA)
  27.         {
  28.             if (Apressed2==1){Apressed2=0;}
  29.         else
  30.         {
  31.             if (Appr2==0){Apressed2=1; Appr2=1;}}
  32.         }
  33.         else
  34.         {
  35.             Apressed2=0;
  36.             Appr2=0;
  37.         }
  38.  
  39.         d_x = this->X - Link->X;
  40.         d_y = this->Y+(this->TileHeight*16-16) - Link->Y;
  41.         a_x = Abs(d_x);
  42.         a_y = Abs(d_y);
  43.    
  44.         if(f != 0) {
  45.             if(a_x < d && a_y < d) {
  46.                   if(a_x <= a_y) {
  47.                     if(d_y >= 0) {
  48.                           this->Data = orig_d + DIR_DOWN;
  49.                     } else {
  50.                         this->Data = orig_d + DIR_UP;
  51.                     }
  52.                 } else {
  53.                     if(d_x >= 0) {
  54.                         this->Data = orig_d + DIR_LEFT;
  55.                     } else {
  56.                         this->Data = orig_d + DIR_RIGHT;
  57.                     }
  58.                   }
  59.             } else {
  60.                 this->Data = orig_d + def_dir;
  61.             }
  62.         }
  63.        
  64.         //This checks if you have item D1, and makes the NPC disappear if you do.
  65.         if (Link->Item[gmitem] == true){this->X=-256; this->Y=-256;}
  66.         else
  67.         {
  68.  
  69.             //This enables horizontal guard mode.
  70.             if (gm_max>0)
  71.             {
  72.                 if (Link->X>gm_min-32 && Link->X<gm_max+32 && Link->Y>this->Y+tho-32 && Link->Y<this->Y+tho+32) {ir=1;}
  73.                 else {ir=0;}
  74.                 if (Link->X<this->X-2 && this->X>gm_min && ir==1)
  75.                 {
  76.                     if (Link->X>gm_min){this->Vx= (- this->X + Link->X)/4;}
  77.                     else{this->Vx= (- this->X + gm_min)/4;}
  78.                 }
  79.                 if (Link->X>this->X+2 && this->X<gm_max && ir==1)
  80.                 {
  81.                     if (Link->X<gm_max){this->Vx= (Link->X - this->X)/4;}
  82.                     else{this->Vx= (gm_max - this->X)/4;}
  83.                 }
  84.                 if (Link->X<this->X+2 && Link->X>this->X-2){this->Vx=0;}
  85.                 if (ir==0){this->Vx=0;}
  86.                 if (this->X<gm_min+1){
  87.                     if (this->Vx<0) this->Vx=0;
  88.                         this->X=gm_min;
  89.                 }
  90.                 if (this->X>gm_max-1){
  91.                     if (this->Vx>0) this->Vx=0;
  92.                     this->X=gm_max;
  93.             }
  94.         }
  95.  
  96.         //This enables vertical guard mode.
  97.         if (gm_max<0)
  98.         {
  99.             if (Link->Y>-gm_min-32 && Link->Y<-gm_max+32 && Link->X>this->X-32 && Link->X<this->X+32) {ir=1;}
  100.             else {ir=0;}
  101.             if (Link->Y<this->Y-2+tho && this->Y+tho>-gm_min && ir==1)
  102.             {
  103.                 if (Link->Y>-gm_min){this->Vy= (- this->Y-tho + Link->Y)/4;}
  104.                 else {this->Vy= (- this->Y-tho + -gm_min)/4;}
  105.             }
  106.             if (Link->Y>this->Y+2+tho && this->Y+tho<-gm_max && ir==1)
  107.             {
  108.                 if (Link->Y<-gm_max){this->Vy= (Link->Y - this->Y-tho)/4;}
  109.                 else {this->Vy= (-gm_max - this->Y-tho)/4;}
  110.             }
  111.                 if (Link->Y<this->Y+2+tho && Link->Y>this->Y-2+tho){this->Vy=0;}
  112.                 if (ir==0){this->Vy=0;}
  113.                 if (this->Y+tho<-gm_min+1){
  114.                     if (this->Vy<0)this->Vy=0;
  115.                     this->Y=-gm_min-tho;
  116.                 }
  117.                 if (this->Y+tho>-gm_max-1){
  118.                     if (this->Vy>0)this->Vy=0;
  119.                     this->Y=-gm_max-tho;
  120.                 }
  121.             }
  122.  
  123.         }
  124.  
  125.         if (this->Vy>0)this->Data = orig_d + DIR_UP;
  126.         if (this->Vy<0)this->Data = orig_d + DIR_DOWN;
  127.         if (this->Vx>0)this->Data = orig_d + DIR_RIGHT;
  128.         if (this->Vx<0)this->Data = orig_d + DIR_LEFT;
  129.    
  130.         if(Apressed2==1 && a_x < 24 && a_y < 24) {
  131.             //This is all checking if Link is facing the NPC while to the left, to the right, above, or below the NPC
  132.             if (Link->X<this->X-8 && Link->Y>this->Y+tho-12 && Link->Y<this->Y+tho+8 && Link->Dir == DIR_RIGHT || Link->X>this->X+8 && Link->Y>this->Y+tho-12 && Link->Y<this->Y+tho+8 && Link->Dir == DIR_LEFT || Link->Y<this->Y+tho-8 && Link->X>this->X-8 && Link->X<this->X+8 && Link->Dir == DIR_DOWN || Link->Y>this->Y+tho+8 && Link->X>this->X-8 && Link->X<this->X+8 && Link->Dir == DIR_UP){
  133.                 Apressed2=0;
  134.                 Screen->Message(m);
  135.                 Link->InputA = false;
  136.             }
  137.         }
  138.  
  139.         //This enables the NPC to be solid without having to lay a solid combo under it.
  140.         if (npcissolid>0){
  141.             if ((Abs(Link->X - this->X) < 10) &&
  142.                 (Link->Y <= this->Y+tho + 12) && (Link->Y > this->Y+tho+8)){Link->Y = this->Y+tho+12;}
  143.            
  144.             if ((Abs(Link->Y - this->Y-tho) < 10) &&
  145.                 (Link->X >= this->X - 12) && (Link->X < this->X-8)){Link->X = this->X-12;}
  146.        
  147.             if ((Abs(Link->X - this->X) < 10) &&
  148.                 (Link->Y >= this->Y+tho - 12) && (Link->Y < this->Y+tho-8)){Link->Y = this->Y+tho-12;}
  149.        
  150.             if ((Abs(Link->Y - this->Y-tho) < 10) &&
  151.                 (Link->X <= this->X + 12) && (Link->X > this->X+8)){Link->X = this->X+12;}
  152.         }
  153.        
  154.         Waitframe();
  155.     }
  156.   }
  157. }
  158.  
  159. //D0: ID of the item
  160. //D1: Price of the item
  161. //D2: Message that plays when the item is bought
  162. //D3: Message that plays when you don't have enough rupees
  163. //D4: Input type 0=A 1=B 2=L 3=R
  164. ffc script SimpleShop{
  165.     void run(int itemID, int price, int m, int n, int input){
  166.         int loc = ComboAt(this->X,this->Y);
  167.         while(true){
  168.             while(!AgainstComboBase(loc) || !SelectPressInput(input)) Waitframe();
  169.             SetInput(input,false);
  170.                 if(Game->Counter[CR_RUPEES] >= price){
  171.                 Game->DCounter[CR_RUPEES] -= price;
  172.                 item shpitm = CreateItemAt(itemID, Link->X, Link->Y);
  173.                 shpitm->Pickup = IP_HOLDUP;
  174.                 Screen->Message(m);
  175.                 }
  176.                 else{
  177.                 Screen->Message(n);
  178.                 }              
  179.             Waitframe();
  180.         }
  181.     }
  182.     bool AgainstComboBase(int loc){
  183.         return Link->Z == 0 && (Link->Dir == DIR_UP && Link->Y == ComboY(loc)+8 && Abs(Link->X-ComboX(loc)) < 8);
  184.     }
  185. }
  186.  
  187. //If you are already using the signpost script remove the code below
  188. bool SelectPressInput(int input){
  189.     if(input == 0) return Link->PressA;
  190.     else if(input == 1) return Link->PressB;
  191.     else if(input == 2) return Link->PressL;
  192.     else if(input == 3) return Link->PressR;
  193. }
  194. void SetInput(int input, bool state){
  195.     if(input == 0) Link->InputA = state;
  196.     else if(input == 1) Link->InputB = state;
  197.     else if(input == 2) Link->InputL = state;
  198.     else if(input == 3) Link->InputR = state;
  199. }
  200.  
  201. //Permanent Tiered Secrets Script
  202. //D0: The Screen->D (0-7) to use to store the number of triggered secrets on the screen
  203. //D1: If you want to use a layered combo to detect secrets being triggered, set this to the layer number
  204. //D2: In an infinite looping tiered secret, set this to the number of states the secret can have
  205. ffc script PermanentTieredSecrets{
  206.         void run(int D, int Layer, int NumStates){
  207.                 //Triggers the number of screen secrets stored in Screen->D when you enter the screen
  208.                 if(Screen->D[D]>0){
  209.                         for(int i=0; i<Screen->D[D]; i++){
  210.                                 Screen->TriggerSecrets();
  211.                         }
  212.                 }
  213.                 //Saves the combo position and combo under the FFC
  214.                 int ComboPos = ComboAt(this->X+8, this->Y+8);
  215.                 int Combo;
  216.                 if(Layer>0)
  217.                         Combo = GetLayerComboD(Layer, ComboPos);
  218.                 else if(Layer==0)
  219.                         Combo = Screen->ComboD[ComboPos];
  220.                 while(true){
  221.                         //Detects if the combo under the FFC changes and increases Screen->D
  222.                         if(Layer>0&&GetLayerComboD(Layer, ComboPos)!=Combo){
  223.                                 Combo = GetLayerComboD(Layer, ComboPos);
  224.                                 Screen->D[D]++;
  225.                         }
  226.                         else if(Layer==0&&Screen->ComboD[ComboPos]!=Combo){
  227.                                 Combo = Screen->ComboD[ComboPos];
  228.                                 Screen->D[D]++;
  229.                         }
  230.                         //Wraps Screen->D if NumStates is set, otherwise caps Screen->D at 100
  231.                         if(NumStates>0&&Screen->D[D]>=NumStates)
  232.                                 Screen->D[D] -= NumStates;
  233.                         else if(NumStates==0&&Screen->D[D]>100){
  234.                                 Screen->D[D] = 100;
  235.                         }
  236.                         Waitframe();
  237.                 }
  238.         }
  239. }
  240.  
  241. //D0: ID of the item
  242. //D1: Price of the item
  243. //D2: Message that plays when the item is bought
  244. //D3: Message that plays when you don't have enough rupees
  245. //D4: Input type 0=A 1=B 2=L 3=R
  246. ffc script SimpleShop{
  247.     void run(int itemID, int price, int m, int n, int input){
  248.         int loc = ComboAt(this->X,this->Y);
  249.         while(true){
  250.             while(!AgainstComboBase(loc) || !SelectPressInput(input)) Waitframe();
  251.             SetInput(input,false);
  252.                 if(Game->Counter[CR_RUPEES] >= price){
  253.                 Game->DCounter[CR_RUPEES] -= price;
  254.                 item shpitm = CreateItemAt(itemID, Link->X, Link->Y);
  255.                 shpitm->Pickup = IP_HOLDUP;
  256.                 Screen->Message(m);
  257.                 }
  258.                 else{
  259.                 Screen->Message(n);
  260.                 }              
  261.             Waitframe();
  262.         }
  263.     }
  264.     bool AgainstComboBase(int loc){
  265.         return Link->Z == 0 && (Link->Dir == DIR_UP && Link->Y == ComboY(loc)+8 && Abs(Link->X-ComboX(loc)) < 8);
  266.     }
  267. }
  268.  
  269. //If you are already using the signpost script remove the code below
  270. bool SelectPressInput(int input){
  271.     if(input == 0) return Link->PressA;
  272.     else if(input == 1) return Link->PressB;
  273.     else if(input == 2) return Link->PressL;
  274.     else if(input == 3) return Link->PressR;
  275. }
  276. void SetInput(int input, bool state){
  277.     if(input == 0) Link->InputA = state;
  278.     else if(input == 1) Link->InputB = state;
  279.     else if(input == 2) Link->InputL = state;
  280.     else if(input == 3) Link->InputR = state;
  281. }