Thread: Void help

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 Void help 
    Registered Member Ghost`'s Avatar
    Join Date
    May 2010
    Posts
    416
    Thanks given
    10
    Thanks received
    13
    Rep Power
    2
    Well, tbh, first time trying this stuff...

    I'm trying to limit the items players can pickup, I worked it out in 1 code before but I only limited money. Now that I want to limit more items (Fire capes, godswords, skillcapes etc) I want to make a void/boolean...I made a void (I THINK) and it just won't work. How do you define it? (By the way, it's Emulous based)

    Pickup code:
    Code:
    if (playerCommand.startsWith("pickup"))			{
    				if (c.inWild())
    					return;
    				if (c.pickupLimit())
    					return;
    				try {
    					String[] args = playerCommand.split(" ");
    					if (args.length == 3) {
    						int newItemID = Integer.parseInt(args[1]);
    						int newItemAmount = Integer.parseInt(args[2]);					
    						if ((newItemID <= 11685) && (newItemID >= 0)) {
    							c.getItems().addItem(newItemID, newItemAmount);		
    						} else {
    							c.sendMessage("Item doesn't exist");
    						}
    					} else {
    						c.sendMessage("Use as ::pickup 995 200");
    					}
    				} catch(Exception e) {	
    				}
    			}
    Void:
    Code:
    public void pickupLimit() {
    		
    		if ((pItemId <= 11287) && (pItemId >= 11283));
    		if ((pItemId <= 9814) && (pItemId >= 9747));
    		if ((pItemId <= 6570) && (pItemId >= 6568));
    		if ((pItemId <= 8010) && (pItemId >= 8000));
    		if ((pItemId <= 996) && (pItemId >= 994));
    		if ((pItemId <= 4760) && (pItemId >= 4708));
    		if ((pItemId <= 8850) && (pItemId >= 8839));
    		if ((pItemId <=20000) && (pItemId >=11685));
    		sendMessage("These items are off limits!");
    							
    		}
    Error:
    Code:
    src\server\model\players\packets\Commands.java:43: incompatible types
    found   : void
    required: boolean
                                    if (c.pickupLimit())
                                                     ^
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    Press any key to continue . . .
    Reply With Quote  
     

  2. #2  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    Almost

    Code:
    public boolean pickupLimit()
    {
    	if ((pItemId <= 11287) && (pItemId >= 11283))||
    	((pItemId <= 9814) && (pItemId >= 9747))||
    	((pItemId <= 6570) && (pItemId >= 6568))||
    	((pItemId <= 8010) && (pItemId >= 8000))||
    	((pItemId <= 996) && (pItemId >= 994))||
    	((pItemId <= 4760) && (pItemId >= 4708))||
    	((pItemId <= 8850) && (pItemId >= 8839))||
    	((pItemId <=20000) && (pItemId >=11685))
    	{
    		sendMessage("These items are off limits!");	
    		return true;
    	}
    	return false;
    }
    This can't hurt :L
    The Java™ Tutorials
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Feb 2009
    Age
    31
    Posts
    107
    Thanks given
    1
    Thanks received
    0
    Rep Power
    2
    Quote Originally Posted by Illuminate View Post
    Almost

    Code:
    public boolean pickupLimit()
    {
    	if ((pItemId <= 11287) && (pItemId >= 11283))||
    	if ((pItemId <= 9814) && (pItemId >= 9747))||
    	if ((pItemId <= 6570) && (pItemId >= 6568))||
    	if ((pItemId <= 8010) && (pItemId >= 8000))||
    	if ((pItemId <= 996) && (pItemId >= 994))||
    	if ((pItemId <= 4760) && (pItemId >= 4708))||
    	if ((pItemId <= 8850) && (pItemId >= 8839))||
    	if ((pItemId <=20000) && (pItemId >=11685))
    	{
    		sendMessage("These items are off limits!");	
    		return true;
    	}
    	return false;
    }
    This can't hurt :L
    The Java™ Tutorials
    Thats not right either.

    You can make an array with item id's and make a for loop to loop through the items.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    Quote Originally Posted by Vegito View Post
    Thats not right either.

    You can make an array with item id's and make a for loop to loop through the items.
    And that makes it not right?

    He obviously doesn't understand the most basic of Java, yet you try to throw in even complex ideas without even providing an example.

    This community isn't about trying to "show up" people.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Feb 2009
    Age
    31
    Posts
    107
    Thanks given
    1
    Thanks received
    0
    Rep Power
    2
    Quote Originally Posted by Illuminate View Post
    And that makes it not right?

    He obviously doesn't understand the most basic of Java, yet you try to throw in even complex ideas without even providing an example.

    This community isn't about trying to "show up" people.
    No but this community isn't about giving bad examples either.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    Quote Originally Posted by Vegito View Post
    No but this community isn't about giving bad examples either.
    And now you are demeaning his code.

    Seriously, this community doesn't need any more of you; close your browser, walk away.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Feb 2009
    Age
    31
    Posts
    107
    Thanks given
    1
    Thanks received
    0
    Rep Power
    2
    This would be a better step in the direction:

    Code:
    public boolean pickupLimit()
    {
    	if (pItemId <= 11287 && pItemId >= 11283||
    	pItemId <= 9814 && pItemId >= 9747||
    	pItemId <= 6570 && pItemId >= 6568||
    	pItemId <= 8010 && pItemId >= 8000||
    	pItemId <= 996 && pItemId >= 994||
    	pItemId <= 4760 && pItemId >= 4708||
    	pItemId <= 8850 && pItemId >= 8839||
    	pItemId <=20000 && pItemId >=11685)
    	{
    		sendMessage("These items are off limits!");	
    		return true;
    	}
    	return false;
    }
    Reply With Quote  
     

  8. #8  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    yeah thats right. forgot to remove the extra ifs.
    Reply With Quote  
     

  9. #9  
    Registered Member Ghost`'s Avatar
    Join Date
    May 2010
    Posts
    416
    Thanks given
    10
    Thanks received
    13
    Rep Power
    2
    Quote Originally Posted by Vegito View Post
    This would be a better step in the direction:

    Code:
    public boolean pickupLimit()
    {
    	if (pItemId <= 11287 && pItemId >= 11283||
    	pItemId <= 9814 && pItemId >= 9747||
    	pItemId <= 6570 && pItemId >= 6568||
    	pItemId <= 8010 && pItemId >= 8000||
    	pItemId <= 996 && pItemId >= 994||
    	pItemId <= 4760 && pItemId >= 4708||
    	pItemId <= 8850 && pItemId >= 8839||
    	pItemId <=20000 && pItemId >=11685)
    	{
    		sendMessage("These items are off limits!");	
    		return true;
    	}
    	return false;
    }
    100 errors, trying to find the extra bracket...
    Reply With Quote  
     

  10. #10  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    There's nothing wrong with the code itself...maybe where you added it?
    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

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