# World Management

Before using world management API, create a world management object is required, as below:

local World = class.World.new()

The specific function name and description are as follows:

Serial number Function name Description
1 isDaytime(...) Whether it is daytime
2 isCustomGame(...) Whether it is customize game
3 isCreativeMode(...) Whether it is creation mode
4 isGodMode(...) Multiplayer Creation Mode or Dev Mode-Edit
5 isExtremityMode(...) Extreme mode
6 isFreeMode(...) Survival mode - Free mode
7 isSurviveMode(...) Single Player or Survival mode-free
8 isCreateRunMode(...) Survival mode turned from creation mode
9 isGameMakerMode(...) Customized edit mode
10 isGameMakerRunMode(...) Customized operate mode
11 getHours(...) Current time(h)
12 setHours(...) Setup game current time(h)
13 getCameraEditState(...) Obtain view editing state
14 setCameraEditState(...) Set view editing state
15 getCustomCameraConfig(...) Obtain customized camera configuration
16 getRangeXZ(...) Acquire chunk range, return chunk start and end location
17 getRayLength(...) Calculate the length of the ray in the specified direction(ends when hit block)
18 getRayBlock(...) Type of block hit by ray(ends when hit block)
19 getActorsByBox(...) Acquire actor within area, type reference to OBJ_TYPE, 0 means all actor within area, return numbers and objid array
20 getPlayerTotal(...) Acquire number of all players, default all players
21 getAllPlayers(...) Acquire all players, can limit survival state(0survive, 1dead),default all players
22 randomOnePlayer(...) Acquire a random player
23 despawnActor(...) Remove actor
24 spawnCreature(...) Generate creature(including monster, NPC, animals etc.)
25 despawnCreature(...) Remove creature
26 spawnItem(...) Generate items in designate location
27 despawnItemByBox(...) Remove items(By region)
28 despawnItemByObjid(...) Remove item(By ID)
29 spawnProjectile(...) Generate Projectile
30 spawnProjectileByDir(...) Generate Projectile(Direction of passage)
31 calcDistance(...) Calculate the distance between locations
32 playParticalEffect(...) Play effect in designate location 1.2+
33 stopEffectOnPosition(...) Stop effect in designate location 1.2+
34 setEffectScaleOnPosition(...) Set up effect size in designate location 1.2+
35 randomParticleEffectID(...) Random effect type, returns a random effect ID 1.2+
36 playSoundEffectOnPos(...) Play the specified sound effect in designate location 1.3+
37 stopSoundEffectOnPos(...) Play the specified sound effect in designate location 1.3+

# isDaytime

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Whether it is daytime
  • The specific use cases are as follows:
--Determine whether it is daytime
local result=World:isDaytime()
if result==0 then--If it is daytime
	Chat:sendSystemMsg("It's daytime now!")
else--if it is not daytime
	Chat:sendSystemMsg("Now is night!")
end

# isCustomGame

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Whether it is customize game
  • The specific use cases are as follows:
--Determine whether it is a custom game
local result=World:isCustomGame()
if result==0 then--If it is customized
	Chat:sendSystemMsg("Currently a custom game!")
else--if not customized
	Chat:sendSystemMsg("Not currently a custom game!")
end

# isCreativeMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Whether it is creation mode
  • The specific use cases are as follows:
--judge whether it is a creative mode
local result=World:isCreativeMode()
if result==0 then--if it is a creative mode
	Chat:sendSystemMsg("Currently,it is a creative mode!")
else--if not in creative mode
	Chat:sendSystemMsg("Currently not a creative mode!")
end

# isGodMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Multiplayer Creation Mode or Dev Mode-Edit
  • The specific use cases are as follows:
--Determine whether it is multiplayer creation mode or gameplay editing mode
local result=World:isGodMode()
if result==0 then--If it is created by multiple people or edited by gameplay
	Chat:sendSystemMsg("Currently multiplayer creation or gameplay editing mode!")
else--if not
	Chat:sendSystemMsg("Currently not a multiplayer creation or gameplay editing mode!")
end

# isExtremityMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Extreme mode
  • The specific use cases are as follows:
--judge whether it is the limit mode
local result=World:isExtremityMode()
if result==0 then--If it is the limit mode
	Chat:sendSystemMsg("Currently Extreme Mode!")
else--if not the limit mode
	Chat:sendSystemMsg("Currently not a limit mode!")
end

# isFreeMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Survival mode - Free mode
  • The specific use cases are as follows:
--Determine whether it is an adventure free mode
local result=World:isFreeMode()
if result==0 then--If it is adventure free mode
	Chat:sendSystemMsg("Currently Adventure Free Mode!")
else--if not
	Chat:sendSystemMsg("Currently not an adventure free mode!")
end

# isSurviveMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Single Player or Survival mode-free
  • The specific use cases are as follows:
--Determine whether it is a single-person survival mode
local result=World:isSurviveMode()
if result==0 then--If it is single player survival mode
	Chat:sendSystemMsg("Currently single player survival mode!")
else--if it is not a single player survival mode
	Chat:sendSystemMsg("Currently not a single player survival mode!")
end

# isCreateRunMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Survival mode turned from creation mode
  • The specific use cases are as follows:
--Judge whether to create a survival mode
local result=World:isCreateRunMode()
if result==0 then--if it is to create a survival mode
	Chat:sendSystemMsg("Currently,create to survive mode!")
else--if not to create a survival mode
	Chat:sendSystemMsg("Currently not a creation-to-survival mode!")
end

# isGameMakerMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Customized edit mode
  • The specific use cases are as follows:
--Determine whether it is a gameplay editing mode
local result=World:isGameMakerMode()
if result==0 then--If it is gameplay editing mode
	Chat:sendSystemMsg("Currently is the gameplay editing mode!")
else--if not in gameplay editing mode
	Chat:sendSystemMsg("Currently not in gameplay editing mode!")
end

# isGameMakerRunMode

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Customized operate mode
  • The specific use cases are as follows:
--Determine whether it is a gameplay mode
local result=World:isGameMakerRunMode()
if result==0 then--If it is the gameplay mode
	Chat:sendSystemMsg("Currently is the gameplay mode!")
else--if it is not a gameplay mode
	Chat:sendSystemMsg("Currently not a gameplay mode!")
end

# getHours

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Current time(h)
  • The specific use cases are as follows:
--Get the current time
local result,time=World:getHours()
--Show in chat box
Chat:sendSystemMsg("It is now "..time.."point!")

# setHours

  • Parameters and types:
    • hour:intHour time
  • Return value and types:
  • The main role of this method: Setup game current time(h)
  • The specific use cases are as follows:
--Set the time to 8 o'clock
World:setHours(8)
--Show in chat box
Chat:sendSystemMsg("Time is set to 8 o'clock!")

# getCameraEditState

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Obtain view editing state
  • The specific use cases are as follows:
--Get the current viewing angle editing status
local result,state=World:getCameraEditState()
if state==0 then--0:default
	Chat:sendSystemMsg("The current view editing state is:default")
elseif state==1 then--1:editing
	Chat:sendSystemMsg("The current perspective editing status is:editing")
elseif state==2 then--2:testing
	Chat:sendSystemMsg("Current perspective editing status is:testing")
end

# setCameraEditState

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set view editing state
  • The specific use cases are as follows:
local result = World:setCameraEditState(state)

# getCustomCameraConfig

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Obtain customized camera configuration
  • The specific use cases are as follows:
local result = World:getCustomCameraConfig()

# getRangeXZ

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Acquire chunk range, return chunk start and end location
  • The specific use cases are as follows:
--Get block range
local result,startX,startZ,endX,endZ=World:getRangeXZ()
Chat:sendSystemMsg("Block start abscissa:"..startX)
Chat:sendSystemMsg("vertical coordinate of the starting point of the block:"..startZ)
Chat:sendSystemMsg("Block end abscissa:"..endX)
Chat:sendSystemMsg("vertical coordinate of block end point:"..endZ)

# getRayLength

  • Parameters and types:
    • srcx,srcy,srcz:numberStart point
    • dstx,dsty,dstz:numberEnd point
    • distance:numberMax distance
  • Return value and types:
  • The main role of this method: Calculate the length of the ray in the specified direction(ends when hit block)
  • The specific use cases are as follows:
local result = World:getRayLength(srcx, srcy, srcz, dstx, dsty, dstz, distance)

# getRayBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Type of block hit by ray(ends when hit block)
  • The specific use cases are as follows:
--Get the id of the first block encountered within 50 squares north from (0,0) height 10
--Direction parameters:0 West 1 East 2 South 3 North 4 Down 5 Up
local result,blockid=World:getRayBlock(0,10,0,3,50)
if id==-1 then--if there are no squares within 50 squares
	Chat:sendSystemMsg("From(0,0) height 10,50 blocks to the north without squares")
else--if there are blocks within 50 squares
	Chat:sendSystemMsg("From(0,0) height 10,the first block id 50 blocks north is "..blockid)
end

# getActorsByBox

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Acquire actor within area, type reference to OBJ_TYPE, 0 means all actor within area, return numbers and objid array
  • The specific use cases are as follows:
--parameter:
local objtype=1--Type parameter:0 all 1 player 2 creature 3 drop 4 throwing object
local x1,y1,z1=0,7,0--the coordinates of the starting point of the area
local x2,y2,z2=50,57,50--region end point coordinates
--Get the number and list of items of type type within the range of (x0,z0) height y0 to (x1,z1) height y1
local result,num,objids=World:getActorsByBox(objtype,x1,y1,z1,x2,y2,z2)
--Display number in chat box
Chat:sendSystemMsg("Total in total"..num.."players")
--Display the list in the chat box
for i,a in ipairs(objids) do
	Chat:sendSystemMsg("第"..i.."个:"..a)
end

# getPlayerTotal

  • Parameters and types:
    • alive:number0 means being killed, 1 means survival, default-1 means all the players
  • Return value and types:
  • The main role of this method: Acquire number of all players, default all players
  • The specific use cases are as follows:
--Get the total number of players currently archived
local result,num=World:getPlayerTotal(-1)
Chat:sendSystemMsg("The total number of players currently archived are:"..num)
--Get the current number of players killed in the archive
result,num=World:getPlayerTotal(0)
Chat:sendSystemMsg("The current number of players in archive are:"..num)
--Get the number of players currently in the archive
result,num=World:getPlayerTotal(1)
Chat:sendSystemMsg("The current number of players on file are:"..num)

# getAllPlayers

  • Parameters and types:
    • alive:number0 means being killed, 1 means survival, default-1 means all the players
  • Return value and types:
  • The main role of this method: Acquire all players, can limit survival state(0survive, 1dead),default all players
  • The specific use cases are as follows:
--Get a list of all players currently archived
--Parameters:-1 all players 0 dead players 1 surviving players
local result,num,array=World:getAllPlayers(-1)
--Display number in chat box
Chat:sendSystemMsg("The current archive has a total of..numplayers")
--Display the list in the chat box
for i,a in ipairs(array) do
	Chat:sendSystemMsg("第"..i.."个:"..a)
end

# randomOnePlayer

  • Parameters and types:
    • alive:number0 means being killed, 1 means survival, default-1 means all the players
  • Return value and types:
  • The main role of this method: Acquire a random player
  • The specific use cases are as follows:
--randomly select a player from all players
--Parameters:-1 all players 0 dead players 1 surviving players
local result,playerid=World:randomOnePlayer(-1)
--Show in chat box
Chat:sendSystemMsg("randomly selected a player:"..playerid)

# despawnActor

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove actor
  • The specific use cases are as follows:
--parameter:
local type=2--type parameter:1 player 2 creature 3 drop 4 throwing object
local x0,y0,z0=0,7,0--the coordinates of the starting point of the area
local x1,y1,z1=50,57,50--the coordinates of the end point of the area
--Get the number and list of items of type type within the range of (x0,z0) height y0 to (x1,z1) height y1
local result,n,actors=World:getActorsByBox(type,x0,y0,z0,x1,y1,z1)
if n>0 then--If the number of creatures in the range is greater than 0
	--Remove one of the creatures
	World:despawnActor(actors[1])
	--Show in chat box
	Chat:sendSystemMsg("removed".. actors[1])
else--if there are no creatures in range
	--Show in chat box
	Chat:sendSystemMsg("There are no creatures in the range from(0,7,0) to(50,57,50)")
end

# spawnCreature

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Generate creature(including monster, NPC, animals etc.)
  • The specific use cases are as follows:
--Generate 3 chickens at (0,0) height 7
--The first three parameters 0,7,0 are generated coordinates
--The fourth parameter 3400 is the generated biological id
--The last parameter 3 is the number generated
local result,objids=World:spawnCreature(0,7,0,3400,3)
--Display a prompt in the chat box
Chat:sendSystemMsg("3 chickens were generated at the position of(0,0) height 7 and their id in the archive are:")
--Display id list in chat box
for i=1,#objids do
	Chat:sendSystemMsg(objids[i])
end

# despawnCreature

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove creature
  • The specific use cases are as follows:
--parameter:
local type=2--type parameter:1 player 2 creature 3 drop 4 throwing object
local x0,y0,z0=0,7,0--the coordinates of the starting point of the area
local x1,y1,z1=50,57,50--the coordinates of the end point of the area
--Get the number and list of items of type type within the range of (x0,z0) height y0 to (x1,z1) height y1
local result,n,actors=World:getActorsByBox(type,x0,y0,z0,x1,y1,z1)
if n>0 then--If the number of creatures in the range is greater than 0
	--Remove one of the creatures
	World:despawnCreature(actors[1])
	--Show in chat box
	Chat:sendSystemMsg("removed".. actors[1])
else--if there are no creatures in range
	--Show in chat box
	Chat:sendSystemMsg("There are no creatures in the range from(0,7,0) to(50,57,50)")
end

# spawnItem

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Generate items in designate location
  • The specific use cases are as follows:
--Generate 3 clods at (0,0) height 7
--The first three parameters 0,7,0 are generated coordinates
--The fourth parameter 101 is the generated item id
--The last parameter 3 is the number generated
local result,objid=World:spawnItem(0,7,0,101,3)
--Display a prompt in the chat box
Chat:sendSystemMsg("3 clods were generated at the position of(0,0) height 7 and their id in the archive is "..objid)

# despawnItemByBox

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove items(By region)
  • The specific use cases are as follows:
--Remove all drops in the designated area
--The first three parameters are the coordinates of the starting point of the area
--The last three parameters are the coordinates of the end point of the area
World:despawnItemByBox(-20,0,-20,20,50,20)
--Show in chat box
Chat:sendSystemMsg("Remove all drops from(-20,0,-20) to(20,50,20)")

# despawnItemByObjid

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove item(By ID)
  • The specific use cases are as follows:
--Whenever a player makes an animated expression,remove a drop within 10 squares around the owner
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Get the coordinates of the homeowner
	local result,x,y,z=Player:getPosition(0)
	--Get the number and list of drops within 10 blocks around the homeowner
	local result2,num,list=World:getActorsByBox(3,x-10,y-10,z-10,x+10,y+10,z+10)
	if num>0 then--if there is a drop
		--Remove the first set of items
		World:despawnItemByObjid(list[1])
		--Show in chat box
		Chat:sendSystemMsg("10 items found nearby,one group has been removed")
	else--if there is no drop
		--Show in chat box
		Chat:sendSystemMsg("No items found in 10 nearby blocks!")
	end
end
--Register animation expression listener,execute the above function when the player makes animation expression
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# spawnProjectile

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Generate Projectile
  • The specific use cases are as follows:
local result = World:spawnProjectile(shooter, itemid, x, y, z, dstx, dsty, dstz, speed)

# spawnProjectileByDir

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Generate Projectile(Direction of passage)
  • The specific use cases are as follows:
local result = World:spawnProjectileByDir(shooter, itemid, x, y, z, dirx, diry, dirz, speed)

# calcDistance

  • Parameters and types:
    • pos1:tableStarting point{x,y,z}
    • pos2:tableEnding point{x,y,z}
  • Return value and types:
  • The main role of this method: Calculate the distance between locations
  • The specific use cases are as follows:
--Calculate the straight line distance between two points
--The first parameter is a table consisting of starting point coordinates
--The second parameter is a table consisting of end point coordinates
local result,distance=World:calcDistance({x=0,y=0,z=0},{x=10,y=10,z=10})
--Show in chat box
Chat:sendSystemMsg("(0,0) height 0 to(10,10) height 10 linear distance is "..distance)

# playParticalEffect 1.2+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Play effect in designate location
  • The specific use cases are as follows:
--Play the smoke effect at the position of (0,0) height 7
--The first three parameters are the position coordinates of the special effects
--The fourth parameter is the special effect id of the special effect,which can be viewed in the "Special Effect Table Data" of "Mini World ID Query"
--The last parameter is the scaling of the special effect
World:playParticalEffect(0,7,0,1001,1)
--Show in chat box
Chat:sendSystemMsg("A smoke effect was generated at(0,0) height 7")

# stopEffectOnPosition 1.2+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Stop effect in designate location
  • The specific use cases are as follows:
--Stop the specified special effects at the specified location
--The first three parameters are the position coordinates to stop playing the special effect
--The last parameter is the special effect id that needs to be stopped
World:stopEffectOnPosition(0,7,0,1001)
--Show in chat box
Chat:sendSystemMsg("Stop the 1001 smoke effect at(0,0) height 7 position")

# setEffectScaleOnPosition 1.2+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set up effect size in designate location
  • The specific use cases are as follows:
--Zoom the specified special effect of the specified position
--The first three parameters are the coordinates that need to be scaled
--The fourth parameter is the special effect id that needs to be scaled
--The last parameter is the set zoom ratio
World:setEffectScaleOnPosition(0,7,0,1001,2)
--Show in chat box
Chat:sendSystemMsg("double the smoke effect at(0,0) height 7 position doubled")

# randomParticleEffectID 1.2+

  • Parameters and types:none
  • Return value and types:
  • The main role of this method: Random effect type, returns a random effect ID
  • The specific use cases are as follows:
--Get a random special effect id
local result,id=World:randomParticleEffectID()
--Show in chat box
Chat:sendSystemMsg("Obtained a random special effect id:"..id)

# playSoundEffectOnPos 1.3+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Play the specified sound effect in designate location
  • The specific use cases are as follows:
--Play music at (0,0) height 7 position 10713
--The first parameter is a table composed of the coordinates of playing music
--The second parameter 10713 is the sound effect id to be played,which can be viewed in the "Sound Effect Table Data" of "Mini World ID Query"
--The last three parameters are:volume,pitch,whether to loop playback
World:playSoundEffectOnPos({x=0,y=7,z=0},10713,100,1,false)
--Show in chat box
Chat:sendSystemMsg("(0,0) height 7 is playing music")

# stopSoundEffectOnPos 1.3+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Play the specified sound effect in designate location
  • The specific use cases are as follows:
--Play music at (0,0) height 7 position 10713
World:playSoundEffectOnPos({x=0,y=7,z=0},10713,100,1,false)
--Display a prompt in the chat box
Chat:sendSystemMsg("(0,0) height 7 position is playing music,animating can stop playing")
--This function is executed when the player makes an animated expression
local function Player_PlayAction(event)
	--Stop (0,0) height 7 position music 10713 playing
	--The first parameter is a table composed of coordinates to stop playing music
	--The second parameter is the music id to stop playing,which can be viewed in the "Sound Effect Table Data" of "Mini World ID Query"
	World:stopSoundEffectOnPos({x=0,y=7,z=0},10713)
	--Show in chat box
	Chat:sendSystemMsg("Stop playing of(0,0) height 7 music 10713")
end
--Register an animated expression listener,execute the above function when the event occurs
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)
Last Update: 6/11/2020, 9:30:46 PM