Thread: Cleaner method?

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Cleaner method? 
    i want a PM. The best in life is free.
    Project M's Avatar
    Join Date
    Mar 2012
    Posts
    368
    Thanks given
    20
    Thanks received
    13
    Rep Power
    14
    is it possible to make my code cleaner? if yes, how?


    iknow its ugly, but i want to learn...

    Code:
    public void pickPlayerPocket(int index) {
    
    		Client p = (Client)PlayerHandler.players[index];
    
    		c.pickingPlayer = false;
    
    		if(p == null) return;
    
    		if (c.playerLevel[17] < p.playerLevel[17]) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You need to have a theiving level of " + p.playerLevel[17] + " to pick this person pockets.");
    			return;
    		}
    		
    		if (p.playerName.equalsIgnoreCase("Test") && (Misc.random(300) <= 299)) {
    		c.startAnimation(832);
            c.sendMessage("@red@[ThievMaster]@red@ @bla@ You failed.");
    					c.gfx100(80);
    					c.getPA().sound(937);
    					
    		return;
        }
    		if (p.Antithievtimer >= 1 || p.anticheattimer >= 1){
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@ " + p.playerName + " has  "+ p.Antithievtimer + " secounds protection");
    			return;
    		}
    
    		if (p.inDuelArena() || p.inCw() || p.isBanking || p.inTrade) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@This player is busy.");
    			return;
    		}
    		c.startAnimation(832);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You attempt to pick " + p.playerName + "'s pockets...");
    
    		
    		if (Misc.random(4) == 1 || Misc.random(4) == 3 || Misc.random(4) == 2 && !p.playerName.equalsIgnoreCase("Test")) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You failed and noticed " + p.playerName + "");
    			p.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@" + c.playerName + " tried to steal from you but failed");
    			c.gfx100(80);
    					c.playerLevel[3] -= 1;
    					c.setHitUpdateRequired(true);
    					c.getPA().refreshSkill(3);;
    					c.getPA().sound(937);
    			return;
    		}
    			
    		int item = 0, amount = 0, trys = 0;
    		while(item == 0 && trys < 1) {
    			for (int i = 0; i < p.playerItems.length; i++) {
    				if ((p.playerItems[i]-1) > 0) {
    					int v = c.getShops().getItemShopValue(p.playerItems[i] - 1);
    					if (v > 150000) continue; // higher than 1 million? skip that shit :)
    					if (Misc.random(4) == 4) {
    					item = p.playerItems[i] - 1;
    						if(p.playerItemsN[i] > 1)
    							amount = Misc.random((p.playerItemsN[i] > 1000000 ? 1000000 : p.playerItemsN[i]));
    						else
    							amount = 1;
    					}
    				}
    			}
    			trys++;
    		}
    		if (item == 0) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@The person dont have any valutes left.");
    			return;
    		}
    		p.getItems().deleteItem(item, amount);
    		p.sendMessage("@yel@[PICKPOCKET]@yel@ @red@" + c.playerName + " did steal something from you. ");
    		c.getItems().addItem(item, amount);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You successfully picked " + p.playerName + "'s pockets!");
    		if (p.playerName.equalsIgnoreCase("Test")) {
    		c.getQuest().thievmaster();
    		c.getPA().yell(""SERVER", c.playerName+" just completed ThievMaster.");
    
    						}
    					}
    				}
    			}
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jun 2009
    Posts
    2,916
    Thanks given
    169
    Thanks received
    806
    Rep Power
    0
    code looks shit
    Reply With Quote  
     

  3. #3  
    i want a PM. The best in life is free.
    Project M's Avatar
    Join Date
    Mar 2012
    Posts
    368
    Thanks given
    20
    Thanks received
    13
    Rep Power
    14
    Quote Originally Posted by iQuality View Post
    code looks shit
    iknow, thatswhy i made a post about it?...

    Could you help me improving it?
    Reply With Quote  
     

  4. #4  
    Registered Member Sakki54's Avatar
    Join Date
    Jul 2010
    Posts
    159
    Thanks given
    37
    Thanks received
    12
    Rep Power
    1
    To make it look visually better, use Eclipse and format it...
    Reply With Quote  
     

  5. #5  
    i want a PM. The best in life is free.
    Project M's Avatar
    Join Date
    Mar 2012
    Posts
    368
    Thanks given
    20
    Thanks received
    13
    Rep Power
    14
    Quote Originally Posted by Sakki54 View Post
    To make it look visually better, use Eclipse and format it...
    well, im getting errors thats impossible to fix ( in 4 files), in eclipse. but when i compile without eclipse it works..


    anyone?
    Reply With Quote  
     

  6. #6  
    Registered Member Sakki54's Avatar
    Join Date
    Jul 2010
    Posts
    159
    Thanks given
    37
    Thanks received
    12
    Rep Power
    1
    Quote Originally Posted by Initium View Post
    well, im getting errors thats impossible to fix ( in 4 files), in eclipse. but when i compile without eclipse it works..


    anyone?
    Post the errors. If they aren't showing in the compiler, but they are showing in eclipse that means that when the server actually uses that code you will get an error.
    Reply With Quote  
     

  7. #7  
    i want a PM. The best in life is free.
    Project M's Avatar
    Join Date
    Mar 2012
    Posts
    368
    Thanks given
    20
    Thanks received
    13
    Rep Power
    14
    Quote Originally Posted by Sakki54 View Post
    Post the errors. If they aren't showing in the compiler, but they are showing in eclipse that means that when the server actually uses that code you will get an error.
    i will figure it out :C too much errors in eclipse right now.

    just want this clean.

    any help with :
    http://www.rune-server.org/runescape...ml#post3486983
    ?
    Reply With Quote  
     

  8. #8  
    Registered Member
    Vox''s Avatar
    Join Date
    Nov 2008
    Age
    31
    Posts
    3,113
    Thanks given
    49
    Thanks received
    181
    Rep Power
    731
    Jesus

    Code:
    public void pickPlayerPocket(int index) {
    
    		Client p = (Client)PlayerHandler.players[index];
    		c.pickingPlayer = false;
    
    		if(p == null) return;
    
    		if (c.playerLevel[17] < p.playerLevel[17]) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You need to have a theiving level of " + p.playerLevel[17] + " to pick this person pockets.");
    			return;
    		}
    		
    		if (p.playerName.equalsIgnoreCase("Test") && (Misc.random(300) <= 299)) {
    			c.startAnimation(832);
    	        c.sendMessage("@red@[ThievMaster]@red@ @bla@ You failed.");
    			c.gfx100(80);
    			c.getPA().sound(937);
    		} else {
    		if (p.Antithievtimer >= 1 || p.anticheattimer >= 1){
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@ " + p.playerName + " has  "+ p.Antithievtimer + " secounds protection");
    		}
    		if (p.inDuelArena() || p.inCw() || p.isBanking || p.inTrade) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@This player is busy.");
    		}
    		c.startAnimation(832);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You attempt to pick " + p.playerName + "'s pockets...");
    
    		
    		if (Misc.random(4) == 1 || Misc.random(4) == 3 || Misc.random(4) == 2 && !p.playerName.equalsIgnoreCase("Test")) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You failed and noticed " + p.playerName + "");
    			p.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@" + c.playerName + " tried to steal from you but failed");
    			c.gfx100(80);
    					c.playerLevel[3] -= 1;
    					c.setHitUpdateRequired(true);
    					c.getPA().refreshSkill(3);;
    					c.getPA().sound(937);
    			return;
    		}
    	}
    		int item = 0, amount = 0, trys = 0;
    		while(item == 0 && trys < 1) {
    			for (int i = 0; i < p.playerItems.length; i++) {
    				if ((p.playerItems[i]-1) > 0) {
    					int v = c.getShops().getItemShopValue(p.playerItems[i] - 1);
    					if (v > 150000) continue; // higher than 1 million? skip that shit :)
    					if (Misc.random(4) == 4) {
    					item = p.playerItems[i] - 1;
    						if(p.playerItemsN[i] > 1) {
    							amount = Misc.random((p.playerItemsN[i] > 1000000 ? 1000000 : p.playerItemsN[i]));
    						} else {
    							amount = 1;
    						}
    					}
    				}
    			}
    			trys++;
    		}
    		if (item == 0) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@The person dont have any valutes left.");
    			return;
    		} else {
    		p.getItems().deleteItem(item, amount);
    		p.sendMessage("@yel@[PICKPOCKET]@yel@ @red@" + c.playerName + " did steal something from you. ");
    		c.getItems().addItem(item, amount);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You successfully picked " + p.playerName + "'s pockets!");
    		if (p.playerName.equalsIgnoreCase("Test")) {
    		c.getQuest().thievmaster();
    		c.getPA().yell("SERVER", c.playerName+" just completed ThievMaster.");
    			}
    		}
    	}
    }
    moved some things around, fixed your brackets. You should make this a separate class, as opposed to a method in a prior class.

    Quote Originally Posted by Zirtrix View Post
    So I've recently changed some things in the server, but when i compile it says
    Code:
    source\server\model\players\packets\Commands.java: 58: error: cannot find symbol
    This.Antileech("Remove This Line");
    ^
    Anyone know the problem?
    Student and Developer for http://www.rune-server.org/runescape...pve-based.html
    Reply With Quote  
     

  9. #9  
    i want a PM. The best in life is free.
    Project M's Avatar
    Join Date
    Mar 2012
    Posts
    368
    Thanks given
    20
    Thanks received
    13
    Rep Power
    14
    Quote Originally Posted by Vox' View Post
    Jesus

    Code:
    public void pickPlayerPocket(int index) {
    
    		Client p = (Client)PlayerHandler.players[index];
    		c.pickingPlayer = false;
    
    		if(p == null) return;
    
    		if (c.playerLevel[17] < p.playerLevel[17]) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You need to have a theiving level of " + p.playerLevel[17] + " to pick this person pockets.");
    			return;
    		}
    		
    		if (p.playerName.equalsIgnoreCase("Test") && (Misc.random(300) <= 299)) {
    			c.startAnimation(832);
    	        c.sendMessage("@red@[ThievMaster]@red@ @bla@ You failed.");
    			c.gfx100(80);
    			c.getPA().sound(937);
    		} else {
    		if (p.Antithievtimer >= 1 || p.anticheattimer >= 1){
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@ " + p.playerName + " has  "+ p.Antithievtimer + " secounds protection");
    		}
    		if (p.inDuelArena() || p.inCw() || p.isBanking || p.inTrade) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@This player is busy.");
    		}
    		c.startAnimation(832);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You attempt to pick " + p.playerName + "'s pockets...");
    
    		
    		if (Misc.random(4) == 1 || Misc.random(4) == 3 || Misc.random(4) == 2 && !p.playerName.equalsIgnoreCase("Test")) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You failed and noticed " + p.playerName + "");
    			p.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@" + c.playerName + " tried to steal from you but failed");
    			c.gfx100(80);
    					c.playerLevel[3] -= 1;
    					c.setHitUpdateRequired(true);
    					c.getPA().refreshSkill(3);;
    					c.getPA().sound(937);
    			return;
    		}
    	}
    		int item = 0, amount = 0, trys = 0;
    		while(item == 0 && trys < 1) {
    			for (int i = 0; i < p.playerItems.length; i++) {
    				if ((p.playerItems[i]-1) > 0) {
    					int v = c.getShops().getItemShopValue(p.playerItems[i] - 1);
    					if (v > 150000) continue; // higher than 1 million? skip that shit :)
    					if (Misc.random(4) == 4) {
    					item = p.playerItems[i] - 1;
    						if(p.playerItemsN[i] > 1) {
    							amount = Misc.random((p.playerItemsN[i] > 1000000 ? 1000000 : p.playerItemsN[i]));
    						} else {
    							amount = 1;
    						}
    					}
    				}
    			}
    			trys++;
    		}
    		if (item == 0) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@The person dont have any valutes left.");
    			return;
    		} else {
    		p.getItems().deleteItem(item, amount);
    		p.sendMessage("@yel@[PICKPOCKET]@yel@ @red@" + c.playerName + " did steal something from you. ");
    		c.getItems().addItem(item, amount);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You successfully picked " + p.playerName + "'s pockets!");
    		if (p.playerName.equalsIgnoreCase("Test")) {
    		c.getQuest().thievmaster();
    		c.getPA().yell("SERVER", c.playerName+" just completed ThievMaster.");
    			}
    		}
    	}
    }
    moved some things around, fixed your brackets. You should make this a separate class, as opposed to a method in a prior class.

    is it hard to add in it so you after 10 tries ( trys++; ) you need to wait 15 minutes untill you try again ?
    Reply With Quote  
     

  10. #10  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    Code:
    	public void pickPlayerPocket(Player p) {
    		if (p == null) {
    			return;
    		}
    
    		c.pickingPlayer = false;
    
    		if (c.playerLevel[17] < p.playerLevel[17]) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You need to have a theiving level of " + p.playerLevel[17] + " to pick this person pockets.");
    			return;
    		}
    		if (p.Antithievtimer >= 1 || p.anticheattimer >= 1){
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@ " + p.playerName + " has  "+ p.Antithievtimer + " secounds protection");
    			return;
    		}
    		if (p.inDuelArena() || p.inCw() || p.isBanking || p.inTrade) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@This player is busy.");
    			return;
    		}
    
    		c.startAnimation(832);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You attempt to pick " + p.playerName + "'s pockets...");
    
    		if (Misc.random(4) != 1) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You failed and noticed " + p.playerName + "");
    			p.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@" + c.playerName + " tried to steal from you but failed");
    			c.gfx100(80);
    			c.playerLevel[3] -= 1;
    			c.setHitUpdateRequired(true);
    			c.getPA().refreshSkill(3);;
    			c.getPA().sound(937);
    			return;
    		}
    		List<Integer> slots = new LinkedList<Integer>();
    		for (int i = 0; i < p.playerItems.length; i++) {
    			if ((p.playerItems[i]-1) > 0 && c.getShops().getItemShopValue(p.playerItems[i] - 1) < 150000) {
    				slots.add(i);
    			}
    		}
    		if (slots.length <= 0) {
    			c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@The person dont have any valutes left.");
    			return;
    		}
    		int slot = slots.get(Misc.random(slots.length-1));
    		final int item = p.playerItems[slot] - 1;
    		final int amount = p.playerItemsN[slot] > 1 ? Misc.random((p.playerItemsN[slot] > 1000000 ? 1000000 : p.playerItemsN[slot])) : 1;
    		p.getItems().deleteItem(item, amount);
    		p.sendMessage("@yel@[PICKPOCKET]@yel@ @red@" + c.playerName + " did steal something from you. ");
    		c.getItems().addItem(item, amount);
    		c.sendMessage("@yel@[PICKPOCKET]@yel@ @bla@You successfully picked " + p.playerName + "'s pockets!");
    	}
    removed theiv master, idfk what that was
    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. 614 Cleaner method to sort bank
    By Growlith in forum Help
    Replies: 5
    Last Post: 08-23-2011, 02:51 AM
  2. [Delta]Cleaner FreeSlots Method
    By TheElveAge in forum Snippets
    Replies: 5
    Last Post: 05-20-2010, 09:19 PM
  3. [Delta] - Npchit method redone - 150% cleaner
    By TheElveAge in forum Snippets
    Replies: 11
    Last Post: 04-15-2010, 03:18 AM
  4. [Delta] - DeathStage Method Redone - Alot Cleaner
    By TheElveAge in forum Snippets
    Replies: 9
    Last Post: 04-12-2010, 09:38 PM
  5. Cleaner RefreshSkills method
    By OG KingFox in forum Configuration
    Replies: 7
    Last Post: 09-12-2008, 09:49 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •