Creating a Square Area

Discussion in 'Plugin Development' started by Irantwomiles, Nov 3, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Irantwomiles

    I'm trying to work on a land claiming area. I was going to use two locations that I pick and then create the area that way but I don't really know how to do that. Any hints or nudges in the right direction would be appreciated.

    EDIT: I don't need a cube, the Y direction is not relevant in this case.
     
  2. Offline

    Lordloss

    Apart from the fact that tons of claiming plugins allready exist, i would simply store important information about the region in a config file. I.E. region-id, owner, location1, location2.
     
  3. Offline

    Irantwomiles

    Its not just a claiming plugin. What exactly do I do with the two locations. How do I loop through the blocks from those 2 locations to create a square?
     
  4. Offline

    Lordloss

    Now i got it. You need to put two for-loops together. In one, you begin with the lower x coordinate (from the 2 locations) and loop until it reaches the higher x coordinate. And the same with the z-coordinate.
    PHP:
    for (lowerXhigherXx++)
        for (
    lowerZhigherZz++)
     
  5. Offline

    DarkenCake

    maybe you should use Vectors...?
     
  6. Offline

    Irantwomiles

    Thats my main problem. How do I figure out which one is my lowest and highest? Players are going to be doing this on the fly so it's going to be a problem.

    EDIT: So this is what I want to do. Very much like factions claiming (except no chunks). I want to check if people are in a certain "claim" or region so I can do different things. I hope that made things easier to understand.
     
  7. Offline

    timtower Administrator Administrator Moderator

  8. Offline

    Irantwomiles

    where do I get that from?
     
  9. Offline

    timtower Administrator Administrator Moderator

    @Irantwomiles You have 2 locations right? Get the smallest x and z, get the biggest x and z from those locations.
    (if it wasn't y, always forget)
    Then you have 2 cornerpoints to loop through.
     
    Irantwomiles likes this.
  10. Offline

    Zombie_Striker

  11. Offline

    mythbusterma

    Irantwomiles likes this.
  12. Offline

    Irantwomiles

    k. I'll give it a try

    EDIT: So will it look something like this.

    Code:
    
    for(int x = 0; x< Math.max(loc1.x, loc2,x); x++) {
    for(int z = 0; z < Math.min(loc1.z, loc2.z); z++ {
    
    }
    }
     
  13. Offline

    mythbusterma

    @Irantwomiles

    That would work, yes. Assuming you were starting from zero, and you were going to the lowest values.

    Although I would think you mean to go from the minimum to the maximum, not zero to minimum.
     
    Irantwomiles likes this.
  14. Offline

    Irantwomiles

    oh, yes you're right. I have another question though, how would I check if a certain person is within this square?
     
  15. Offline

    mythbusterma

    @Irantwomiles

    Vectors have a method called "isInAABB" which will check that (just make sure they're at y =0 and y = 255 if you don't want to consider Y).
     
    Irantwomiles likes this.
  16. Offline

    Irantwomiles

    Ok thanks. I'll look into it tomorrow morning!
     
Thread Status:
Not open for further replies.

Share This Page