User Tag List

Results 1 to 4 of 4

Thread: Empty Bottle Script

  1. #1
    Gel Floundermaj's Avatar
    Join Date
    Aug 2013
    Location
    Connecticut
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    506
    Level
    8
    vBActivity - Bars
    Lv. Percent
    8.46%

    Cool Empty Bottle Script

    I was looking for a script to implement bottles, but I couldn't find one, so I made one.

    These scripts implements 4 bottles and 4 different types of potions. Setting them up is quite involved, and requires 20 custom items and 4 custom item classes. Rather than writing a prolonged explanation I'll just post the code, and if you can't figure it out ask me. I have tested this and it works on the quest I am building. Note that the item numbers in the script apply to my custom quest, and they'll be different for you, as will sound effect and string numbers. I'm still new to scripting, so feel free to improve on them in any way, but please give me credit if you use this.

    Code:
    //Bottle Scripts
    //by FlounderMAJ
    
    //This is a script for empty bottles!
    //D0 is the item number for the pickup potion/bottle item, D1, D2, D3 and D4 are 
    //the item numbers for each potion or other bottle item.
    //The four Bottle variables in the script are the item numbers of your bottles.
    //These will always be the same for your quest.
    //D5 is a pickup string, and D6 is a String stating there are no empty bottles.
    //D7 is the amount of Rupees to return to Link if there is no empty bottle available.
    //For this script to work, Each bottle must be a separate item in a separate custom item class,
    //and EACH potion type will have an item for EACH bottle, in the custom item class mathing the respective bottle.
    //For 4 Bottles and 4 types of potions/bottle items, this requires 20 custom items in 4 custom item classes.
    //This script should be slotted as a pickup script for the built-in potion type items.
    
    
    //Use this table to organize the D0-D7 needed to set up each item.
    //+------------+--------+------------+-------------+--------------+---------------+----------+
    //| Item class | Bottle | Red Potion | Blue Potion | Green Potion | Purple Potion | Variable |
    //+------------+--------+------------+-------------+--------------+---------------+----------+
    //| Potions (for pickup)|     29     |     30      |     125      |    126        |   D0     |
    //| Custom 1   |  127   |    129     |    135      |     139      |     63        |   D1     |
    //| Custom 2   |  128   |    130     |    136      |     140      |     55        |   D2     |
    //| Custom 3   |  131   |    133     |    137      |     141      |    121        |   D3     | 
    //| Custom 4   |  132   |    134     |    138      |      50      |    120        |   D4     |
    //|   Pickup String     |     10     |     11      |      12      |     13        |   D5     |
    //|  No Bottle String   |     14     |     14      |      14      |     14        |   D6     |
    //|  Rupees to return   |     40     |    160      |      40      |     60        |   D7     |
    //+---------------------+------------+-------------+--------------+---------------+----------+
    
    item script emptybottle
    {
    	void run(int pickup, int potion1, int potion2, int potion3, int potion4, int string1, int string2, int rupees)
    	{
    		int bottle1=127;
    		int bottle2=128;
    		int bottle3=131;
    		int bottle4=132;
    
    		Link->Item[pickup]=false;
    
    		if (Link->Item[bottle1])
    		{
    			
    			Link->Item[potion1]=true;
    			Link->Item[bottle1]=false;
    			Screen->Message(string1);
    		}
    		else if (Link->Item[bottle2])
    		{
    			Link->Item[potion2]=true;
    			Link->Item[bottle2]=false;
    			Screen->Message(string1);
    		}
    		else if (Link->Item[bottle3])
    		{
    			Link->Item[potion3]=true;
    			Link->Item[bottle3]=false;
    			Screen->Message(string1);
    		}
    		else if (Link->Item[bottle4])
    		{
    			Link->Item[potion4]=true;
    			Link->Item[bottle4]=false;
    			Screen->Message(string1);
    		}
    		else
    		{
    			Game->Counter[1]=(Game->Counter[1]+rupees);
    			Game->PlaySound(69);
    			Screen->Message(string2);
    			
    		}	
    			
    	}
    }
    
    
    
    
    //This Script is for the bottle potions.
    //D0 is the item number of the potion you are using, D1-D4 are the items corresponding to the 4 potion types.
    //D5 is the corresponding empty bottle for that potion set, and D6 is a string that is displayed when 
    //Link tries to use an empty bottle.  D7 is a sound effect to play.
    //The item numbers should be listed in the table above.
    //This script should be slotted as the action script for each bottle item, including the empty bottle.
    
    
    item script potions
    {
    	void run(int PotionUsed, int Red, int Blue, int Green, int Purple, int Bottle, int String, int sfx)
    	{
    		Link->Item[29]=false;    //These lines remove any pickup potions Link has, 
    		Link->Item[30]=false;    //see table above and change item numbers to match
    		Link->Item[125]=false;
    		Link->Item[126]=false;
    
    		Link->Item[Bottle]=true;
    		Game->PlaySound(sfx);		
    
    		if (PotionUsed==Red)
    		{
    			Link->HP=Link->MaxHP;
    			Link->Item[PotionUsed]=false;			
    		}
    
    		if (PotionUsed==Blue)
    		{
    			Link->HP=Link->MaxHP;
    			Link->MP=Link->MaxMP;
    			Link->Item[PotionUsed]=false;		
    		}
    
    		if (PotionUsed==Green)
    		{
    			Link->MP=Link->MaxMP;
    			Link->Item[PotionUsed]=false;		
    		}
    
    		if (PotionUsed==Purple)
    		{
    			if (Link->MaxHP<129)
    			{
    				Link->HP=Link->MaxHP;
    				Link->Item[PotionUsed]=false;			
    			}
    
    			else
    			{
    				Link->HP=Link->HP+128;
    				Link->Item[PotionUsed]=false;		
    			}
    		}
    		
    		if (PotionUsed==Bottle)
    		{
    			Screen->Message(String);
    		}
    	}
    		
    }
    
    //This Global script is designed to work with the purple potion, and to automatically restore 4 hearts of health to Link 
    //if his health drops to 0.  May be used to implement bottle fairies also.  the Item numbers used should match the table 
    //above, and the sound effect and amount of health restored can be adjusted as well. Paste the contents of the while(true)
    //loop into your own loop on your own custom global script if you want to.  Remember to copy the variable declarations also. 
    
    global script BottlesGlobal
    {
    
    
    	void run()
    	{
    		int purple1=63;
    		int purple2=55;
    		int purple3=121;
    		int purple4=120;
    		
    		int bottle1=127;
    		int bottle2=128;
    		int bottle3=131;
    		int bottle4=132;
    		
    		int sfx=25;
    		int RestoreAmt=64;
    		
    		while (true)
    		{
    			if (Link->HP==0)
    			{
    				if (Link->Item[purple1])
    				{
    					Link->Item[bottle1]=true;
    					Link->Item[purple1]=false;
    					Game->PlaySound(sfx);
    					if (Link->MaxHP<(RestoreAmt-1))
    					{
    						Link->HP=Link->MaxHP;
    					}
    
    					else
    					{
    						Link->HP=Link->HP+RestoreAmt;
    					}
    				}
    
    				else if (Link->Item[purple2])
    				{
    					Link->Item[bottle2]=true;
    					Link->Item[purple2]=false;
    					Game->PlaySound(sfx);
    					if (Link->MaxHP<(RestoreAmt-1))
    					{
    						Link->HP=Link->MaxHP;
    					}
    
    					else
    					{
    						Link->HP=Link->HP+RestoreAmt;
    					}
    				}	
    			
    				else if (Link->Item[purple3])
    				{
    					Link->Item[bottle3]=true;
    					Link->Item[purple3]=false;
    					Game->PlaySound(sfx);
    					if (Link->MaxHP<(RestoreAmt-1))
    					{
    						Link->HP=Link->MaxHP;
    					}
    
    					else
    					{
    						Link->HP=Link->HP+RestoreAmt;
    					}
    				}
    				else if (Link->Item[purple4])
    				{
    					Link->Item[bottle4]=true;
    					Link->Item[purple4]=false;
    					Game->PlaySound(sfx);
    					if (Link->MaxHP<(RestoreAmt-1))
    					{
    						Link->HP=Link->MaxHP;
    					}
    
    					else
    					{
    						Link->HP=Link->HP+RestoreAmt;
    					}
    				}									
    			}	
    
    			Waitframe();
    		}
    	}
    }
    Once this is implemented, you can add each of the custom item classes to your subscreen, and you have 4 independent bottles, each one can have different contents, and be used individually. The bottles can be used over and over. And since you are slotting the script into the built-in potion items, you can still use the Letter item to activate the shop. Let me know what you think, and please feel free to ask if you need help setting the items up.

    Happy Questing,

    FlounderMAJ

  2. #2
    Admiral Zim's Avatar
    Join Date
    Oct 2012
    Posts
    388
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    vBActivity - Stats
    Points
    1,721
    Level
    13
    vBActivity - Bars
    Lv. Percent
    90.77%
    Well written and great explanations. Kudos. I don't see anything wrong with the way this is written whatsoever.

    Edit: "Game->Counter[1]=(Game->Counter[1]+rupees);" could be re-written as "Game->Counter[1]+=rupees;" and is the same syntactically.
    Last edited by Zim; 12-24-2013 at 07:45 PM.

  3. #3
    Aerstalfos En Passant's Avatar
    Join Date
    May 2014
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    412
    Level
    7
    vBActivity - Bars
    Lv. Percent
    35.56%
    The use of all four Potion Item IDs in the potion script is redundant when the script is slotted into each potion individually. Here's what I recommend changing it to:
    CODE: Show
    //This Script is for the bottle potions.//D0 is the type of potion, with 0 being empty, 1 being Red, 2 being Blue, 3 being Green, and 4 being Purple.
    //D1 is the Item ID of the potion.
    //D2 is the Item ID corresponding empty bottle for that potion set.
    //D3 is an optional string ID to display once the item is used.
    //D4 is a sound effect ID to play.
    //The item numbers should be listed in the table above.
    //This script should be slotted as the action script for each bottle item, but not


    item script potions{
    void run(int PotionUsed, int PotionID, int Bottle, int String, int sfx){
    Link->Item[125]=false; //These lines remove any pickup potions Link has,
    Link->Item[126]=false; //see table above and change item numbers to match
    Link->Item[127]=false;
    Link->Item[128]=false;


    Link->Item[Bottle]=true;
    Game->PlaySound(sfx);


    if (PotionUsed==1){ //Red Potion
    Link->HP=Link->MaxHP;
    Link->Item[PotionID]=false;
    }


    if (PotionUsed==2){ //Blue Potion
    Link->HP=Link->MaxHP;
    Link->MP=Link->MaxMP;
    Link->Item[PotionID]=false;
    }


    if (PotionUsed==3){ //Green Potion
    Link->MP=Link->MaxMP;
    Link->Item[PotionID]=false;
    }


    if (PotionUsed==4){ //Purple Potion
    if (Link->MaxHP<129){
    Link->HP=Link->MaxHP;
    Link->Item[PotionID]=false;
    } else {
    Link->HP=Link->HP+128;
    Link->Item[PotionID]=false;
    }
    }
    Screen->Message(String);
    }
    }

    I have also moved the String message out so that any potion has the option of having a string displayed.

  4. #4
    Gel Floundermaj's Avatar
    Join Date
    Aug 2013
    Location
    Connecticut
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    506
    Level
    8
    vBActivity - Bars
    Lv. Percent
    8.46%
    Quote Originally Posted by Dry Paratroopa View Post
    The use of all four Potion Item IDs in the potion script is redundant when the script is slotted into each potion individually.
    Oh yeah I realized that it was Redundant ages ago. It works in any case. The idea of leaving an option for a string for every potion is a good one, Thanks! Have you found it easy to set up and work with otherwise? Is it working well?

    Edit: I did recently find a bug related to attempting to buy a potion without an empty bottle and when your wallet is full. As written, the rupees are not properly returned to Link due to the wallet being full. What happens is the script gives the rupees immediately, before they drain in the normal fashion. To fix this, I added a line to temporarily increase the wallet cap by the amount of the rupees being returned. Then, on the screen just outside the shop, I drop in a simple ffc script that resets the wallet cap to where it should be. It works well on my quest, and so far I haven't had an instance where the wallet has more rupees than the wallet capacity.
    Last edited by Floundermaj; 08-26-2014 at 10:59 AM. Reason: bug report
    The Legend of Zelda: The River of Destiny

    Coming Soon! Play the Demo!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social