Advertisement
ZoriaRPG

Z3 Shop (2.54) v0.4

Apr 19th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.46 KB | None | 0 0
  1. import "std.zh"
  2.  
  3. const int FLAG_SHOP_ITEM = 100; // A flag to use for shop items.
  4. const int CMB_SHOP_ITEM = 2500; // Blank, solid combo.
  5. const int SHOP_PRICE_Y_OFFSET = 18;
  6. const int SHOP_PRICE_X_OFFSET = -4;
  7. const int SFX_BUYITEM = 63;
  8. const int SHOP_STRING_LAYER = 2;
  9. const int SHOP_STRING_SHADOW_X_OFFSET = 1;
  10. const int SHOP_STRING_SHADOW_Y_OFFSET = 1;
  11. const int SHOP_STRING_BG_COLOUR = 0x0F;
  12. const int SHOP_STRING_FG_COLOUR = 0x01;
  13.  
  14. ffc script Automatic_Z3_Shop
  15. {
  16.     void run(int shop_id)
  17.     {
  18.         item shopitems[3];  int count; messagedata md[3];
  19.          
  20.         shopdata sd = Game->LoadShopData(shop_id);
  21.         md[0] = Game->LoadMessageData(sd->String[0]);
  22.         md[1] = Game->LoadMessageData(sd->String[1]);
  23.         md[2] = Game->LoadMessageData(sd->String[2]);
  24.         for ( int q = 0; q < 176; ++q )
  25.         {
  26.             //FInd the flags and place the items
  27.             if ( Screen->ComboF[q] == FLAG_SHOP_ITEM )
  28.             {
  29.                 Screen->ComboD[q] = CMB_SHOP_ITEM;
  30.                 shopitems[count] = Screen->CreateItem(sd->Item[count]);
  31.                 shopitems[count]->X = ComboX(q);
  32.                 shopitems[count]->Y = ComboY(q);
  33.                 shopitems[count]->HitXOffset = -32768;
  34.                 shopitems[count]->PickupString = sd->String[count];
  35.                 shopitems[count]->PickupStringFlags |= 0x04;
  36.                 ++count;
  37.                 if ( count > 2 ) { break; }
  38.             }
  39.         }
  40.         while(1)
  41.         {
  42.            
  43.             //Draw the prices
  44.             Screen->DrawString( SHOP_STRING_LAYER, shopitems[0]->X+SHOP_PRICE_X_OFFSET+SHOP_STRING_SHADOW_X_OFFSET,
  45.                 shopitems[0]->Y+SHOP_PRICE_Y_OFFSET+SHOP_STRING_SHADOW_Y_OFFSET, FONT_Z3SMALL, SHOP_STRING_BG_COLOUR,
  46.                 0, 0, sd->Price[0], OP_OPAQUE);
  47.                
  48.             Screen->DrawString( SHOP_STRING_LAYER, shopitems[0]->X+SHOP_PRICE_X_OFFSET,
  49.                 shopitems[0]->Y+SHOP_PRICE_Y_OFFSET, FONT_Z3SMALL, SHOP_STRING_FG_COLOUR,
  50.                 0, 0, sd->Price[0], OP_OPAQUE);
  51.            
  52.             Screen->DrawString( SHOP_STRING_LAYER, shopitems[1]->X+SHOP_PRICE_X_OFFSET+SHOP_STRING_SHADOW_X_OFFSET,
  53.                 shopitems[0]->Y+SHOP_PRICE_Y_OFFSET+SHOP_STRING_SHADOW_Y_OFFSET, FONT_Z3SMALL, SHOP_STRING_BG_COLOUR,
  54.                 0, 0, sd->Price[1], OP_OPAQUE);
  55.                
  56.             Screen->DrawString( SHOP_STRING_LAYER, shopitems[1]->X+SHOP_PRICE_X_OFFSET,
  57.                 shopitems[0]->Y+SHOP_PRICE_Y_OFFSET, FONT_Z3SMALL, SHOP_STRING_FG_COLOUR,
  58.                 0, 0, sd->Price[1], OP_OPAQUE);
  59.                
  60.             Screen->DrawString( SHOP_STRING_LAYER, shopitems[2]->X+SHOP_PRICE_X_OFFSET+SHOP_STRING_SHADOW_X_OFFSET,
  61.                 shopitems[0]->Y+SHOP_PRICE_Y_OFFSET+SHOP_STRING_SHADOW_Y_OFFSET, FONT_Z3SMALL, SHOP_STRING_BG_COLOUR,
  62.                 0, 0, sd->Price[2], OP_OPAQUE);
  63.                
  64.             Screen->DrawString( SHOP_STRING_LAYER, shopitems[2]->X+SHOP_PRICE_X_OFFSET,
  65.                 shopitems[0]->Y+SHOP_PRICE_Y_OFFSET, FONT_Z3SMALL, SHOP_STRING_FG_COLOUR,
  66.                 0, 0, sd->Price[2], OP_OPAQUE);
  67.  
  68.                 //Don't do shop interactivity while Link is holding up an item!
  69.                 if ( Link->Action == LA_HOLD1LAND ) continue;
  70.                 if ( Link->Action == LA_HOLD2LAND ) continue;
  71.  
  72.             for ( int q = 0; q < 3; ++q )
  73.             {
  74.                 if ( PressedBuyButton() )
  75.                 {
  76.                     if ( Link->Dir == DIR_UP )
  77.                     {
  78.                         if ( Game->Counter[CR_RUPEES] >= sd->Price[q] )
  79.                         {
  80.                             if ( _Z3_Below(shopitems[q]) )
  81.                             {
  82.                                 if ( _Z3_DistXY(shopitems[q], 12) )
  83.                                 {
  84.                                     Audio->PlaySound(SFX_BUYITEM);
  85.                                     Game->DCounter[CR_RUPEES] -= sd->Price[q];
  86.                                     shopitems[q]->Pickup = IP_HOLDUP;
  87.                                     shopitems[q]->HitXOffset = 0;
  88.                                     shopitems[q]->X = Link->X;
  89.                                     shopitems[q]->Y = Link->Y;
  90.                                 }
  91.                             }
  92.                         }
  93.                     }
  94.                 }
  95.             }
  96.             Waitframe();
  97.         }
  98.     }
  99. }
  100.  
  101. bool _Z3_Below(item n){ return Link->Y > n->Y; }
  102.  
  103. bool _Z3_DistXY(item b, int distance) {
  104.     int distx; int disty;
  105.     distx = Abs(Link->X - b->X);
  106.     disty = Abs(Link->Y - b->Y);
  107.  
  108.     return ( distx <= distance && disty <= distance );
  109. }
  110.  
  111. const int Z3_SHOP_BUY_BUTTON_A = 1;
  112. const int Z3_SHOP_BUY_BUTTON_B = 1;
  113. const int Z3_SHOP_BUY_BUTTON_L = 0;
  114. const int Z3_SHOP_BUY_BUTTON_R = 0;
  115. const int Z3_SHOP_BUY_BUTTON_EX1 = 0;
  116. const int Z3_SHOP_BUY_BUTTON_EX2 = 0;
  117. const int Z3_SHOP_BUY_BUTTON_EX3 = 0;
  118. const int Z3_SHOP_BUY_BUTTON_EX4 = 0;
  119. bool PressedBuyButton()
  120. {
  121.     if ( Z3_SHOP_BUY_BUTTON_A && Link->PressA ) return true;
  122.     if ( Z3_SHOP_BUY_BUTTON_B && Link->PressB ) return true;
  123.     if ( Z3_SHOP_BUY_BUTTON_L && Link->PressL ) return true;
  124.     if ( Z3_SHOP_BUY_BUTTON_R && Link->PressR ) return true;
  125.     if ( Z3_SHOP_BUY_BUTTON_EX1 && Link->PressEx1 ) return true;
  126.     if ( Z3_SHOP_BUY_BUTTON_EX2 && Link->PressEx2 ) return true;
  127.     if ( Z3_SHOP_BUY_BUTTON_EX3 && Link->PressEx3 ) return true;
  128.     if ( Z3_SHOP_BUY_BUTTON_EX4 && Link->PressEx4 ) return true;
  129.    
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement