Thread: Enum Issue [ Resolved]

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 Enum Issue [ Resolved] 
    Registered Member
    Edimmu's Avatar
    Join Date
    Jun 2012
    Age
    30
    Posts
    1,098
    Thanks given
    37
    Thanks received
    119
    Rep Power
    98
    Been a while since I worked with enums and just need some slight help with it.

    Code:
    package com.rs.game.player.actions.skills.crafting;
    
    import com.rs.cache.loaders.ItemDefinitions;
    import com.rs.game.player.Player;
    import com.rs.utils.Utils;
    
    public class Tanning {
    	
    	public enum hides {
    		
    		COW(1739, 1741, 10),
    		GREEN(1753, 1745, 30),
    		BLUE(1751, 2505, 30),
    		RED(1749, 2507, 30),
    		BLACK(1747, 2509, 30),
    		ROYAL(24372, 24374, 30);
    		
    		public int hide, leather, cost;
    		
    		hides(int hide, int leather, int cost) {
    			this.hide = hide;
    			this.leather = leather;
    			this.cost = cost;
    		}
    		
    		public int getHide() {
    			return hide;
    		}
    		
    		public int getLeather() {
    			return leather;
    		}
    		
    		public int getCost() {
    			return cost;
    		}
    	}
    	
    	public static void hideChecker(Player player) {
    		for (hides hide : hides.values()) {
    			int i = player.getInventory().getNumerOf(hide.getHide());
    			int pouch = player.money;
    			if (!player.getInventory().contains(hide.getHide())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    			if (pouch < i*hide.getCost() && !player.getInventory().containsItem(995, i*hide.getCost())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have enough money.");
    				return;
    			}
    			if (pouch >= hide.getCost()) {
    				player.money -= i*hide.getCost();
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, i*hide.getCost());
    			}
    			player.getInventory().deleteItem(hide.getHide(), i);
    			player.getInventory().addItem(hide.getLeather(), i);
    			player.sm("Ellis tans x" +i+ " " +ItemDefinitions.getItemDefinitions(hide.getHide()).getName()+ " for you for x"+Utils.format(i*hide.getCost())+" coins.");
    			player.getDialogueManager().finishDialogue();
    			return;
    		}
    	}
    }
    This only works for cow hide and no other leathers for some reason and I'm not too sure why. Any help with be massive appreciated
    Reply With Quote  
     

  2. #2  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    You're doing return wich makes the loop stop. Change it to continue; at the locations when it doesnt complete the tanning

    EDIT: or if you want it to tan all things you got in the inventory you should set all to continue instead of return.
    Reply With Quote  
     

  3. #3  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by Gnakos View Post
    You're doing return wich makes the loop stop. Change it to continue; at the locations when it doesnt complete the tanning

    EDIT: or if you want it to tan all things you got in the inventory you should set all to continue instead of return.
    Then it will spam through all the enum set. He needs to loop through the set first and then report Sorry you don't have any hides for me to tan. if none are found.
    Reply With Quote  
     

  4. #4  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by Stuart View Post
    Then it will spam through all the enum set. He needs to loop through the set first and then report Sorry you don't have any hides for me to tan. if none are found.
    Well I am not sure how he want it to work, but for now he just stops after cow hides all the time.. since he does return..
    Reply With Quote  
     

  5. #5  
    Registered Member
    Edimmu's Avatar
    Join Date
    Jun 2012
    Age
    30
    Posts
    1,098
    Thanks given
    37
    Thanks received
    119
    Rep Power
    98
    Quote Originally Posted by Gnakos View Post
    You're doing return wich makes the loop stop. Change it to continue; at the locations when it doesnt complete the tanning

    EDIT: or if you want it to tan all things you got in the inventory you should set all to continue instead of return.
    Quote Originally Posted by Stuart View Post
    Then it will spam through all the enum set. He needs to loop through the set first and then report Sorry you don't have any hides for me to tan. if none are found.
    Quote Originally Posted by Gnakos View Post
    Well I am not sure how he want it to work, but for now he just stops after cow hides all the time.. since he does return..
    Thanks for the fast reponses guys. I have added the continue to the end of the hideChecker method but as Stu said, this now spams though the enum looking for the other hides and responses with "no hides". It tans correctly now, just a bit still for it to not just stop after it's done the hides in your inventory.

    He's the current method now:
    Code:
    public static void hideChecker(Player player) {
    		for (hides hide : hides.values()) {
    			int i = player.getInventory().getNumerOf(hide.getHide());
    			int pouch = player.money;
    			if (!player.getInventory().containsItem(hide.getHide(), i)) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    			if (pouch < i*hide.getCost() && !player.getInventory().containsItem(995, i*hide.getCost())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have enough money.");
    				return;
    			}
    			if (pouch >= hide.getCost()) {
    				player.money -= i*hide.getCost();
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, i*hide.getCost());
    			}
    			player.getInventory().deleteItem(hide.getHide(), i);
    			player.getInventory().addItem(hide.getLeather(), i);
    			player.sm("Ellis tans x" +i+ " " +ItemDefinitions.getItemDefinitions(hide.getHide()).getName()+ " for you for x"+Utils.format(i*hide.getCost())+" coins.");
    			player.getDialogueManager().finishDialogue();
    			int loop = 0;
    			if (loop < i) {
    				loop++;
    				continue;
    			} else {
    				return;
    			}
    		}
    	}
    EDIT: And for the record, the loop didn't work.
    Reply With Quote  
     

  6. #6  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by Edimmu View Post
    Thanks for the fast reponses guys. I have added the continue to the end of the hideChecker method but as Stu said, this now spams though the enum looking for the other hides and responses with "no hides". It tans correctly now, just a bit still for it to not just stop after it's done the hides in your inventory.

    He's the current method now:
    Code:
    public static void hideChecker(Player player) {
    		for (hides hide : hides.values()) {
    			int i = player.getInventory().getNumerOf(hide.getHide());
    			int pouch = player.money;
    			if (!player.getInventory().containsItem(hide.getHide(), i)) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    			if (pouch < i*hide.getCost() && !player.getInventory().containsItem(995, i*hide.getCost())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have enough money.");
    				return;
    			}
    			if (pouch >= hide.getCost()) {
    				player.money -= i*hide.getCost();
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, i*hide.getCost());
    			}
    			player.getInventory().deleteItem(hide.getHide(), i);
    			player.getInventory().addItem(hide.getLeather(), i);
    			player.sm("Ellis tans x" +i+ " " +ItemDefinitions.getItemDefinitions(hide.getHide()).getName()+ " for you for x"+Utils.format(i*hide.getCost())+" coins.");
    			player.getDialogueManager().finishDialogue();
    			int loop = 0;
    			if (loop < i) {
    				loop++;
    				continue;
    			} else {
    				return;
    			}
    		}
    	}
    EDIT: And for the record, the loop didn't work.
    due to:
    Code:
    if (!player.getInventory().containsItem(hide.getHide(), i)) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    Makes the loop stop if you dont have any hides of that kind... thats what I meant with continue.. oh well I was just trying to point what the trouble was, why it only did the cow hides.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Edimmu's Avatar
    Join Date
    Jun 2012
    Age
    30
    Posts
    1,098
    Thanks given
    37
    Thanks received
    119
    Rep Power
    98
    Quote Originally Posted by Gnakos View Post
    due to:
    Code:
    if (!player.getInventory().containsItem(hide.getHide(), i)) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    Makes the loop stop if you dont have any hides of that kind... thats what I meant with continue.. oh well I was just trying to point what the trouble was, why it only did the cow hides.
    With that return it does more than cow hides with the continue I added. return/continue at that point doesn't seem to make a difference.

    EDIT: This is what is happening now.
    Attached image
    Reply With Quote  
     

  8. #8  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Quote Originally Posted by Edimmu View Post
    With that return it does more than cow hides with the continue I added. return/continue at that point doesn't seem to make a difference.

    EDIT: This is what is happening now.
    Attached image
    When you dont have any cow hides left in the inventory, it will not go to the next one

    And when you got the cow hides in the inventory it does continue because it does not get stuck at that part as I pasted.
    you could do it this way instead:

    Code:
    public static void hideChecker(Player player) {
    		for (hides hide : hides.values()) {
    			int i = player.getInventory().getNumerOf(hide.getHide());
    			if (i == 0) continue; // so if you dont have any of that kind it continues to look at the next hide in the enumset
    			int pouch = player.money;
    			if (!player.getInventory().contains(hide.getHide())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    			if (pouch < i*hide.getCost() && !player.getInventory().containsItem(995, i*hide.getCost())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have enough money.");
    				return;
    			}
    			if (pouch >= hide.getCost()) {
    				player.money -= i*hide.getCost();
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, i*hide.getCost());
    			}
    			player.getInventory().deleteItem(hide.getHide(), i);
    			player.getInventory().addItem(hide.getLeather(), i);
    			player.sm("Ellis tans x" +i+ " " +ItemDefinitions.getItemDefinitions(hide.getHide()).getName()+ " for you for x"+Utils.format(i*hide.getCost())+" coins.");
    			player.getDialogueManager().finishDialogue();
    			return;
    		}
    	}
    but then you would not get the message of that you dont have anything to tan if you dont have any hides..
    Reply With Quote  
     

  9. #9  
    Registered Member
    Edimmu's Avatar
    Join Date
    Jun 2012
    Age
    30
    Posts
    1,098
    Thanks given
    37
    Thanks received
    119
    Rep Power
    98
    Quote Originally Posted by Gnakos View Post
    When you dont have any cow hides left in the inventory, it will not go to the next one

    And when you got the cow hides in the inventory it does continue because it does not get stuck at that part as I pasted.
    you could do it this way instead:

    Code:
    public static void hideChecker(Player player) {
    		for (hides hide : hides.values()) {
    			int i = player.getInventory().getNumerOf(hide.getHide());
    			if (i == 0) continue; // so if you dont have any of that kind it continues to look at the next hide in the enumset
    			int pouch = player.money;
    			if (!player.getInventory().contains(hide.getHide())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    				return;
    			}
    			if (pouch < i*hide.getCost() && !player.getInventory().containsItem(995, i*hide.getCost())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have enough money.");
    				return;
    			}
    			if (pouch >= hide.getCost()) {
    				player.money -= i*hide.getCost();
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, i*hide.getCost());
    			}
    			player.getInventory().deleteItem(hide.getHide(), i);
    			player.getInventory().addItem(hide.getLeather(), i);
    			player.sm("Ellis tans x" +i+ " " +ItemDefinitions.getItemDefinitions(hide.getHide()).getName()+ " for you for x"+Utils.format(i*hide.getCost())+" coins.");
    			player.getDialogueManager().finishDialogue();
    			return;
    		}
    	}
    I'm saying that it now does go to the next one. I will try this though, cheers
    Edit: I've edited it a bit more and all works smashingly now. Cheers for the help!
    Reply With Quote  
     

  10. #10  
    Reverse Engineering

    freeezr's Avatar
    Join Date
    Dec 2011
    Posts
    1,067
    Thanks given
    288
    Thanks received
    444
    Rep Power
    401
    Code:
    public static void hideChecker(Player player) {
    		List<hides> avail = new ArrayList<>();
    		for (hides hide : hides.values()) {
    			if (player.getInventory().contains(hide.getHide()))
    				avail.add(hide);
    		}
    		
    		if (avail.isEmpty()) {
    			player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have any hides for me to tan.");
    			return;
    		}
    			
    		for (hides hide : avail) {
    			int i = player.getInventory().getNumerOf(hide.getHide());
    			int pouch = player.money;
    			if (pouch < i*hide.getCost() && !player.getInventory().containsItem(995, i*hide.getCost())) {
    				player.getDialogueManager().startDialogue("SimpleNPCMessage", 2824, "Sorry you don't have enough money.");
    				return;
    			}
    			if (pouch >= hide.getCost()) {
    				player.money -= i*hide.getCost();
    				player.refreshMoneyPouch();
    			} else {
    				player.getInventory().deleteItem(995, i*hide.getCost());
    			}
    			player.getInventory().deleteItem(hide.getHide(), i);
    			player.getInventory().addItem(hide.getLeather(), i);
    			player.sm("Ellis tans x" +i+ " " +ItemDefinitions.getItemDefinitions(hide.getHide()).getName()+ " for you for x"+Utils.format(i*hide.getCost())+" coins.");
    		}
    	}
    idk, off the top of my hea, while playing bo3. just an idea.

    Attached image
    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. Drop issue resolved around eating?
    By Someone in forum Help
    Replies: 2
    Last Post: 04-10-2013, 10:23 PM
  2. enum issue[rsgp]
    By LoveandPower in forum Buying
    Replies: 1
    Last Post: 11-04-2012, 02:35 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •