Thread: Array check equipped items. & for loop help.

Results 1 to 8 of 8
  1. #1 Array check equipped items. & for loop help. 
    Registered Member
    Join Date
    Jan 2008
    Posts
    147
    Thanks given
    9
    Thanks received
    4
    Rep Power
    1
    How would I make an array/for loop that'll check my equipped items?

    I have tried this:

    Code:
    public void checkItems() {
    int[]equipItems = { 4151, 6570, 11694,......};
    
    
    for (int i = 0; i < equipItems.length; i++) { 
    if (c.playerEquipment[c.playerWeapon] != equipItems[i]){
    } else if (c.playerEquipment[c.playerHat] != equipItems[i]){
    } else if (c.playerEquipment[c.playerHands] != equipItems[i]){
    } else if (c.playerEquipment[c.playerChest] != equipItems[i]){
    } else if (c.playerEquipment[c.playerLegs] != equipItems[i]){
    } else if (c.playerEquipment[c.playerFeet] != equipItems[i]){
    } else if (c.playerEquipment[c.playerShield] != equipItems[i]){
    c.sendMessage("You cannot bring those items with you to play.");
    	} else {
    c.sendMessage("Your items are ok. Please continue.");
    		}
    	}
    }
    It doesn't work it'll allow those items in my array even if I have them equipped.



    New Project.
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Wait what do you want to do? Please explain
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jan 2008
    Posts
    147
    Thanks given
    9
    Thanks received
    4
    Rep Power
    1
    Yes basically the items inside

    Code:
    int[]equipItems = { 4151, 6570, 11694,......};



    New Project.
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    just use something like

    Code:
    public static boolean equipmentCheck(Player p, int[][] data) {
    		for (int i = 0; i < data.length; i++) {
    			if (p.playerEquipment[data[i][0]] != data[i][1]) {
    				System.out.println("Doesn't have required equipment.");
    				return false;
    			}
    		}
    		return true;
    	}
    Use as:

    int[][] data = { {equipmentSlot, equipmentItemId}, {equipmentSlot2, equipmentItemId2} };
    equipmentCheck(((Player)c), data);
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jan 2008
    Posts
    147
    Thanks given
    9
    Thanks received
    4
    Rep Power
    1
    Quote Originally Posted by iRageQuit2012 View Post
    just use something like

    Code:
    public static boolean equipmentCheck(Player p, int[][] data) {
    		for (int i = 0; i < data.length; i++) {
    			if (p.playerEquipment[data[i][0]] != data[i][1]) {
    				System.out.println("Doesn't have required equipment.");
    				return false;
    			}
    		}
    		return true;
    	}
    Use as:

    int[][] data = { {equipmentSlot, equipmentItemId}, {equipmentSlot2, equipmentItemId2} };
    equipmentCheck(((Player)c), data);
    I don't see how that'll check certain equipment, like if I don't want a player to be able to wear an Abyssal whip or a Firecape when entering a minigame, I can't do playerHasItem because I want to do it with multiple items.

    If I'm wrong please explain. I'm trying to learn how to use these methods better.



    New Project.
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Jun 2009
    Posts
    2,916
    Thanks given
    169
    Thanks received
    806
    Rep Power
    0
    Code:
    public static boolean hasUnavailableEquipment(Client p) {
    	for (int i = 0; i < restrictedItems.length; i++) {
    		for (int equip = 0; equip < 14; equip++) {
    			if (p.playerEquipment[equip] == restrictedItems[i]) {
    			c.sendMessage("You can not bring "+c.getItems().getItemName(p.playerEquipment[equip]);
    				return true;
    			}
    		}
    	}
    	return  false;
    }
    
    static int [] restrictedItems = {4151};
    in your entering shit

    Code:
    if (hasUnavailableEquipment(c)
    	return;
    Reply With Quote  
     

  7. #7  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by Jads View Post
    I don't see how that'll check certain equipment, like if I don't want a player to be able to wear an Abyssal whip or a Firecape when entering a minigame, I can't do playerHasItem because I want to do it with multiple items.

    If I'm wrong please explain. I'm trying to learn how to use these methods better.
    Code:
    public static boolean isWearingItems(Player player, int[][] items) {
    	for(int i = 0; i < items.length; i++) {
    		if(player.playerEquipment[items[i][0]] != items[i][1]) {
    			return false;
    		}
    	}
    	return true;
    }
    Code:
    int[][] requiredItems = { 
    	{PlayerConstants.CAPE, 6570},
            {PlayerConstants.WEAPON, 4153}
    }
    		
    if(!isWearingItems(player, requiredItems)) {
    	// not wearing the items
    }
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by 5tuart View Post
    Code:
    public static boolean isWearingItems(Player player, int[][] items) {
    	for(int i = 0; i < items.length; i++) {
    		if(player.playerEquipment[items[i][0]] != items[i][0]) {
    			return false;
    		}
    	}
    	return true;
    }
    Code:
    int[][] requiredItems = { 
    	{PlayerConstants.CAPE, 6570},
            {PlayerConstants.WEAPON, 4153}
    }
    		
    if(!isWearingItems(player, requiredItems)) {
    	// not wearing the items
    }
    Same shit I just posted, but ok. .__.

    @ Jads, what are you talking about? I even told you how to use it, just add the method in ItemAssistant and then when you want to check use:

    int[][] data = { {equipmentSlot}, {equipmentId} };

    if (ItemAssistant.equipmentCheck(player, data)) {

    }
    Reply With Quote  
     

  9. Thankful user:



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] Equipped items [pi]
    By oblivion-rs in forum Help
    Replies: 1
    Last Post: 12-26-2010, 02:43 AM
  2. Replies: 7
    Last Post: 08-30-2010, 07:01 AM
  3. Loop 3D Array
    By Greyfield in forum Help
    Replies: 2
    Last Post: 12-21-2009, 03:57 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
  •