Thread: Why Isn't This Working?

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Why Isn't This Working? 
    Donator
    Bernie Sanders's Avatar
    Join Date
    Jun 2011
    Posts
    475
    Thanks given
    274
    Thanks received
    42
    Rep Power
    72
    Hi,

    I'm adding the final touches to my Halloween event, but came across a problem that is probably extremely easy to fix, and I'm just missing it.

    When searching a pumpkin, I want it to give you a Jack Lantern Mask. If you already have one in your inventory, it will instead give you a chocolate bomb.

    For some reason, it's giving me both when I search the pumpkin. Any ideas?

    Objecthandler.java
    Code:
    				if (id == 62430) {
    					if (player.getInventory().containsItem(9920, 1) == false);
    					player.getInventory().addItem(9920, 1);
    					player.getPackets().sendGameMessage(
    							"You find a Jack Lantern Mask!");}
    					else if (player.getInventory().containsItem(9920, 1) == true);
    					player.getInventory().addItem(2185, 1);
    					player.getPackets().sendGameMessage(
    							"You find a chocolatey treat!");

    Also, if you can show me how to make it check your equipment slots and bank for the mask that would be great!
    Attached image
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Feb 2013
    Posts
    4,409
    Thanks given
    59
    Thanks received
    478
    Rep Power
    138
    Code:
    if (id == 62430) {
        if (!player.getInventory().containsItem(9920, 1)) {
    player.getInventory().addItem(9920, 1);
    player.sendMessage("You find a Jack Lantern Mask!");
    } else if (player.getInventory().containsItem(9920, 1)) {
    player.getInventory().addItem(2185, 1);
    player.sendMessage("You find a chocolatey treat!");
        }
    }
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Donator
    Bernie Sanders's Avatar
    Join Date
    Jun 2011
    Posts
    475
    Thanks given
    274
    Thanks received
    42
    Rep Power
    72
    Quote Originally Posted by Datbeastmayne View Post
    Code:
    if (id == 62430) {
    if (player.getInventory().containsItem(9920, 1)) {
    player.getInventory().addItem(9920, 1);
    player.sendMessage("You find a Jack Lantern Mask!");
    } else if (player.getInventory().containsItem(9920, 1)) {
    player.getInventory().addItem(2185, 1);
    player.sendMessage("You find a chocolatey treat!");
    }
    }
    It's not giving me any items now.
    Attached image
    Reply With Quote  
     

  5. #4  
    Server developer


    Join Date
    Jul 2010
    Posts
    881
    Thanks given
    265
    Thanks received
    55
    Rep Power
    94
    Code:
    if (id == 62430) {
        if (!player.getInventory().containsItem(9920)) {
    	     player.getInventory().addItem(9920, 1);
    	     player.getPackets().sendGameMessage("You find a Jack Lantern Mask!");
    	} else if (player.getInventory().containsItem(9920)) {;
    		player.getInventory().addItem(2185, 1);
    	        player.getPackets().sendGameMessage("You find a chocolatey treat!");
            }
    }
    ?

    I'd rather do it with:

    Code:
    if (playerhasitem.....) { //does have the item
        //do stuff here
    } else { //does not have the item
       //do stuff here
    }
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Donator
    Bernie Sanders's Avatar
    Join Date
    Jun 2011
    Posts
    475
    Thanks given
    274
    Thanks received
    42
    Rep Power
    72
    Quote Originally Posted by klaasvaakjes View Post
    Code:
    if (id == 62430) {
        if (!player.getInventory().containsItem(9920)) {
    	     player.getInventory().addItem(9920, 1);
    	     player.getPackets().sendGameMessage("You find a Jack Lantern Mask!");
    	} else if (player.getInventory().containsItem(9920)) {;
    		player.getInventory().addItem(2185, 1);
    	        player.getPackets().sendGameMessage("You find a chocolatey treat!");
            }
    }
    ?

    I'd rather do it with:

    Code:
    if (playerhasitem.....) { //does have the item
        //do stuff here
    } else { //does not have the item
       //do stuff here
    }
    Thanks, that worked. How would I go about making it also check the head slot and bank for the Jack Lantern mask? I want to make sure players only get one mask.
    Attached image
    Reply With Quote  
     

  8. #6  
    Registered Member
    Join Date
    Oct 2014
    Posts
    23
    Thanks given
    1
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Giraffe View Post
    Thanks, that worked. How would I go about making it also check the head slot and bank for the Jack Lantern mask? I want to make sure players only get one mask.
    What base are you using?
    Reply With Quote  
     

  9. #7  
    Donator
    Bernie Sanders's Avatar
    Join Date
    Jun 2011
    Posts
    475
    Thanks given
    274
    Thanks received
    42
    Rep Power
    72
    Quote Originally Posted by Monty Python View Post
    What base are you using?
    That doesn't really matter. It's a 718, not one released in any community.
    Attached image
    Reply With Quote  
     

  10. #8  
    Registered Member
    Join Date
    Oct 2014
    Posts
    23
    Thanks given
    1
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Giraffe View Post
    That doesn't really matter. It's a 718, not one released in any community.
    Get the ID of the head slot, and check it contains the item ID.
    Reply With Quote  
     

  11. #9  
    Registered Member

    Join Date
    Oct 2012
    Posts
    1,461
    Thanks given
    560
    Thanks received
    323
    Rep Power
    122
    Quote Originally Posted by Giraffe View Post
    Thanks, that worked. How would I go about making it also check the head slot and bank for the Jack Lantern mask? I want to make sure players only get one mask.
    Not sure how you would do it on your source but should be the same hopefully :

    Code:
    if (player.getBank().contains(9920, 1) {
    //They contain a jack lantern mask in their bank.
    }
    For head slot :

    Code:
    if (player.getEquipment().get(Equipment.SLOT_HELMET) != null && player.getEquipment().get(Equipment.SLOT_HELMET).getId() == 9920) {
    //Player is wearing a jack lantern mask
    }
    You should make the whole check by using nested if statements (if statements inside one another) to make the check to make sure they haven't got one in their bank and equipment and inventory then add it. If you want to send a message, after the if (player.getBank()... etc, after the bracket that closes that if statement, just do like

    Code:
    } else {
    //Send message here saying you already have that in your inv/bank/equipment whatever.
    }
    Hope i helped in some way or the other

    “I have not failed. I've just found 10,000 ways that won't work.”
    ― Thomas A. Edison


    Attached image


    Reply With Quote  
     

  12. #10  
    Registered Member
    Join Date
    Apr 2012
    Posts
    36
    Thanks given
    2
    Thanks received
    4
    Rep Power
    22
    Code:
    if (player.getEquipment().getHatId() == id)
    
    and 
    
    if (player.getBank().getItem(id) != null)
    this should work the way you want
    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. [hyperion] why isn't this working..
    By Andrew in forum Help
    Replies: 4
    Last Post: 09-09-2012, 03:47 AM
  2. Why isn't this working? PT 2
    By Flaunter in forum Help
    Replies: 7
    Last Post: 01-03-2012, 01:50 AM
  3. Why isn't this working?
    By Flaunter in forum Help
    Replies: 19
    Last Post: 01-02-2012, 03:04 PM
  4. Why isn't this working
    By Tom Sawyer in forum Help
    Replies: 3
    Last Post: 06-09-2011, 06:52 AM
  5. Why isn't this working?
    By Zahhak in forum Website Development
    Replies: 11
    Last Post: 01-20-2011, 02:00 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
  •