Thread: Help With Enums

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 Help With Enums 
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750
    Need alittle help with using Enums to read equipment. If someone could just provide one of these for me, that'd be great. Im new to enums, and learned they are more effective than what I currently have, so please help:

    Code:
    public enum Arrows { arrows, arrow, bolts }
    
    public static int itemType(int item, Client c) {
            String getTheItem = c.GetItemName(item);
            getTheItem.toLowerCase();
            
                for(Arrows Type : Arrows.values()) {
                  return c.playerArrows;
                }
                
                return c.playerWeapon;
        }

    The enum is to be used for getting whats contained in the item name. If the item contains arrows, arrow, or bolts, it will equip to the arrow slot. Thats basically what im trying to do. HALP!

    I am just at a complete loss when it comes to enums. I know this is probably all fucked up. >.<

    Attached image
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    I would suggest to use this temporarily (I would just use this to easily get the correct slots then add the information to my server-sided cache and read it on start-up to avoid all the looping every time you need to get an item's slot)

    Code:
    	public enum Type {
    		/*
    		 * Put the enums in order, i.e helmet should be first, etc.
    		 */
    		AMMUNITION("arrow", "bolt");
    		
    		private Type(String... names) {
    			this.names = names;
    		}
    		
    		private String[] names;
    	}
    	
    	public static int getSlot(Client client, int id) {
    		String itemName = ItemAssistant.getName(id).toLowerCase();
    		for (Type type : Type.values()) {
    			for (String names : type.names()) {
    				if (names.contains(itemName)) {
    					return names.ordinal();
    				}
    			}
    		}
    		return 3; //default slot
    	}
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    🍥🍥🍥


    Join Date
    Dec 2008
    Posts
    1,702
    Thanks given
    664
    Thanks received
    293
    Rep Power
    621
    You should also read this post: http://www.rune-server.org/3601166-post28.html
    Reply With Quote  
     

  5. #4  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750
    Quote Originally Posted by spring2000 View Post
    You should also read this post: http://www.rune-server.org/3601166-post28.html
    I already did, but its use is not the same as what i need it for

    Attached image
    Reply With Quote  
     

  6. #5  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750


    Cant resolve that
    Also, my server is delta...but heavily modified. Can u remake that for delta?

    Attached image
    Reply With Quote  
     

  7. #6  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    Quote Originally Posted by King Fox View Post


    Cant resolve that
    Also, my server is delta...but heavily modified. Can u remake that for delta?
    Code:
    for (Type type : Type.values()) {
                if (type.toString().contains(itemName.toUpperCase())) {
                    return type;
                }
        }
    change return type to Type
    Reply With Quote  
     

  8. #7  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Yeah, my bad, here

    Code:
    public static int getSlot(Client client, int id) {
    		String itemName = ItemAssistant.getName(id).toLowerCase();
    		for (Type type : Type.values()) {
    			for (String names : type.names) {
    				if (names.contains(itemName)) {
    					return type.ordinal();
    				}
    			}
    		}
    		return 3; //default slot
    	}
    This is how I just added it to my server btw:

    Code:
    private enum Type {
    		HELMET(Equipment.HELMET_SLOT, "helm", "hat", "hood"),
    		CAPE(Equipment.CAPE_SLOT, "cape"),
    		AMULET(Equipment.AMULET_SLOT, "amulet", "necklace"),
    		CHEST(Equipment.BODY_SLOT, "body", "chest", "top"),
    		SHIELD(Equipment.SHIELD_SLOT, "shield"),
    		LEGS(Equipment.LEG_SLOT, "legs", "bottom"),
    		GLOVES(Equipment.HANDS_SLOT, "gloves", "gauntlets"),
    		RING(Equipment.RING_SLOT, "ring"),
    		AMMUNITION(Equipment.AMMUNITION_SLOT, "arrow", "bolt");
    		
    		private Type(int slot, String... names) {
    			this.slot = slot;
    			this.names = names;
    		}
    		
    		private int slot;
    		
    		private String[] names;
    	}
    	
    	private static void addSlotDefinition(int id) {
    		for (Type type : Type.values()) {
    			for (String names : type.names) {
    				if (forId(id).name.toLowerCase().contains(names)) {
    					forId(id).slot = type.slot;
    					System.out.println("Added slot for item " + id + " to slot " + type.slot);
    				}
    			}
    		}
    	}
    
    private void getValues(DataInputStream in) {
    		try {
    			do {
    				int opcode = in.readByte();
    				if(opcode == 0)
    					return;
    				if(opcode == 1) {
    					name = in.readUTF();
    					addSlotDefinition(id);
    				} else if(opcode == 2) {
    					....
    Reply With Quote  
     

  9. #8  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750
    Thanks, there we go. No errors. now just to test o.

    Sorry if I'm a bother, but I have no clue on enums, and my server is Delta, which makes it a bit more difficult. Equipping my items are painfully slow. I just want to make everything efficient.

    Im beginning to think my equipping needs to be completely redone

    EDIT: i feel like an idiot. Anyway, everything just equips to the weapon slot, even the arrows ?

    Attached image
    Reply With Quote  
     

  10. #9  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750
    edited reply....feel like a moron

    Attached image
    Reply With Quote  
     

  11. #10  
    Renown Programmer

    Join Date
    Dec 2010
    Posts
    2,876
    Thanks given
    508
    Thanks received
    1,898
    Rep Power
    5000
    i don't think you have any clue what you're doing whatsoever and should quit while you're behind
    Reply With Quote  
     

  12. Thankful user:


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. PI Cooking with enums
    By Chris SS in forum Snippets
    Replies: 25
    Last Post: 04-26-2013, 01:08 AM
  2. Arrays Vs Enums.
    By Gluon in forum Application Development
    Replies: 44
    Last Post: 02-26-2012, 05:18 AM
  3. Question on enums
    By Innocence in forum Application Development
    Replies: 5
    Last Post: 11-16-2011, 08:57 AM
  4. Basic Enums
    By Sir Tom in forum Application Development
    Replies: 1
    Last Post: 12-28-2010, 03:53 PM
  5. Teleporting using Enums
    By Ho H0 Ho in forum Configuration
    Replies: 8
    Last Post: 11-11-2010, 01:05 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
  •