-
-
Notifications
You must be signed in to change notification settings - Fork 6
Creating a Region
skript-worldguard allows you to create the three region types provided by WorldGuard: global regions, cuboid regions, and polygonal regions. On this page, we will cover how you can create each of those regions.
Global regions cover entire worlds. As a result, they are the simplest to create. All you need is a name (also referred to as "ID") and a world.
Tip
Not sure what counts as a valid region ID? Read up on Region IDs at the end of this page!
The syntax for creating a global region is:
create [a] [temporary] global [worldguard] region [named] %string% [in %world%]
Note
If you create a temporary
region, the region will be deleted when the server restarts.
While the syntax looks long, it is simple to put together. Let's say you wanted to make a simple command for an admin to create a global region. Consider the following code (see the end of this page) that sends a message if the first argument is not a valid region name:
command /createregion <text>:
trigger:
if arg-1 is not a valid region id:
send "<red>Region IDs may only contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, forward slashes." to player
Now, with this syntax, we can complete this command:
command /createregion <text>:
trigger:
if arg-1 is not a valid region id:
send "<red>Region IDs may only contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, forward slashes." to player
else:
create a global region named arg-1 in the player's world
After running this command with the argument custom_global_region
, you can see a new region appears in WorldGuard's region list command.
Here's what it looks like in-game:
Cuboid regions are the typical region type most are familiar with. It has two corner points that form a box. While more information is required to create cuboid regions, it is still quite simple.
The syntax for creating a cuboid region is:
create [a] [:temporary] [cuboid|rectangular] [worldguard] region [named] %string% [in %-world%] (between|from) %location% (to|and) %location%
Tip
You may have noticed that you don't need to specify a world. This is because the location parameters may already contain a world. If you are sure the locations you are using in the effect have a world, you do not need to specify it. It is important that both locations have the same world too. If the world of the two locations do not match, or if they do not have a world, the effect will error.
Let's revisit the command from above. This time though, we can use the cuboid region syntax instead of the global region syntax. It might look something like this:
command /createregion <text>:
trigger:
if arg-1 is not a valid region id:
send "<red>Region IDs may only contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, forward slashes." to player
else:
create a cuboid region named arg-1 between {point1::%player's uuid%} and {point2::%player's uuid%}
This command could be combined with another to set {point1::%player's uuid%}
and {point2::%player's uuid%}
to different locations.
Last up is the polygonal region. These are the most complicated regions WorldGuard offers, as they are not limited to just a box. Polygonal regions are made up of many points, which allows the user to create some interestingly shaped regions. Essentially, points are viewed on a two-dimensional plane (x/z components). The shape formed by these points shapes the region. Then, the provided minimum and maximum heights (y-components) are used to stretch the region vertically. Every polygonal region has at least three points.
Most importantly, the syntax for creating a polygonal region is:
create [a] [:temporary] polygonal [worldguard] region [named] %string% [in %-world%] [with [a] min[imum] height of %-integer% and [a] max[imum] height of %-integer%] with [the] points %locations%
Just like cuboid regions, polygonal regions do not require a world to be specified as long as every point shares the same world. However, there is some additional information now required. Since polygonal regions have many points, you are required to supply a list of them (at least three). There is also the option of specifying the minimum and maximum height of the region. If these heights are not specified, they will instead be calculated from the provided points.
Once again referencing the command from above, we can fill out this syntax. We will expand it to support new arguments for our minimum and maximum height values. It might look something like:
command /createregion <text> <number> <number>:
trigger:
if arg-1 is not a valid region id:
send "<red>Region IDs may only contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, forward slashes." to player
else:
create a polygonal region named arg-1 with a minimum height of arg-2 and a maximum height of arg-3 with the points {points::*}
command /addpoint:
trigger:
add player's location to {points::*}
The points list would be a list of the points for this region. You could make a command that adds the player's current location to the list, like the one shown above. If the points list contains less than three points, the effect will fail.
Here is an example of some points that will make up a polygonal region:
In-game, with the region created and filled in, it looks like:
It is easy to see how polygonal regions can be used to create more precise zones.
WorldGuard has restrictions on what characters can and cannot be used in a region name (also referred to as "region ID"). Currently, only the following characters may be in a region name:
- Letters
- Numbers
- Underscores
- Commas
- Single Quotation Marks
- Dashes
- Pluses
- Forward Slashes
That means characters like percentage signs, parentheses, and colons are not valid.
What if you wanted to make a custom command that lets users create a new region? While you could give access to WorldGuard's built in command, you could have far greater control by using Skript. If a user is going to be naming a region, you will want to provide an error message if the name they give is invalid. You could just check against these requirements yourself, but what if they change in the future? You would have to make sure your script is always up to date.
While this probably is not a situation many people are going to have, it is still useful to provide a utility for those that will. skript-worldguard offers a condition to check if a string is a valid region name (or ID). The syntax for this condition is:
%strings% (is|are) [a] valid [worldguard] region id
%strings% (isn't|is not|aren't|are not) [a] valid [worldguard] region id
If you wanted to use this in a command, it could look something like:
command /createregion <text>:
trigger:
if arg-1 is not a valid region id:
send "<red>Region IDs may only contain letters, numbers, underscores, commas, single quotation marks, dashes, pluses, forward slashes." to player
So, if the user entered an invalid region ID, they would get an error message telling them what characters are allowed in a region ID. Even if the characters allowed in a region ID changed in the future, only the message would be incorrect. The command would still prevent users from entering an invalid region ID.
If you were to enter an invalid region ID, here's what it would look like in-game:
That is about all there is to creating regions with skript-worldguard. Make sure to check out the other pages listed in the sidebar to learn about what you can do with your brand new regions!