Thread: Remove all objects in a given area

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 Remove all objects in a given area 
    Registered Member
    MerzA's Avatar
    Join Date
    Jul 2008
    Age
    27
    Posts
    592
    Thanks given
    36
    Thanks received
    28
    Rep Power
    95
    I just threw this together, and I know it's done sloppily, but it works 100% correctly

    Feel free to revise and repost if you can clean it up a bit

    EDIT
    Revised code after help from Kataang

    Code:
    public static void removeAreaObjects(int areaTopLeftX, int areaTopLeftY, int areaBottomRightX, int areaBottomRightY) {
    	for(int x = areaTopLeftX; x <= areaBottomRightX; x++) {
    		for(int y = areaBottomRightY; y <= areaTopLeftY; y++) {
    			ReplaceObject(x, y, 6951, -1, 10);
    		}
    	}
    }
    Here's the original if anyone wants

    Code:
    public void removeAreaObjects(int areaTopLeftX, int areaTopLeftY, int areaBottomRightX, int areaBottomRightY) { //Made by MerzA
    	areaTopLeftY+=2;
    	int replaceX = 0, replaceY = 0, boundsX = areaBottomRightX - areaTopLeftX, boundsY = areaTopLeftY - areaBottomRightY, totalReplace = (areaBottomRightX - areaTopLeftX)*(areaTopLeftY - areaBottomRightY)+5;
    	
    	for (int replacing = (areaBottomRightX - areaTopLeftX)*(areaTopLeftY - areaBottomRightY) + 5; replacing > 0; replacing--) {
    	
    		if (boundsY >= 0) {
    		
    			if (boundsX >= 0) {
    			
    				replaceX = areaBottomRightX - boundsX;
    				replaceY = areaTopLeftY - boundsY;
    		
    			} else if (boundsX < 0) {
    				
    				boundsX = areaBottomRightX - areaTopLeftX;
    				boundsY--;
    				replaceX = areaBottomRightX - boundsX;
    				replaceY = areaTopLeftY - boundsY;
    			}
    		}
    			
    		ReplaceObject(areaBottomRightX - boundsX, areaTopLeftY - boundsY, 6951, -1, 10);
    		boundsX--;
    		//misc.println("Removing " + replaceX + ", " + replaceY + " - " + ((totalReplace-replacing) + 1) + "/"+ totalReplace);
    	
    	}
    }
    Put the methods with your defined parameters wherever you create or destroy global objects (heck you can even throw them all in your case 121 if you want)

    If you use this, please post :]

    NOTE: I would only use this for small areas where objects are located side by side in a grid (ie fields of cabbage?). Using this in areas with excessive empty tiles is unadvised
    Last edited by MerzA; 12-13-2010 at 04:30 AM. Reason: Commented out the println line, that was used for testing :]
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Aug 2008
    Posts
    2,823
    Thanks given
    362
    Thanks received
    447
    Rep Power
    965
    ...Why?

    Code:
    for(int x = startingX; x < endingX; x++) {
         for(int y = startingY; y < endingY; y++) {
              ReplaceObject(x, y, 6951, -1, 10);
         }
    }
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Donator

    Seba's Avatar
    Join Date
    Sep 2009
    Age
    26
    Posts
    360
    Thanks given
    50
    Thanks received
    25
    Rep Power
    120
    Nice man.
    Reply With Quote  
     

  5. #4  
    Registered Member
    MerzA's Avatar
    Join Date
    Jul 2008
    Age
    27
    Posts
    592
    Thanks given
    36
    Thanks received
    28
    Rep Power
    95
    Thanks bro
    Reply With Quote  
     

  6. #5  
    Banned
    Join Date
    Nov 2010
    Posts
    550
    Thanks given
    32
    Thanks received
    10
    Rep Power
    0
    area.
    Code:
    ifObject(existX, existY) { //in the designated are
    inArea = true; //statement
    ReplaceObject(blah, -1, 10); //replaces the object
    /thread
    People really need to cut there codes down. Making "long" codes like this will jam pack your client.java, next thing you know its 1mb.
    Reply With Quote  
     

  7. #6  
    Registered Member

    Join Date
    Aug 2008
    Posts
    2,823
    Thanks given
    362
    Thanks received
    447
    Rep Power
    965
    Quote Originally Posted by MT View Post
    area.
    Code:
    ifObject(existX, existY) { //in the designated are
    inArea = true; //statement
    ReplaceObject(blah, -1, 10); //replaces the object
    /thread
    People really need to cut there codes down. Making "long" codes like this will jam pack your client.java, next thing you know its 1mb.
    Do you even know what he's doing with his code? He's making it so all the objects within the X and Y coords he specifies are deleted...
    Reply With Quote  
     

  8. #7  
    Registered Member
    MerzA's Avatar
    Join Date
    Jul 2008
    Age
    27
    Posts
    592
    Thanks given
    36
    Thanks received
    28
    Rep Power
    95
    Quote Originally Posted by MT View Post
    area.
    Code:
    ifObject(existX, existY) { //in the designated are
    inArea = true; //statement
    ReplaceObject(blah, -1, 10); //replaces the object
    /thread
    People really need to cut there codes down. Making "long" codes like this will jam pack your client.java, next thing you know its 1mb.

    Thanks for that :] I posted in requests asking for a boolean that would return true if there was an object at a certain tile, and you just gave it to me
    Reply With Quote  
     

  9. #8  
    Registered Member
    MerzA's Avatar
    Join Date
    Jul 2008
    Age
    27
    Posts
    592
    Thanks given
    36
    Thanks received
    28
    Rep Power
    95
    Sorry for double posting. I revised my original method after using what Kataang wrote

    Code:
    public static void removeAreaObjects(int areaTopLeftX, int areaTopLeftY, int areaBottomRightX, int areaBottomRightY) {
    	for(int x = areaTopLeftX; x <= areaBottomRightX; x++) {
    		for(int y = areaBottomRightY; y <= areaTopLeftY; y++) {
    			ReplaceObject(x, y, 6951, -1, 10);
    		}
    	}
    }
    Kataang you were off by one, you needed <= instead of <
    Reply With Quote  
     

  10. #9  
    Registered Member

    Join Date
    Aug 2008
    Posts
    2,823
    Thanks given
    362
    Thanks received
    447
    Rep Power
    965
    Ok thanks, I wrote it up freehand. Knew there was a mistake in there somewhere.
    Reply With Quote  
     

  11. #10  
    Banned

    Join Date
    Jan 2009
    Age
    28
    Posts
    2,662
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    Wtf...

    Edit the maps client side not server side.

    DeleteObject is only for firemaking (cant think of any other use's for it).

    and even fire's only allow a certain amount of fire's to die per cycle.
    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. [PI] Remove Objects [PI]
    By farmerscape in forum Help
    Replies: 6
    Last Post: 05-05-2012, 11:36 AM
  2. [317]Remove objects [317]
    By copycopy in forum Help
    Replies: 2
    Last Post: 07-08-2010, 02:34 AM
  3. How to add/remove objects
    By Avoid` in forum Help
    Replies: 2
    Last Post: 12-30-2009, 07:32 AM
  4. remove objects
    By inlogger in forum Help
    Replies: 2
    Last Post: 12-22-2009, 07:40 PM
  5. How do i remove objects?
    By ryannathans in forum Help
    Replies: 3
    Last Post: 03-25-2009, 08:43 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
  •