blueFlagLoc will be the starting position of the flags in the red and blue base respectively.
redBaseCorner2 will be two opposite corners of a rectangle that spans the entrance to the red base. We know the red team has scored if a red player is holding the blue flag in that rectangle. The same is true for the blue base.
REMEMBER: Your values will be different for these locations!
redBaseCorner1 will be the front left block of the doorway one above the ground,
-210 84 296 in this example.
redBaseCorner2 will be one block behind the back right block of the doorway one above the ground to that the border surrounds a row of air blocks in back of the doorway,
-212 84 303 in this example.
You may notice that if a player gets hit while holding a flag, they don't drop it! We need to add that to our
onEntityDamageByEntity function before we can test returning the flag to base.
Remember to test this for BOTH teams. You may have a typo in one if-statement but not the other. Always test every possible scenario when checking your work!
isInRect() will return
true if the
player is inside the area bounded by
It works by sorting the X and Z values of the locations from low to high. Then, if the player's X position is greater than that of the higher X corner, we know the player is outside the rectangle and we return false. The same is true if the player's X position is lower than that of the lower X corner. We then do the same thing for the Z positions. If we make it past both of those checks without returning false, we know the player must be inside the rectangle and we return true.
Make sure to test flag capturing on BOTH teams. Capture the flag 3 times as each team to make sure both teams can win the game!