Thread: Simple ItemOnItem handler.

Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1 Simple ItemOnItem handler. 
    Registered Member Own4g3's Avatar
    Join Date
    Mar 2011
    Age
    29
    Posts
    359
    Thanks given
    97
    Thanks received
    133
    Rep Power
    38
    This is used for combining 2 items into 1.

    Example: Ely sigial + blessed shield = Ely shield.

    Create a new class in content folder and name it "ItemOnItemHandler.java"

    Code:
    package com.rs.game.player.content;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import com.rs.game.player.Player;
    import com.rs.game.player.Skills;
    
    /**
     * Handles item on item.
     * 
     * @author Raghav
     *
     */
    public class ItemOnItemHandler {
    
    	/**
    	 * An enum containing all the data.
    	 * 
    	 * @author Raghav
    	 *
    	 */
    	public enum ItemOnItem {
    
    		ELYSIAN_SPIRIT_SHIELD(13750, 13736, 13742, Skills.PRAYER, 90, 10, Skills.SMITHING, 85, 10);
    
    		/**
    		 * A hasmap to store all the data.
    		 */
    		private static Map<Integer, ItemOnItem> itemOnItems = new HashMap<Integer, ItemOnItem>();
    
    		/**
    		 * Gets the data from mapping.
    		 * @param itemId The item used id.
    		 * @return The {@code ItemOnItem} {@code Object}, or {@code Null} if the data is nonexistent.
    		 */
    		public static ItemOnItem forId(int itemId) {
    			return itemOnItems.get(itemId);
    		}
    
    		/**
    		 * Populating the map.
    		 */
    		static {
    			for (ItemOnItem itemOnItem : ItemOnItem.values()) {
    				itemOnItems.put(itemOnItem.getItem1(), itemOnItem);
    			}
    		}
    
    		/**
    		 * The item to be used on item2.
    		 */
    		private final int item1;
    
    		/**
    		 * The item to be used on item1.
    		 */
    		private final int item2;
    
    		/**
    		 * The new item which player is going to make by combining item1 and item2.
    		 */
    		private final int item3;
    
    		/**
    		 * If player can make this item.
    		 */
    		private final int[] skillRequirement;
    
    		/**
    		 * Constructs a new {@code ItemOnItem} {@code Object}.
    		 * 
    		 * @param item1 The item to be used on item2.
    		 * @param item2 The item to be used on item1.
    		 * @param item3 The new item which player is going to make by combining item1 and item2.
    		 * @param skillRequirement Skill Id, Required level, Exp in that skill.
    		 */
    		ItemOnItem(int item1, int item2, int item3, int...skillRequirement) {
    			this.item1 = item1;
    			this.item2 = item2;
    			this.item3 = item3;
    			this.skillRequirement = skillRequirement;
    		}
    
    		/**
    		 * Gets the first item.
    		 * @return item1
    		 */
    		public int getItem1() {
    			return item1;
    		}
    
    		/**
    		 * Gets the 2nd item.
    		 * @return item2
    		 */
    		public int getItem2() {
    			return item2;
    		}
    
    		/**
    		 * Gets the 3rd item.
    		 * @return item3
    		 */
    		public int getItem3() {
    			return item3;
    		}
    
    		/**
    		 * Gets skill requirments..
    		 * @return skillRequirement
    		 */
    		public int[] getSkillRequirement() {
    			return skillRequirement;
    		}
    	}
    
    	/**
    	 * Handles the item on item action.
    	 * 
    	 * @param player The player.
    	 * @param itemOnItem The itemOnItem.
    	 * @param usedWith The item used.
    	 * @param itemUsed The item used.
    	 */
    	public static void handleItemOnItem(Player player, ItemOnItem itemOnItem, int usedWith, int itemUsed) {
    		int[] skillStuff = itemOnItem.getSkillRequirement();
    		if (player.getSkills().getLevel(skillStuff[0]) >= skillStuff[1]) {
    			if (player.getSkills().getLevel(skillStuff[3]) >= skillStuff[4]) {
    				player.getInventory().deleteItem(usedWith, 1);
    				player.getInventory().deleteItem(itemUsed, 1);
    				player.getInventory().addItem(itemOnItem.getItem3(), 1);
    				player.getSkills().addXp(skillStuff[0], skillStuff[2]);
    			} else 
    				player.getPackets().sendGameMessage("You need a " + Skills.SKILL_NAME[skillStuff[3]] + " level of " + Skills.SKILL_NAME[skillStuff[4]] + " to make this.");
    		} else
    			player.getPackets().sendGameMessage("You need a " + Skills.SKILL_NAME[skillStuff[0]] + " level of " + skillStuff[1] + " to make this.");
    	}
    
    }
    Now, implement it.

    InventoryOptionsHandler.java

    Code:
    				ItemOnItem itemOnItem = ItemOnItem.forId(itemUsedId);
    				if (itemOnItem != null) {
    					if (itemUsedWithId == itemOnItem.getItem2())
    						ItemOnItemHandler.handleItemOnItem(player, itemOnItem, usedWith.getId(), itemUsed.getId());
    					return;
    				}
    Add it under "handleItemOnItem" method.

    And that's it.
    You're done.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jan 2010
    Posts
    696
    Thanks given
    109
    Thanks received
    29
    Rep Power
    3
    One question, where the hell put new items? when i trying to add divine i got errors.
    Reply With Quote  
     

  3. #3  
    Registered Member wildking72's Avatar
    Join Date
    Sep 2011
    Age
    27
    Posts
    506
    Thanks given
    62
    Thanks received
    36
    Rep Power
    11
    It's shorter than the other one.
    Reply With Quote  
     

  4. #4  
    Registered Member Own4g3's Avatar
    Join Date
    Mar 2011
    Age
    29
    Posts
    359
    Thanks given
    97
    Thanks received
    133
    Rep Power
    38
    Quote Originally Posted by Tomasmu View Post
    One question, where the hell put new items? when i trying to add divine i got errors.
    In the Enum??
    Reply With Quote  
     

  5. #5  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Dont put it in the Enum.
    When you put it in the Enum, it only lets you put one.
    I know this because I tried this myself, but failed miserably.
    Miserably.
    Reply With Quote  
     

  6. #6  
    Registered Member Own4g3's Avatar
    Join Date
    Mar 2011
    Age
    29
    Posts
    359
    Thanks given
    97
    Thanks received
    133
    Rep Power
    38
    Quote Originally Posted by nbness View Post
    Dont put it in the Enum.
    When you put it in the Enum, it only lets you put one.
    I know this because I tried this myself, but failed miserably.
    Miserably.
    No, lol.

    Remove the " ; " and put " , "
    Reply With Quote  
     

  7. #7  
    Registered Member Emperium's Avatar
    Join Date
    Mar 2012
    Posts
    104
    Thanks given
    4
    Thanks received
    10
    Rep Power
    13
    at the some of the people trying to do this rofl. This is a very simple thing to do and really didn't need any new defined statements in InventoryOptionHandler... Simply use the imports the herblore class uses... But thank you for the help for the ones that do not understand a single thing when it comes to Java.
    legitimate buys so much stuff off of me then states that I'm a new fag ROFL.

    http://www.rune-server.org/members/legitimate/



    Yeah, "newfag" my ass cunt.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Jul 2008
    Posts
    430
    Thanks given
    6
    Thanks received
    29
    Rep Power
    12
    Quote Originally Posted by Emperium View Post
    at the some of the people trying to do this rofl. This is a very simple thing to do and really didn't need any new defined statements in InventoryOptionHandler... Simply use the imports the herblore class uses... But thank you for the help for the ones that do not understand a single thing when it comes to JavaScript
    At least he knows what programming language were using

    Oh just to bash on you more, you should change your signature while your at it.
    People acting like they know what they are talking about...
    Quote Originally Posted by Emperium View Post
    at the some of the people trying to do this rofl. This is a very simple thing to do and really didn't need any new defined statements in InventoryOptionHandler... Simply use the imports the herblore class uses... But thank you for the help for the ones that do not understand a single thing when it comes to JavaScript
    Reply With Quote  
     

  9. #9  
    Registered Member Emperium's Avatar
    Join Date
    Mar 2012
    Posts
    104
    Thanks given
    4
    Thanks received
    10
    Rep Power
    13
    Quote Originally Posted by solcrystal View Post
    At least he knows what programming language were using

    Oh just to bash on you more, you should change your signature while your at it.
    You're an idiot. Simple as that. You have not said 1 thing that even implies the word 'bashing' as what you have just stated, makes you look like a true arrogant douchebag. And it's sad we have you kids coming to these forums once again. "At least he knows what programming language were using"?

    1. We're
    2. You're
    3. Java, Java, Java, and Java. You come to a snippet for what reason? Oh to rip what others have created???? That's a true meaning of a leecher. Not someone that downloads something as a base. Again, arrogant and douchebag.



    Cunt

    Once said Javascript = Implying the basics of statements. IE Base of Java programming.
    legitimate buys so much stuff off of me then states that I'm a new fag ROFL.

    http://www.rune-server.org/members/legitimate/



    Yeah, "newfag" my ass cunt.
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Jul 2008
    Posts
    430
    Thanks given
    6
    Thanks received
    29
    Rep Power
    12
    Quote Originally Posted by Emperium View Post
    You're an idiot. Simple as that. You have not said 1 thing that even implies the word 'bashing' as what you have just stated, makes you look like a true arrogant douchebag. And it's sad we have you kids coming to these forums once again. "At least he knows what programming language were using"?

    1. We're
    2. You're
    3. Java, JavaScript, Java, Java, and Java. You come to a snippet for what reason? Oh to rip what others have created???? That's a true meaning of a leecher. Not someone that downloads something as a base. Again, arrogant and douchebag.



    Cunt

    Once said Javascript = Implying the basics of statements. IE Base of Java programming.
    Are you serious? You think javascript was based on java? Please go back to the DOCS and learn how java and java script started. FYI, javascript was NEVER based on Java.

    Do that before you spread idiotic knowledge to more people.
    People acting like they know what they are talking about...
    Quote Originally Posted by Emperium View Post
    at the some of the people trying to do this rofl. This is a very simple thing to do and really didn't need any new defined statements in InventoryOptionHandler... Simply use the imports the herblore class uses... But thank you for the help for the ones that do not understand a single thing when it comes to JavaScript
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. 614 Ban Handler (simple)
    By xJames in forum Snippets
    Replies: 13
    Last Post: 12-19-2010, 11:58 PM
  2. Itemonitem
    By Press Conference in forum Help
    Replies: 16
    Last Post: 10-06-2009, 11:10 PM
  3. ItemOnItem handler
    By Laxika in forum Tutorials
    Replies: 21
    Last Post: 10-11-2008, 11:17 PM
  4. A simple "Command Handler"
    By samuraiblood2 in forum Tutorials
    Replies: 7
    Last Post: 11-24-2007, 11:15 AM
  5. Sweet and simple way to make a handler
    By Harvey in forum Tutorials
    Replies: 24
    Last Post: 10-05-2007, 05:38 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •