////////////////////////////////////// /// Shop FFC Item with Yes/No Menu /// /// By: ZoriaRPG /// /// 26-June-2016 /// /// v0.5.5 /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// D0 : The item ID (number) to give Link. /// /// D1 : The price of the item. /// /// D2 : The item info message (high) and the OPTIONAL alternate counter (low). /// /// --> Integer Portion (#####.xxxx) THe message to display for Item Info menu option. /// /// --> Decimal Portion (xxxxx.####) An alternate counter, instead of the default (CR_RUPEES), if desired. /// /// D3 : Alternate combo to use, if you want a generic combo for shop items. /// /// D4 : Sound to play if purchase is a success. /// /// D5 : If set to '1', Link holds the item up with one hand. If set to '2', he holds it up with two hands. /// /// Set to '0' for no item hold-up animation. /// /// D6 : This value is split between the integer portion,a nd the decimal. the decimal portion is only used for optional shop capabilities. /// /// --> Integer Portion ( #####.xxxx ) Set to '1' to sell only one time. /// /// If set to '1', a 'sold out' sign will take the place of this item when it sells. /// /// If set ABOVE 1, a REPLACEMENT item with this ID will take the place of the item when it sells. /// /// --> Decimal Portion ( xxxxx.#### ) If you wish to set a different place for a REPLACEMENT ITEM, enter it here. /// /// D7 : The Nth item in this shop. Set each in sequence, starting at '1', and ending at '9' (max) or whatever the number of items is that /// /// you have in this shop. /// /// --> Example: If a shop with three items, number one of them '1', another '2', and the last '3'. /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Requested By: JudasRising, with additional features requested by Dimentio, and Grayswandir. /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // There are certainly other ways to handle these... // Vars used by the Tango menu. int menuCommand; int menuArg; //Tango Menu Init void SetUpWindow(int slot, int style, int x, int y, int size) { SetStyleSize(style, size); Tango_ClearSlot(slot); Tango_SetSlotStyle(slot, style); Tango_SetSlotPosition(slot, x, y); } //Quick way to drop a string into a Tango dialogue box. void ShowString(int string, int slot, int style, int x, int y) { SetUpWindow(slot, style, x, y, SIZE_LARGE); Tango_LoadString(slot, string); Tango_ActivateSlot(slot); while(Tango_SlotIsActive(slot)) Waitframe(); } //The ffc that makes the screen dark. ffc script ShopDarknessFFC{ void run(){ while(true){ if ( IsShopAllSoldOut() && 1 ) ShopSoldOut(); //Draw dark layer if setting enabled. Waitframe(); } } } //The main shop ffc. ffc script ShopItemMenu{ void run(int itm, int price, int msg, int itemcombo, int sound, int holdup_type, int only_once, int itemnumber_in_shop){ int msg_str = msg << 0; //Message string is integer of D2. int counter = ( msg - ( msg << 0 )) *10000; //Alt counte ris decimal of D2. if ( counter == 0 ) counter = 1; //Allow an alternate counter. item it = Screen->CreateItem(only_once << 0); it->DrawXOffset = -300; it->HitXOffset = -300; it->DrawYOffset = -300; it->HitYOffset = -300; if ( only_once == 1 || only_once < 0 ) { if ( FFC_ShopFlag(000000001b) && itemnumber_in_shop == 1 ) this->Data = 22913; else if ( FFC_ShopFlag(000000010b) && itemnumber_in_shop == 2 ) this->Data = 22913; else if ( FFC_ShopFlag(000000100b) && itemnumber_in_shop == 3 ) this->Data = 22913; else if ( FFC_ShopFlag(000001000b) && itemnumber_in_shop == 4 ) this->Data = 22913; else if ( FFC_ShopFlag(000010000b) && itemnumber_in_shop == 5 ) this->Data = 22913; else if ( FFC_ShopFlag(000100000b) && itemnumber_in_shop == 6 ) this->Data = 22913; else if ( FFC_ShopFlag(100000000b) && itemnumber_in_shop == 7 ) this->Data = 22913; else if ( FFC_ShopFlag(010000000b) && itemnumber_in_shop == 8 ) this->Data = 22913; else if ( FFC_ShopFlag(000000100b) && itemnumber_in_shop == 9 ) this->Data = 22913; } if ( itemcombo ) this->Data = itemcombo; //If we have a specific combo ID set, use it. if ( ( ( only_once << 0 ) > 1 ) ) { //We have a replacement item when this one sells, so don't put up a sold out sign. if ( FFC_ShopFlag(000000001b) && itemnumber_in_shop == 1 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(000000010b) && itemnumber_in_shop == 2 ) { itm = ( only_once << 0 ); this->Data = 1000; } //We could offer drawtile for this. else if ( FFC_ShopFlag(000000100b) && itemnumber_in_shop == 3 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(000001000b) && itemnumber_in_shop == 4 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(000010000b) && itemnumber_in_shop == 5 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(000100000b) && itemnumber_in_shop == 6 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(100000000b) && itemnumber_in_shop == 7 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(010000000b) && itemnumber_in_shop == 8 ) { itm = ( only_once << 0 ); this->Data = 1000; } else if ( FFC_ShopFlag(000000100b) && itemnumber_in_shop == 9 ) { itm = ( only_once << 0 ); this->Data = 1000; } Screen->DrawTile(1, this->X, this->Y, it->Tile, 1, 1, it->CSet, -1, -1, 0, 0, 0, 0, true, OP_OPAQUE); //Make the combo of the ffc invisible, then... //Draw a tile so that it's easier to customise what the user sees. if ( ( only_once - ( only_once << 0 )) *10000 > 0 ) price = ( only_once - ( only_once << 0 )) *10000; //Set an alternate price using the decimal portion of D6. } int str_price[6]; int free[]="Free"; if ( !1 || price != 0 ) itoa(str_price,price); //Store the price in a string to display it. else itoa(str_price,free); //Show 'Free' instead of a numeral '0'. int choice; bool pressed; bool dotile; //true if we use a tile, not a combo //Replce the item if needed. if ( ( this->Data == 22913 || 9182) && !1 ) { this->Script = 0; Quit(); } //Clear the ffc if the item is sold, to prevent count of running shops from reading it. if ( ( this->Data == 22913 || 9182) && 1 ) { this->Script = FFC_GetShopDarkness(); Quit(); } //If shops should be dark, change the script. FFC_SetNumberShopItems(); //Store how many shops are running. while(true){ if ( ( this->Data == 22913 || 9182) && !1 ){ this->Script = 0; Quit(); } if ( ( this->Data == 22913 || 9182) && 1 ) { this->Script = FFC_GetShopDarkness(); Quit(); } //If shops should be dark, change the script. if ( 0 && IsShopAllSoldOut() ) this->Data = 9182; //Draw the shop prices and icons: //If a tile is set for a rupee icon... if ( ( 5170 && !1 ) || ( 5170 && 1 && price != 0 ) ) { Screen->DrawTile( 2, this->X + 4, this->Y + 15, 5170, 0, 0, 0, 50, 50, 0, 0, 0, 0, true, 128); } //If the setting to draw an 'x' between the rupee icon and the price is enabled... if ( ( 1 && !1 ) || ( 1 && 1 && price != 0 ) ) FFC_DrawShopPrice_X_Sign(this); //Draw the 'x' //Draw the actual price. if ( ( ( !0 && price !=0 ) || 0 && price > -1 ) && ( ( !0 && price > -1 ) || 0 ) ) //Draw the background. Screen->DrawString( 2, this->X+13, this->Y+14, 2, 0x01, 0, 0, str_price, 128); //Background //Draw the foreground. Screen->DrawString( 2, this->X+12, this->Y+13, 2, 0x01, 0, 0, str_price, 128); //Foreground if ( __DistX(this,25,true) && __DistY(this,25,true) && ( __LinkFacing(this) || !1 ) ) { //Draw the button tile overlay. if ( 44162 ) Screen->DrawTile( 2, this->X + 9, this->Y + - 8, 44162, 1, 1, 2, -1, -1, 0, 0, 0, 0, true, 128); //Check for input based on the button settings... if ( 1 && Link->PressR ) { pressed = true; Link->PressR = false; Link->InputR = false; } if ( 0 && Link->PressL ) { pressed = true; Link->PressL = false; Link->InputL = false; } if ( 0 && Link->PressA ) { pressed = true; Link->PressA = false; Link->InputA = false; } if ( 1 && Link->PressB ) { pressed = true; Link->PressB = false; Link->InputB = false; } if ( 0 && Link->PressEx1 ) { pressed = true; Link->PressEx1 = false; Link->InputEx1 = false; } if ( 0 && Link->PressEx2 ) { pressed = true; Link->PressEx2 = false; Link->InputEx2 = false; } if ( 0 && Link->PressEx3 ) { pressed = true; Link->PressEx3 = false; Link->InputEx3 = false; } if ( 0 && Link->PressEx4 ) { pressed = true; Link->PressEx4 = false; Link->InputEx4 = false; } if ( pressed ) { //If Link pressed a button that we want to use... pressed = false; //Clear pressed. if ( !0 || ( 0 && price != 0) ) choice = BuyYesNo(msg_str,price); if ( choice == 2 || ( 0 && price == 0 ) ) { //Bought it. if ( Game->Counter[counter] >= price ) { //Bought and can buy it... Game->DCounter[counter] -= price; if ( sound ) Game->PlaySound(sound); item it = Screen->CreateItem(itm); it->X = Link->X; it->Y = Link->Y; it->Z = Link->Z; if ( holdup_type ) { Link->Action = holdup_type + 3; Link->HeldItem = itm; } if ( only_once ) { //Set the flags. if ( itemnumber_in_shop == 1 ) FFC_SetShopFlag(000000001b, true); if ( itemnumber_in_shop == 2 ) FFC_SetShopFlag(000000010b, true); if ( itemnumber_in_shop == 3 ) FFC_SetShopFlag(000000100b, true); if ( itemnumber_in_shop == 4 ) FFC_SetShopFlag(000001000b, true); if ( itemnumber_in_shop == 5 ) FFC_SetShopFlag(000010000b, true); if ( itemnumber_in_shop == 6 ) FFC_SetShopFlag(000100000b, true); if ( itemnumber_in_shop == 7 ) FFC_SetShopFlag(001000000b, true); if ( itemnumber_in_shop == 8 ) FFC_SetShopFlag(010000000b, true); if ( itemnumber_in_shop == 9 ) FFC_SetShopFlag(100000000b, true); //If only_once and no alternate item if ( ( only_once << 0) < 0 || ( only_once << 0 ) == 1 ) this->Data = 22913; else { //! Replace with the new item itm = ( only_once << 0 ); //Make this ffc combo invisible, then... Screen->DrawTile(1, this->X, this->Y, it->Tile, 1, 1, it->CSet, -1, -1, 0, 0, 0, 0, true, OP_OPAQUE); //Draw a tile so that it's easier to customise what the user sees. if ( ( only_once - ( only_once << 0 )) *10000 > 0 ) price = ( only_once - ( only_once << 0 )) *10000; //Set an alternate price using the decimal portion of D6. } } } else { //Errors if ( 9 ) Game->PlaySound(9); if ( 10 ) Screen->Message(10); } } else choice = 0; //Clear the choice selection. } } Waitframe(); } } //The following three functions are from my std.zh update, with leading underscores added in the event that you upgrade, to prevent conflicts. bool __DistX(ffc a, int distance, bool fromcentre) { int dist; if ( a->X > Link->X ) dist = a->X - Link->X; else dist = Link->X - a->X; return ( dist <= distance ); } //Link to ffc distance bool __DistY(ffc a, int distance, bool fromcentre) { int dist; if ( a->Y > Link->Y ) dist = a->Y - Link->Y; else dist = Link->Y - a->Y; return ( dist <= distance ); } bool __LinkFacing(ffc f){ if ( Link->Dir == DIR_UP && Link->Y < f->Y ) return true; if ( Link->Dir == DIR_DOWN && Link->Y > f->Y ) return true; if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true; if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true; return false; } } //Global Functions //Check a shop item sold-out flag. bool FFC_ShopFlag(int flag){ return ( ( Screen->D[6]<<0 )&flag ) != 0; } //Set a shop item sold-out flag. void FFC_SetShopFlag(int flag, bool state){ int val[3]; val[0]= Screen->D[6]; val[1]= val[0] << 0; //Integer side val[2] = val[0] - val[1]; //Decimal side. if ( state ) val[1] |= flag; else val[1] &= ~flag; Screen->D[6] = val[1]+val[2]; //Preserve the decimal, and replace the integer. } //Returns how many shop item ffcs are running. int FFC_NumShopItems(){ ffc f; int count; int ff[]="ShopItemMenu"; int ffid = Game->GetFFCScript(ff); for ( int q = 1; q < 32; q++ ){ f = Screen->LoadFFC(q); if ( f->Script == ffid ) count++; } return count; } //Stores the number of items in the screen register. void FFC_SetNumberShopItems(){ int val[6]; val[0]= Screen->D[6]; val[1]= val[0] << 0; //Integer side val[2] = val[0] - val[1]; //Decimal side. val[3] = val[2] * 10000; //Decimal to Int val[4] = FFC_NumShopItems(); //Read how many shops are running. val[5] = val[4] / 10000; //Turn it into a decimal. Screen->D[6] = val[1]+val[5]; //Preserve the integer, and replace the decimal. } //Returns te stored value of the number of running shop items. int FFC_GetNumberShopItems(){ int val[3]; val[0]= Screen->D[6]; val[1]= val[0] << 0; //Integer side val[2] = val[0] - val[1]; //Decimal side. return val[2]; } //Check if all items are sold out. Works only if there ALL items sold out. bool IsShopAllSoldOut(){ int shopsold[]={0,1,2,4,8,16,32,64,128,256}; int count; for ( int q = 0; q <= FFC_GetNumberShopItems(); q++ ) { count += shopsold[q]; } return ( Screen->D[6] >= count ); } //Draws darkness effect if the shop is sold out, and the setting is enabled. int FFC_GetShopDarkness(){ int ff[]="ShopDarknessFFC"; return Game->GetFFCScript(ff); } //Draws the darkness layer. void ShopSoldOut(){ for ( int q = 0; q < 3; q++ ) Screen->Rectangle(6, 0, 0, 255, 175, 0x0F, 100, 0, 0, 0, true, 64); } //Draw the 'x' between the rupee icon and the price. void FFC_DrawShopPrice_X_Sign(ffc f){ int x[]="x"; Screen->DrawString(2, f->X+13, f->Y+14, 1, 0x01, 0, 0, x, 128); //Background Screen->DrawString(2, f->X+8, f->Y+9, 1, 0x0F, 0, 0, x, 128); //Background } //The 'yes/no' menu called by the ffc. int BuyYesNo(int msg, int price) { int lineBreak[]="@26"; int line1[]="@choice(1)Item Info@26"; int line2[]="@choice(2)Buy@26@choice(3)Cancel@domenu(1)@suspend()"; int free[]="@choice(2)Take@26@choice(3)Cancel@domenu(1)@suspend()"; SetUpWindow(0, 2, 32, 32, SIZE_LARGE); Tango_LoadString(0, line1); if ( price == 0 ) Tango_AppendString(0, free); else Tango_AppendString(0, line2); Tango_ActivateSlot(0); while(!Tango_MenuIsActive()){ Waitframe(); } // Save the state again... int slotState[278]; int menuState[960]; int cursorPos; Tango_SaveSlotState(0, slotState); Tango_SaveMenuState(menuState); int done = 0; int choice; while(true){ while( Tango_MenuIsActive() ) { cursorPos=Tango_GetMenuCursorPosition(); Waitframe(); } choice = Tango_GetLastMenuChoice(); if ( choice == 1 ) { // Item Info int text[256]; Game->GetMessage(msg,text); //Load msg into the buffer. ShowString(text, 1, 2, 48, 48); } else if ( choice == 2 ) { //Buy done = choice; menuArg = choice; } else if ( choice == 3 ) { //Cancel done = choice; } else if ( Link->PressEx1 ) { done = 1; } else done = 3; if ( done ) { break; // return choice; } else { Tango_RestoreSlotState(0, slotState); Tango_RestoreMenuState(menuState); Tango_SetMenuCursorPosition(cursorPos); } } Tango_ClearSlot(0); return done; } //Global Scripts //Mandatory init script: If you already have an init script, merge them. global script Init { void run(){ SetCommonStyleData(0); SetCommonStyleData(1); SetCommonStyleData(2); } } //Example global active (slot 2) script. global script Tango{ void run(){ Tango_Start(); StartGhostZH(); while(true) { UpdateGhostZH1(); Tango_Update1(); Waitdraw(); UpdateGhostZH2(); Tango_Update2(); Waitframe(); } } }