Thread: Checking for Item in Inventory/Equip using Arrays

Results 1 to 4 of 4
  1. #1 Checking for Item in Inventory/Equip using Arrays 
    Registered Member
    Grey's Avatar
    Join Date
    May 2007
    Posts
    634
    Thanks given
    0
    Thanks received
    23
    Rep Power
    433
    Purpose: Creating an array that checks if you are wielding or have an item in your inventory.
    Difficulty: As hard as you make it.
    Assumed knowlege: Reading/Comprehending

    Declare:

    Code:
    public void checkEMItems() {
    int[]EMNA = { 4151 };
    
    for (int h = 0; h < EMNA.length; h++) {
    if (!playerHasItem(EMNA[h], 1)){
    sendMessage("You have an item that you can't bring on board.");
    } else {
    sendMessage("You can board the ship.");
    }}}
    
    public void checkEMWItems() {
    int[]EMNA2 = { 4151 };
    
    for (int h = 0; h < EMNA2.length; h++) {
    if (playerEquipment[playerWeapon] != EMNA2[h]){
    //
    } else if (playerEquipment[playerHat] != EMNA2[h])
    //
    } else if (playerEquipment[playerHands] != EMNA2[h]){
    //
    } else if (playerEquipment[playerChest] != EMNA2[h]){
    //
    } else if (playerEquipment[playerLegs] != EMNA2[h]){
    //
    } else if (playerEquipment[playerFeet] != EMNA2[h]){
    //
    } else if (playerEquipment[playerShield] != EMNA2[h]){
    //
    } else {
    sendMessage("You are wielding an item that you can't bring on board.");
    }}}
    The ENMA and the EMNA2 are the arrays. The 4151 inside the array is the ID for a whip. The code above searches through the arrays to see if you are wielding the item in any of the equipment spots, or if you have it in your inventory. You can use the method above for whatever you want.

    Example:
    I could use the above method to have the Entrana Monk search me before I can embark on the journey to Entrana.

    That's why the methods are called EMItems (standing for Entrana Monk Items - inventory) and EMWItems (standing for Entrana Monk Wield Items).

    To check it, we would just use this method:

    Code:
    checkEMItems();
    checkEMWItems();
    This is just a base, you guys can customize it to however you wish. This is just a simple base for whichever intentions you use.

    Here is an array if you plan on using the Entrana Monk searching method:

    Code:
    int[]EMNA = { 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 577, 579, 
    581, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 
    664, 1033, 1035, 1037, 1038, 1040, 1042, 1044, 1046, 1048, 1050, 1053, 1055, 
    1057, 1059, 1833, 1835, 1837, 2894, 2896, 2898, 2900, 2902, 2904, 2906, 2908, 2910, 
    2912, 2914, 2916, 2918, 2920, 2922, 2924, 2926, 2928, 2930, 2932, 2934, 2936, 2938, 2940, 2942, 6570 };
    The above array has a LOT of the robe code, including boots, gloves, hats, body's, and bottoms.
    Working on The Rebirth.
    Reply With Quote  
     

  2. #2  
    Community Veteran

    Songoty's Avatar
    Join Date
    Dec 2007
    Posts
    2,740
    Thanks given
    211
    Thanks received
    1,034
    Rep Power
    2455
    I don't see why playerHasItem(int,amount) isn't sufficient?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Grey's Avatar
    Join Date
    May 2007
    Posts
    634
    Thanks given
    0
    Thanks received
    23
    Rep Power
    433
    Quote Originally Posted by Songoty View Post
    I don't see why playerHasItem(int,amount) isn't sufficient?
    This is used to check more than one item.

    Sure, I could have it just have the if (playerHasItem(4151, 1); but if I wanted multiple items, an array would be a lot easier.
    Working on The Rebirth.
    Reply With Quote  
     

  4. #4  
    Community Veteran

    Songoty's Avatar
    Join Date
    Dec 2007
    Posts
    2,740
    Thanks given
    211
    Thanks received
    1,034
    Rep Power
    2455
    Meh.

    Also, I'm not sure why you guys don't grasp this concept, but the loops you are using to loop threw an array is not correct.

    Code:
    for (int i : EMNA) {
    if (!playerHasItem(i, 1)){
    Watever you had here
    } 
    }
    This is the correct loop to use when going threw a single array.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •