# Area Management

Before using the area interface, please create the area management object. The method is as follows:

local Area = class.Area.new()

The specific function name and description are as follows:

Serial number Function name Description
1 createAreaRect(...) Create a rectangular area
2 createAreaRectByRange(...) Create a rectangular area(through range) 1.1+
3 destroyArea(...) Destroy area
4 getAreaByPos(...) Find area via location
5 offsetArea(...) Area Offset
6 expandArea(...) Expand the area
7 getAreaCenter(...) Obtain the center point of the area
8 getAreaRectLength(...) Obtain the length of the area 1.1+
9 getAreaRectRange(...) Obtain the range of area 1.1+
10 getRandomPos(...) Location in random area
11 objInArea(...) detect if the object in the area
12 blockInArea(...) detect if the block in the area
13 posInArea(...) If location is in the area
14 getAreaPlayers(...) Obtain all players in area
15 getAreaCreatures(...) Obtain all creatures in area
16 fillBlock(...) Fill the area with blocks
17 clearAllBlock(...) Clear all the blocks in area
18 cloneArea(...) Clone the block in the area to another
19 getPosOffset(...) Position offset
20 replaceAreaBlock(...) Replace the old blocks with new ones
21 blockInAreaRange(...) When blocks exist in the area 1.5+
22 getAllObjsInAreaRange(...) Acquire all objectives in the area 1.5+
23 getAllObjsInAreaRangeByObjTypes(...) Acquire all objectives in the area 1.5+
24 getAllPlayersInAreaRange(...) Acquire all players in the area 1.5+
25 getAllCreaturesInAreaRange(...) Acquire all creatures in the area 1.5+
26 fillBlockAreaRange(...) Fill the area with blocks 1.5+
27 clearAllBlockAreaRange(...) Clear out blocks in the area 1.5+
28 cloneAreaRange(...) Clone the block in the area to another 1.5+
29 replaceAreaRangeBlock(...) Replace blocks in the area 1.5+

# createAreaRect

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Create a rectangular area
  • The specific use cases are as follows:
--Create an area by a center point and extended length
--The first parameter {x=0,y=10,z=0} is the table composed of the center coordinates of the area
--The second parameter {x=1,y=2,z=3} is a table composed of the distance extended in each direction of the area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=1,y=2,z=3})
--Show in chat box
Chat:sendSystemMsg("centered on(0,0) height 10,expanded by 1 grid on each side,2 grids on top and bottom,and 3 grids on front and back,creating an area with id "..areaid)

# createAreaRectByRange 1.1+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Create a rectangular area(through range)
  • The specific use cases are as follows:
--Create a region by starting and ending coordinates
--The first parameter is a table composed of the coordinates of the starting point of the area,that is,the coordinates of the vertices on the left,bottom,and rear of the area when facing north
--The second parameter is a table composed of the coordinates of the end point of the area,that is,the coordinates of the vertices on the right,top and front of the area when facing north
local result,areaid=Area:createAreaRectByRange({x=0,y=7,z=0},{x=5,y=10,z=5})
--Show in chat box
Chat:sendSystemMsg("Create an area with(0,0) height 7 as the starting point,(5,5) height 10 as the ending point,id is "..areaid)

# destroyArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Destroy area
  • The specific use cases are as follows:
--Destroy the specified area,the parameter is the area id
Area:destroyArea(1)
--Show in chat box
Chat:sendSystemMsg("Destroyed the area with id 1")

# getAreaByPos

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Find area via location
  • The specific use cases are as follows:
--To determine the area to which a coordinate belongs,the parameter is a table composed of coordinates
local result,areaid=Area:getAreaByPos({x=0,y=7,z=0})
if result==0 then--If the acquisition is successful
	--Show in chat box
	Chat:sendSystemMsg("(0,0) area id where height 7 is "..areaid)
else--if the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Failed to get,or(0,0) height 7 does not belong to any area")
end

# offsetArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Area Offset
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Pan area range
--The first parameter is the area id to be translated
--The last three parameters are the translation distance to the right,up and front,which can be negative
Area:offsetArea(areaid,5,5,5)
--Show in chat box
Chat:sendSystemMsg(the area with "id is "..areaid.." is moved 5 spaces to the right,top,and front")

# expandArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Expand the area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Expand the area
--The first parameter is the area id
--The last three parameters are the distance that the area expands to the left,right,top,and back
Area:expandArea(areaid,2,2,2)
--Show in chat box
Chat:sendSystemMsg("id is "..areaid.." the area is expanded by 2 grids to the left,right,top,bottom,and back")

# getAreaCenter

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the center point of the area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Get the center coordinates of the specified area,the parameter is the area id of the center to be obtained
local result,pos=Area:getAreaCenter(areaid)
--Show in chat box
Chat:sendSystemMsg("id is "..areaid.." area center coordinates are:("..pos.x..","..pos.y..","..pos.z..")")

# getAreaRectLength 1.1+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the length of the area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Get the side length of the specified area in all directions,the parameter is the area id
local result,x,y,z=Area:getAreaRectLength(areaid)
--Show in chat box
Chat:sendSystemMsg("id is "..areaid.." The side length of each direction of the area is:left and right "..x..",up and down "..y..",before and after "..z)

# getAreaRectRange 1.1+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the range of area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Get the coordinates of the start and end points of the specified area,the parameter is the area id
local result,posBeg,posEnd=Area:getAreaRectRange(areaid)
--Show in chat box
Chat:sendSystemMsg("id is "..areaid.." The starting point of the area is("..posBeg.x..","..posBeg.y..","..posBeg.z.."),the end point coordinates are("..posEnd.x..","..posEnd.y..","..posEnd.z..")")

# getRandomPos

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Location in random area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Randomly obtain a coordinate from the specified area,the parameter is the area id
local result,pos=Area:getRandomPos(areaid)
--Show in chat box
Chat:sendSystemMsg("A coordinate is randomly obtained from the area with id "..areaid.."("..pos.x..","..pos.y..","..pos.z..")")

# objInArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: detect if the object in the area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Determine whether an object is in the specified area
--The first parameter is the area id
--The second parameter is the object id,which can be the player's mini number,creature id or drop id,etc.
local result=Area:objInArea(areaid,1000)
if result==0 then--If in the area
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is in the area"..areaid.."Internal")
else--If it is not internal or the acquisition fails
	--Show in chat box
	Chat:sendSystemMsg("Player 1000 is not in the area".. areaid.. "Inside,or Player 1000 is not in the current archive")
end

# blockInArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: detect if the block in the area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Determine whether the specified area contains a certain square
--The first parameter is the area id
--The second parameter is the block id
local result=Area:blockInArea(areaid,101)
if result==0 then--if included
	--Show in chat box
	Chat:sendSystemMsg("id is "..areaid.." in the area of ​​soil")
else--if not included
	--Show in chat box
	Chat:sendSystemMsg("id is "..areaid.." there is no soil in the area")
end

# posInArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: If location is in the area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--determine whether a coordinate is within a specified area
--The first parameter is a table composed of coordinates to be judged
--The second parameter is the area id
local result=Area:posInArea({x=0,y=7,z=0},areaid)
if result==0 then--if inside
	--Show in chat box
	Chat:sendSystemMsg("(0,0) height 7 position is in the area with id "..areaid)
else--if not inside
	--Show in chat box
	Chat:sendSystemMsg("(0,0) height 7 position is not in the area with id "..areaid)
end

# getAreaPlayers

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain all players in area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Get the list of players in the area,the parameter is the area id
local result,playerlist=Area:getAreaPlayers(areaid)
if #playerlist>0 then--If there are players in the area
	for i,a in ipairs(playerlist) do
		--Display the list in the chat box
		Chat:sendSystemMsg("Area"..areaid.."Inside"..i.."Player:"..a)
	end
else--If there is no player in the area
	--Show in chat box
	Chat:sendSystemMsg("Area"..areaid.."There are no players")
end

# getAreaCreatures

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain all creatures in area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Get the list of creatures in the area,the parameter is the area id
local result,creaturelist=Area:getAreaCreatures(areaid)
if #creaturelist>0 then--If there are creatures in the area
	for i,a in ipairs(creaturelist) do
		--Display the list in the chat box
		Chat:sendSystemMsg("Area"..areaid.."Inside"..i.."A creature:"..a)
	end
else--if there are no creatures in the area
	--Show in chat box
	Chat:sendSystemMsg("Area"..areaid.."There are no creatures")
end

# fillBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Fill the area with blocks
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=3,y=3,z=3})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 3 squares to the left,right,top,bottom,back and forth,area ID is "..areaid)
--Fill the specified area with squares
--The first parameter is the area id
--The second parameter is the id of the block to be filled,1 is the bedrock
--The third parameter is the block orientation:0 West 1 East 2 South 3 North 4 Down 5 Up
Area:fillBlock(areaid,1,0)
--Show in chat box
Chat:sendSystemMsg("area".. areaid.. "filled with bedrock")

# clearAllBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Clear all the blocks in area
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Empty the specified block in the specified area
--The first parameter is the area id
--The second parameter is the block id to be cleared
Area:clearAllBlock(areaid,101)
--Show in chat box
Chat:sendSystemMsg("Clear All soil blocks in area"..areaid)

# cloneArea

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Clone the block in the area to another
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Copy the block in the area to another location
--The first parameter is the area id to be copied
--The second parameter is the table composed of the coordinates of the starting point to be copied to
Area:cloneArea(areaid,{x=0,y=10,z=0})
--Show in chat box
Chat:sendSystemMsg("Copy area"..areaid.." to a position of(0,0) height 10,this coordinate corresponds to the starting point of the area")

# getPosOffset

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Position offset
  • The specific use cases are as follows:
local result = Area:getPosOffset(srcpos, dim)

# replaceAreaBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Replace the old blocks with new ones
  • The specific use cases are as follows:
--Create an area
local result,areaid=Area:createAreaRect({x=0,y=10,z=0},{x=30,y=30,z=30})
--Show in chat box
Chat:sendSystemMsg("Create an area centered on(0,0) height 10,extending 30 squares to the left,right,top,bottom,back,and back,area id is "..areaid)
--Replace a block in the specified area with a new block
--The first parameter is the area id
--The second parameter is the id of the block to be replaced,101 is the soil block
--The third parameter is the id of the block to be replaced,1 is the foundation stone
--The last parameter is the block orientation:0 west 1 east 2 south 3 north 4 down 5 up
Area:replaceAreaBlock(areaid,101,1,0)
--Show in chat box
Chat:sendSystemMsg("Area"..areaid.."All the soil blocks are replaced with bedrock")

# blockInAreaRange 1.5+

  • Parameters and types:
    • blockid:number
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
  • Return value and types:
  • The main role of this method: When blocks exist in the area
  • The specific use cases are as follows:
--Determine whether there is a certain square in the range before two points
--The first parameter is the block id,101 is the soil block
--The last two parameters are the table composed of the start and end coordinates of the range
local result=Area:blockInAreaRange(101,{x=0,y=5,z=0},{x=1,y=8,z=1})
if result==0 then--if included
	--Show in chat box
	Chat:sendSystemMsg("There are clods in the range of(0,0) height 5 to(1,1) height 8")
else--if not included
	--Show in chat box
	Chat:sendSystemMsg("There is no clod within the range of(0,0) height 5 to(1,1) height 8")
end

# getAllObjsInAreaRange 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
    • objtypeidx:tableObject Type Index
  • Return value and types:
  • The main role of this method: Acquire all objectives in the area
  • The specific use cases are as follows:
local result = Area:getAllObjsInAreaRange(posbeg, posend, objtype)

# getAllObjsInAreaRangeByObjTypes 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
    • objtypeidxs:tableObject Type Index Array
  • Return value and types:
  • The main role of this method: Acquire all objectives in the area
  • The specific use cases are as follows:
local result = Area:getAllObjsInAreaRangeByObjTypes(posbeg, posend, objtypes)

# getAllPlayersInAreaRange 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
  • Return value and types:
  • The main role of this method: Acquire all players in the area
  • The specific use cases are as follows:
local result = Area:getAllPlayersInAreaRange(posbeg, posend)

# getAllCreaturesInAreaRange 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
  • Return value and types:
  • The main role of this method: Acquire all creatures in the area
  • The specific use cases are as follows:
local result = Area:getAllCreaturesInAreaRange(posbeg, posend)

# fillBlockAreaRange 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
    • blockid:numberBlock ID
    • face:numberDirection
  • Return value and types:
  • The main role of this method: Fill the area with blocks
  • The specific use cases are as follows:
--Fill a square in the range between two points
--The first two parameters are the table composed of the start and end coordinates of the filling range
--The third parameter 1 is the id of the block to be filled,and 1 is the foundation stone
--The fourth parameter 0 is the block orientation:0 west 1 east 2 south 3 north 4 down 5 up
Area:fillBlockAreaRange({x=0,y=7,z=0},{x=5,y=9,z=5},1,0)
--Show in chat box
Chat:sendSystemMsg("The range from(0,0) height 7 to(5,5) height 9 is filled with bedrock")

# clearAllBlockAreaRange 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
    • blockid:numberBlock ID
  • Return value and types:
  • The main role of this method: Clear out blocks in the area
  • The specific use cases are as follows:
--Clear a block in the range between two points
--The first two parameters are the table composed of the coordinates of the start and end of the range
--The third parameter is the id of the block to be cleared,101 is the soil block
Area:clearAllBlockAreaRange({x=0,y=7,z=0},{x=5,y=9,z=5},101)
--Show in chat box
Chat:sendSystemMsg("Empty clods in the range of(0,0) height 7 to(5,5) height 9")

# cloneAreaRange 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
    • deststartpos:tableTarget starting position {x=number, y=number, z=number}
  • Return value and types:
  • The main role of this method: Clone the block in the area to another
  • The specific use cases are as follows:
--Copy the block in the range between two points to another location
--The first two parameters are the table composed of the coordinates of the start and end of the range
--The latter parameter is the starting point coordinate of the range to be copied to
Area:cloneAreaRange({x=0,y=3,z=0},{x=5,y=7,z=5},{x=0,y=10,z=0})
--Show in chat box
Chat:sendSystemMsg("Copy the blocks in the range of(0,0) height 3 to(5,5) height 7 to(0,0) height 10(take this as the starting point)")

# replaceAreaRangeBlock 1.5+

  • Parameters and types:
    • posbeg:tableStarting point{x=number, y=number, z=number}
    • posend:tableEnd point{x=number, y=number, z=number}
    • srcblockid:numberReplace the original blocks
    • destblockid:numberReplace the target blocks
    • face:numberDirection
  • Return value and types:
  • The main role of this method: Replace blocks in the area
  • The specific use cases are as follows:
--Replace one block in the range between two points with another block
--The first two parameters are the table composed of the coordinates of the start and end of the range
--The third parameter 101 is the id of the block to be replaced,101 is the soil block
--The fourth parameter is the block id to be replaced,and 1 is the foundation stone
--The last parameter is the block orientation:0 west 1 east 2 south 3 north 4 down 5 up
Area:replaceAreaRangeBlock({x=0,y=3,z=0},{x=5,y=7,z=5},101,1,0)
--Show in chat box
Chat:sendSystemMsg("From(0,0) height 3 to(5,5) height 7 range,all soil blocks are replaced with bedrock")
Last Update: 6/11/2020, 9:30:46 PM