# 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:
local isDayTx = World:isDaytime()
if isDayTx~=ErrorCode.OK then --if it is night then send torch to player
	local itemId, itemCnt = 817, 2 --Torch Id and quantity
	Player:gainItems(playerId, itemId, itemCnt, 1)
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==ErrorCode.OK then print('Current game is 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:
local result = World:isCreativeMode()
if result==ErrorCode.OK then print('Current mode: Creation') 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==ErrorCode.OK then print('Current Mode: Multiplayer Creation 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:
local result = World:isExtremityMode()
if result==ErrorCode.OK then print('Current Mode: 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==ErrorCode.OK then print('Current Mode: Survival mode-free') 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==ErrorCode.OK then print('Current Mode: 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:
local result = World:isCreateRunMode()
if result==ErrorCode.OK then print('Current Mode:Surviva lmode switched from creation') 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==ErrorCode.OK then print('Current Mode: Dev Mode-Edit 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:
local result = World:isGameMakerRunMode()
if result==ErrorCode.OK then print('Current Mode: Dev Mode-Play 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:
local result, dayTime = World:getHours()
if result==ErrorCode.OK then print('Current time:', dayTime) end

# 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:
local result = World:setHours(hour)

# 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 result==ErrorCode.OK then print('Current View-edit:', state) 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:
--Acquired obj is camera(userdata),return nill
local result, config = World:getCustomCameraConfig()
if result==ErrorCode.OK and config~=nil then --Custom View
	config:setOption(CAMERA_OPTION_INDEX_CONFIG_SET, CCG_FLATVIEW)
end

# 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()
if result==ErrorCode.OK then print('StartXZ=(',startX,', ',startZ,'), EndXZ=(',endX,', ',endZ,')')  end

# 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:
local result = World:getRayBlock(srcx, srcy, srcz, face, distance)

# 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 actorType = 0 --OBJ_TYPE_MONSTER
local x1, y1, z1 = -5, 1, -5
local x2, y2, z2 = 15, 9, 15
local ret, num, array = World:getActorsByBox(actorType, x1,y1,z1, x2,y2,z2)
if ret == ErrorCode.OK then print('Actors ===>> ', num, array) 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 = World:getPlayerTotal(alive)

# 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:
local aliveType = -1 --Acquire all player data
local ret, num, array = World:getAllPlayers(aliveType)
if ret == ErrorCode.OK then print('Actors ===>> ', num, array) 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:
local aliveType = 1 --Random survived Id
local ret, playerId = World:randomOnePlayer(aliveType)
if ret == ErrorCode.OK then print('Player ===>> ', playerId) end

# despawnActor

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Remove actor
  • The specific use cases are as follows:
local ret, num, array = World:getActorsByBox(aType, x1,y1,z1, x2,y2,z2)
if array and #array>0 then --Remove Actor
	local result = World:despawnActor(array[#array])
	if result == ErrorCode.OK then print('Despawn the last actor') end
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:
local x, y, z = 6, 7, 8
local actorId, actorCnt = 3812, 2 --Cow
local ret, objids = World:spawnCreature(x, y, z, actorId, actorCnt)
if objids and #objids>0 then
	for idx = 1, #objIds do --Set oxygen dependency
		Creature:setOxygenNeed(objids[idx], true)
	end
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 result = World:despawnCreature(objids[1])
if result == ErrorCode.OK then print('Despawn the creature') 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:
local xPos, yPos, zPos = 5, 6, 7
local itemId, itemCnt = 15003, 30 --Item Id and number
local ret, objIds = World:spawnItem(xPos, yPos, zPos, itemId, itemCnt)
if ret == ErrorCode.OK then print("Item[1]====>>>", objIds[1]) end

# 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:
local x1, y1, z1 = -5, 5, -5
local x2, y2, z2 = 15, 9, 15
local result = World:despawnItemByBox(x1,y1,z1, x2,y2,z2)
if result == ErrorCode.OK then print('Successfully removed item in target area') end

# 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:
local result = World:despawnItemByObjid(objIds[1])
if result == ErrorCode.OK then print('Successfully removed item in target area') end

# 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:
local result = World:calcDistance(pos1, pos2)

# 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:
local result = World:playParticalEffect(x, y, z, particleId, scale)

# 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:
local result = World:stopEffectOnPosition(x, y, z, particleId)

# 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:
local result = World:setEffectScaleOnPosition(x, y, z, particleId, scale)

# 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:
local result = World:randomParticleEffectID(x, y, z, particleId, scale)

# 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:
local result = World:playSoundEffectOnPos(pos, soundId, volume, pitch, isLoop)

# 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:
local result = World:stopSoundEffectOnPos(pos, soundId)
Last Update: 11/22/2019, 2:31:59 PM