# 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+
38 getLightByPos(...) Get light intensity 1.7+
39 setBlockLightEx(...) Set light intensity 1.7+

# 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:
--判断现在是不是白天
local result=World:isDaytime()
if result==0 then--如果是白天
	Chat:sendSystemMsg("现在是白天!")
else--如果不是白天
	Chat:sendSystemMsg("现在是晚上!")
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:
--判断是不是自定义游戏
local result=World:isCustomGame()
if result==0 then--如果是自定义
	Chat:sendSystemMsg("当前是自定义游戏!")
else--如果不是自定义
	Chat:sendSystemMsg("当前不是自定义游戏!")
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:
--判断是不是创造模式
local result=World:isCreativeMode()
if result==0 then--如果是创造模式
	Chat:sendSystemMsg("当前是创造模式!")
else--如果不是创造模式
	Chat:sendSystemMsg("当前不是创造模式!")
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:
--判断是不是多人创造模式或者玩法编辑模式
local result=World:isGodMode()
if result==0 then--如果是多人创造或者玩法编辑
	Chat:sendSystemMsg("当前是多人创造或玩法编辑模式!")
else--如果不是
	Chat:sendSystemMsg("当前不是多人创造或玩法编辑模式!")
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:
--判断是不是Extreme mode
local result=World:isExtremityMode()
if result==0 then--如果是Extreme mode
	Chat:sendSystemMsg("当前是Extreme mode!")
else--如果不是Extreme mode
	Chat:sendSystemMsg("当前不是Extreme 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:
--判断是不是冒险自由模式
local result=World:isFreeMode()
if result==0 then--如果是冒险自由模式
	Chat:sendSystemMsg("当前是冒险自由模式!")
else--如果不是
	Chat:sendSystemMsg("当前不是冒险自由模式!")
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:
--判断是不是单人生存模式
local result=World:isSurviveMode()
if result==0 then--如果是单人生存模式
	Chat:sendSystemMsg("当前是单人生存模式!")
else--如果不是单人生存模式
	Chat:sendSystemMsg("当前不是单人生存模式!")
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:
--判断是不是创造转生存模式
local result=World:isCreateRunMode()
if result==0 then--如果是创造转生存模式
	Chat:sendSystemMsg("当前是创造转生存模式!")
else--如果不是创造转生存模式
	Chat:sendSystemMsg("当前不是创造转生存模式!")
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:
--判断是不是玩法编辑模式
local result=World:isGameMakerMode()
if result==0 then--如果是玩法编辑模式
	Chat:sendSystemMsg("当前是玩法编辑模式!")
else--如果不是玩法编辑模式
	Chat:sendSystemMsg("当前不是玩法编辑模式!")
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:
--判断是不是玩法运行模式
local result=World:isGameMakerRunMode()
if result==0 then--如果是玩法运行模式
	Chat:sendSystemMsg("当前是玩法运行模式!")
else--如果不是玩法运行模式
	Chat:sendSystemMsg("当前不是玩法运行模式!")
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:
--获取当前时间
local result,time=World:getHours()
--在聊天框显示
Chat:sendSystemMsg("现在是"..time.."点!")

# 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:
--设置时间为8点
World:setHours(8)
--在聊天框显示
Chat:sendSystemMsg("时间设置为8点!")

# 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:
--获取当前视角编辑状态
local result,state=World:getCameraEditState()
if state==0 then--0:默认
	Chat:sendSystemMsg("当前视角编辑状态为:默认")
elseif state==1 then--1:编辑中
	Chat:sendSystemMsg("当前视角编辑状态为:编辑中")
elseif state==2 then--2:测试中
	Chat:sendSystemMsg("当前视角编辑状态为:测试中")
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:
--获取区块范围
local result,startX,startZ,endX,endZ=World:getRangeXZ()
Chat:sendSystemMsg("区块起点横坐标:"..startX)
Chat:sendSystemMsg("区块起点纵坐标:"..startZ)
Chat:sendSystemMsg("区块End point横坐标:"..endX)
Chat:sendSystemMsg("区块End point纵坐标:"..endZ)

# getRayLength

  • Parameters and types:
    • srcx,srcy,srcz:numberStart point coord
    • dstx,dsty,dstz:numberEnd point coord
    • 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:
--获取从(0,0)高度10开始,向北50格内碰到的第一个方块id
--方向参数:0西 1东 2南 3北 4下 5上
local result,blockid=World:getRayBlock(0,10,0,3,50)
if id==-1 then--如果50格内没有方块
	Chat:sendSystemMsg("从(0,0)高度10开始,向北50格没有方块")
else--如果50格内有方块
	Chat:sendSystemMsg("从(0,0)高度10开始,向北50格第一个方块id是"..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:
--参数:
local objtype=1--类型参数:0全部 1玩家 2生物 3掉落物 4投掷物
local x1,y1,z1=0,7,0--区域起点坐标
local x2,y2,z2=50,57,50--区域End point坐标
--获取(x0,z0)高度y0到(x1,z1)高度y1范围内,类型为type的物品number与列表
local result,num,objids=World:getActorsByBox(objtype,x1,y1,z1,x2,y2,z2)
--在聊天框显示number
Chat:sendSystemMsg("在范围内一共有"..num.."个玩家")
--在聊天框显示列表
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:
--获取当前存档玩家总数
local result,num=World:getPlayerTotal(-1)
Chat:sendSystemMsg("当前存档玩家总数为:"..num)
--获取当前存档阵亡玩家数
result,num=World:getPlayerTotal(0)
Chat:sendSystemMsg("当前存档阵亡玩家数为:"..num)
--获取当前存档存活玩家数
result,num=World:getPlayerTotal(1)
Chat:sendSystemMsg("当前存档存活玩家数为:"..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:
--获取当前存档全部玩家列表
--参数:-1全部玩家 0阵亡玩家 1存活玩家
local result,num,array=World:getAllPlayers(-1)
--在聊天框显示number
Chat:sendSystemMsg("当前存档一共有"..num.."个玩家")
--在聊天框显示列表
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:
--从全部玩家中随机选取一名玩家
--参数:-1全部玩家 0阵亡玩家 1存活玩家
local result,playerid=World:randomOnePlayer(-1)
--在聊天框显示
Chat:sendSystemMsg("随机选取了一名玩家:"..playerid)

# despawnActor

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove actor
  • The specific use cases are as follows:
--参数:
local type=2--类型参数:1玩家 2生物 3掉落物 4投掷物
local x0,y0,z0=0,7,0--区域起点坐标
local x1,y1,z1=50,57,50--区域End point坐标
--获取(x0,z0)高度y0到(x1,z1)高度y1范围内,类型为type的物品number与列表
local result,n,actors=World:getActorsByBox(type,x0,y0,z0,x1,y1,z1)
if n>0 then--如果范围内生物number大于0
	--移除其中一个生物
	World:despawnActor(actors[1])
	--在聊天框显示
	Chat:sendSystemMsg("移除了"..actors[1])
else--如果范围内没有生物
	--在聊天框显示
	Chat:sendSystemMsg("(0,7,0)至(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:
--在(0,0)高度7的Location ID生成3只鸡
--前三个参数0,7,0是生成坐标
--第四个参数3400是生成的生物id
--最后一个参数3是生成的number
local result,objids=World:spawnCreature(0,7,0,3400,3)
--在聊天框显示提示
Chat:sendSystemMsg("在(0,0)高度7的Location ID生成了3只鸡,它们在存档中的id分别是:")
--在聊天框显示id列表
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:
--参数:
local type=2--类型参数:1玩家 2生物 3掉落物 4投掷物
local x0,y0,z0=0,7,0--区域起点坐标
local x1,y1,z1=50,57,50--区域End point坐标
--获取(x0,z0)高度y0到(x1,z1)高度y1范围内,类型为type的物品number与列表
local result,n,actors=World:getActorsByBox(type,x0,y0,z0,x1,y1,z1)
if n>0 then--如果范围内生物number大于0
	--移除其中一个生物
	World:despawnCreature(actors[1])
	--在聊天框显示
	Chat:sendSystemMsg("移除了"..actors[1])
else--如果范围内没有生物
	--在聊天框显示
	Chat:sendSystemMsg("(0,7,0)至(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:
--在(0,0)高度7的Location ID生成3个土块
--前三个参数0,7,0是生成坐标
--第四个参数101是生成的物品id
--最后一个参数3是生成的number
local result,objid=World:spawnItem(0,7,0,101,3)
--在聊天框显示提示
Chat:sendSystemMsg("在(0,0)高度7的Location ID生成了3个土块,它们在存档中的id是"..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:
--移除指定区域内所有掉落物
--前三个参数为区域起点坐标
--后三个参数为区域End point坐标
World:despawnItemByBox(-20,0,-20,20,50,20)
--在聊天框显示
Chat:sendSystemMsg("移除了(-20,0,-20)至(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:
--每当有玩家做动画表情,移除房主周围10格内的某一掉落物
--当玩家做动画表情时执行此函数
local function Player_PlayAction(event)
	--获取房主的坐标
	local result,x,y,z=Player:getPosition(0)
	--获取房主周围10格内的掉落物number和列表
	local result2,num,list=World:getActorsByBox(3,x-10,y-10,z-10,x+10,y+10,z+10)
	if num>0 then--如果存在掉落物
		--移除第一组物品
		World:despawnItemByObjid(list[1])
		--在聊天框显示
		Chat:sendSystemMsg("附近10格发现掉落物品,已移除了其中一组")
	else--如果不存在掉落物
		--在聊天框显示
		Chat:sendSystemMsg("附近10格没有发现掉落物品!")
	end
end
--注册动画表情监听器,当玩家做动画表情时执行上面的函数
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:
--计算两点间的直线距离
--第一个参数是由起点坐标组成的表
--第二个参数是由End point坐标组成的表
local result,distance=World:calcDistance({x=0,y=0,z=0},{x=10,y=10,z=10})
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度0到(10,10)高度10的直线距离是"..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:
--在(0,0)高度7的Location ID播放烟雾特效
--前三个参数是播放特效的Location ID坐标
--第四个参数是播放特效的Effect id,具体可以在“迷你世界ID查询”的“特效表数据”里查看
--最后一个参数是特效的缩放比例
World:playParticalEffect(0,7,0,1001,1)
--在聊天框显示
Chat:sendSystemMsg("在(0,0)高度7的Location ID生成了一个烟雾特效")

# 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:
--停止指定Location ID的指定特效
--前三个参数是停止播放特效的Location ID坐标
--最后一个参数是需要停止的Effect id
World:stopEffectOnPosition(0,7,0,1001)
--在聊天框显示
Chat:sendSystemMsg("停止了(0,0)高度7Location ID的1001烟雾特效")

# 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:
--缩放指定Location ID的指定特效
--前三个参数是需要缩放特效的坐标
--第四个参数是需要缩放的Effect id
--最后一个参数是设置的缩放比例
World:setEffectScaleOnPosition(0,7,0,1001,2)
--在聊天框显示
Chat:sendSystemMsg("把(0,0)高度7Location ID的烟雾特效放大了两倍")

# 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:
--获取一个随机Effect id
local result,id=World:randomParticleEffectID()
--在聊天框显示
Chat:sendSystemMsg("获取到了一个随机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:
--在(0,0)高度7的Location ID播放音乐10713
--第一个参数为播放音乐的坐标组成的表
--第二个参数10713为播放的音效id,具体可以在“迷你世界ID查询”的“音效表数据”里查看
--后三个参数分别是:音量、音高、是否循环播放
World:playSoundEffectOnPos({x=0,y=7,z=0},10713,100,1,false)
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度7的Location ID正在播放音乐")

# 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:
--在(0,0)高度7的Location ID播放音乐10713
World:playSoundEffectOnPos({x=0,y=7,z=0},10713,100,1,false)
--在聊天框显示提示
Chat:sendSystemMsg("(0,0)高度7的Location ID正在播放音乐,做动画表情即可停止播放")
--当玩家做动画表情时执行此函数
local function Player_PlayAction(event)
	--停止(0,0)高度7Location ID音乐10713的播放
	--第一个参数为要停止播放音乐的坐标组成的表
	--第二个参数为要停止播放的音乐id,具体可以在“迷你世界ID查询”的“音效表数据”里查看
	World:stopSoundEffectOnPos({x=0,y=7,z=0},10713)
	--在聊天框显示
	Chat:sendSystemMsg("停止了(0,0)高度7音乐10713的播放")
end
--注册一个动画表情监听器,事件发生时执行上面的函数
ScriptSupportEvent:registerEvent([=[Player.PlayAction]=],Player_PlayAction)

# getLightByPos 1.7+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Get light intensity
  • The specific use cases are as follows:
local result = World:getLightByPos(x, y, z)

# setBlockLightEx 1.7+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set light intensity
  • The specific use cases are as follows:
local result = World:setBlockLightEx(x, y, z, lv)
Last Update: 9/7/2020, 10:19:13 PM