Appearance
世界模块管理接口 World
具体函数名及描述如下:
StopParticleOnPos
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 停止指定位置的粒子特效(支持传特效ID或路径)
- 具体使用案例如下:
lua
local pos = {x = x, y = y, z = z} -- 创建的位置
local createoffset = {x = 0,y = 0.5, z = 0} --创建的偏移位置
local result = World:StopParticleOnPos(pos.x +createoffset.x, pos.y +createoffset.y,pos.z +createoffset.z, 1001, worldId)SetParticleTransform
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 调整指定位置的粒子特效偏移/旋转/缩放(支持单个或多个特效)
- 具体使用案例如下:
lua
-- 设置效果缩放2倍
local pos = {x = x, y = y, z = z} -- 创建的位置
local createoffset = {x = 0,y = 0.5, z = 0} --创建的偏移位置
local result = World:SetParticleTransform({x=pos.x +createoffset.x, y=pos.y +createoffset.y,z=pos.z +createoffset.z}, 1001, {x= 0,y= 0,z=0}, nil, {x = 2, y = 2, z = 2}, worldId)PlayParticle
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 在指定位置播放粒子特效(支持单个或多个特效)
- 具体使用案例如下:
lua
local offset = {x=0,y=0.5,z=0}
local result = World:PlayParticle({x = x, y = y, z = z}, 1001, 2, offset, nil, nil, worldId)GetLightByPos
- 参数及类型:
- 返回值及类型:
- lv:
number光照强度(0~16),失败为-1
- lv:
- 该方法的其他说明: 获取指定位置的光照强度
- 具体使用案例如下:
lua
local light = World:GetLightByPos(x, y, z, WorldId)
print("获取光照强度 ", light)SpawnCreature
- 参数及类型:
- 返回值及类型:
- objs:
table/ nil 生成的生物ID数组
- objs:
- 该方法的其他说明: 在指定位置生成生物(怪物/NPC/动物等)
- 具体使用案例如下:
lua
local creatures = World:SpawnCreature(x + 5, y + 1, z, 3400, 1, true, worldId)DespawnActor
- 参数及类型:
- objid:
number对象objID
- objid:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 移除一个生物,如果是骑乘的生物则会先把骑乘关系处理掉再移除生物。(玩家不允许移除)
- 具体使用案例如下:
lua
local result = World:DespawnActor(creatureId)GetPlayerTotal
- 参数及类型:
- alive:
number/ nil 玩家状态(0阵亡 1存活 -1全部)
- alive:
- 返回值及类型:
- ret:
number玩家数量,失败为-1
- ret:
- 该方法的其他说明: 获取当前玩家数量(可按存活/死亡筛选)
- 具体使用案例如下:
lua
local total = World:GetPlayerTotal()GetAllPlayers
- 参数及类型:
- alive:
number/ nil 玩家状态(0阵亡 1存活 -1全部)
- alive:
- 返回值及类型:
- list:
table/ nil 玩家objid数组
- list:
- 该方法的其他说明: 获取当前地图中全部玩家对象ID列表(可按存活/死亡筛选)
- 具体使用案例如下:
lua
local players = World:GetAllPlayers()GetSpawnPoint
- 参数及类型:
- worldId:
number/ nil 星球ID(nil或-1表示当前星球)
- worldId:
- 返回值及类型:
- 该方法的其他说明: 取当前地图/世界配置的默认出生点
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local x, y, z = World:GetSpawnPoint(worldId)FindCanSpawnMobPosList
- 参数及类型:
- 返回值及类型:
- posList:
table/ nil 位置列表
- posList:
- 该方法的其他说明: 获取指定中心点周围,以设置的半径为范围的「可刷怪」位置列表,可选是否把中心点也算进结果里
- 具体使用案例如下:
lua
local posList = World:FindCanSpawnMobPosList(x, y, z, 10, true, WorldId)
if posList then
for i, v in ipairs(posList) do
print("可以创建生物位置", v.x, v.y, v.z)
end
endFindNearestPlayerByPos
- 参数及类型:
- 返回值及类型:
- objid:
number/ nil 玩家ID
- objid:
- 该方法的其他说明: 以指定位置为中心、在半径范围内查找玩家,返回最近的玩家ID
- 具体使用案例如下:
lua
local nearestPlayerId = World:FindNearestPlayerByPos(x, y, z, worldId)PlaySoundEffectOnPos
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 在指定位置播放音效(可设置音量/音调/是否循环)
- 具体使用案例如下:
lua
local result = World:PlaySoundEffectOnPos({x = x, y = y, z = z}, 10946, 100, 1, false, worldId)StopSoundEffectOnPos
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 停止指定位置上的音效(传 -1 表示停止该位置所有音效)
- 具体使用案例如下:
lua
local result = World:StopSoundEffectOnPos({x = x, y = y, z = z}, 10946, worldId)PauseSoundEffectOnPos
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否成功
- ret:
- 该方法的其他说明: 暂停或恢复指定位置的音效(传 -1 表示该位置所有音效)
- 具体使用案例如下:
lua
local result = World:PauseSoundEffectOnPos({x = x, y = y, z = z}, 10946, true, worldId)IsDaytime
- 参数及类型: 无
- 返回值及类型:
- ret:
boolean是否白天
- ret:
- 该方法的其他说明: 当前是否为白天
- 具体使用案例如下:
lua
local isDaytime = World:IsDaytime()SetHours
lua
local result = World:SetHours(2)GetHours
- 参数及类型: 无
- 返回值及类型:
- curHour:
number/ nil 小时
- curHour:
- 该方法的其他说明: 获取当前世界时间(小时)
- 具体使用案例如下:
lua
local hours = World:GetHours()GetDay
- 参数及类型: 无
- 返回值及类型:
- ret:
number/ nil 天数
- ret:
- 该方法的其他说明: 获取当前世界过了多少天
- 具体使用案例如下:
lua
local day = World:GetDay()SetGravity
lua
local result = World:SetGravity(12, worldId)AddGravity
lua
local result = World:AddGravity(1, worldId)GetGravity
- 参数及类型:
- worldId:
number/ nil 星球ID(默认当前主机所在星球)
- worldId:
- 返回值及类型:
- value:
number/ nil 重力值
- value:
- 该方法的其他说明: 获取当前星球重力值
- 具体使用案例如下:
lua
local gravity = World:GetGravity(worldId)IsChunkLoaded
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否已加载
- ret:
- 该方法的其他说明: 判断某个区块是否已加载
- 具体使用案例如下:
lua
local worldId = World:GetHostWorldId()
local result = World:IsChunkLoaded(x, z, worldId)CanMobSpawnOnPosXZ
- 参数及类型:
- 返回值及类型:
- posy:
number查到的可刷怪落脚 Y(-1 表示未找到)
- posy:
- 该方法的其他说明: 在指定的 x、z 处从高度 y 向上查找,得到第一个可落脚刷怪的高度,找不到合适位置返回 -1。
- 具体使用案例如下:
lua
local canSpawnY = World:CanMobSpawnOnPosXZ(x,y, z, WorldId)
if canSpawnY and canSpawnY > 0 then
print("可以创建生物位置", x, canSpawnY, z)
endGetHostWorldId
- 参数及类型: 无
- 返回值及类型:
- worldId:
number星球ID
- worldId:
- 该方法的其他说明: 获取主机所在星球ID
- 具体使用案例如下:
lua
local worldId = World:GetHostWorldId()
print("获取主机世界id ", worldId)SpawnProjectile
- 参数及类型:
- 返回值及类型:
- objid:
number/ nil 投掷物objid
- objid:
- 该方法的其他说明: 在起点生成一个投掷物并朝目标点飞行(可指定速度)
- 具体使用案例如下:
lua
-- 生成石箭往x+20,y+5,z方向射出, 速度10
local projectile = World:SpawnProjectile((playerId or Player:GetHostUin()), 12051, x, y, z, x + 20, y + 5, z, 10, worldId)SpawnProjectileByDir
- 参数及类型:
- 返回值及类型:
- ret:
number/ nil 投掷物ID(失败返回nil)
- ret:
- 该方法的其他说明: 在指定位置生成投掷物,按指定方向飞行(可指定速度)
- 具体使用案例如下:
lua
local projectileByDir = World:SpawnProjectileByDir((playerId or Player:GetHostUin()), 12051, x, y, z, 20, 5, 20, 10, worldId)GetBiomeType
- 参数及类型:
- 返回值及类型:
- ret:
number/ nil 地形类型(BiomeType)
- ret:
- 该方法的其他说明: 获取指定位置的地形类型;取不到返回 nil
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local biomeType = World:GetBiomeType(x, z, worldId)
if biomeType == BiomeType.GrassLand then
print("草原")
elseif biomeType == BiomeType.Forest then
print("森林")
endGetBiomeGroup
- 参数及类型:
- 返回值及类型:
- ret:
number/ nil 地形组类型(WeatherGroup)
- ret:
- 该方法的其他说明: 获取指定位置的地形组类型;取不到返回 nil
- 具体使用案例如下:
lua
local group = World:GetBiomeGroup(x, z, WorldId)FindEcosystem
- 参数及类型:
- 返回值及类型:
- retX|retY|retZ:
number/ nil 找到的地形位置坐标(失败返回nil)
- retX|retY|retZ:
- 该方法的其他说明: 从起点附近搜索指定地形类型,找到则返回目标坐标,找不到返回 nil,radius是 (2radius + 1) ^ 2个chunk, radius = 4就需要遍历81个chunk,8116*16个方块
- 具体使用案例如下:
lua
local x,y,z = World:FindEcosystem(centerX, centerY, centerZ, BiomeType.GrassLand, 50, worldId)
if x and y and z then
print("找到草原", x, y, z)
endPixelMapAddMarker
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否添加成功
- ret:
- 该方法的其他说明: 在地图上添加一个开发者标记点(查看下案例,了解params结构)
- 具体使用案例如下:
lua
-- 参数说明
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local x, y, z = Actor:GetPosition(targetPlayerId)
if x == nil or y == nil or z == nil then
x, y, z = GetPlayerPos()
end
x, y, z = x or 0, y or 0, z or 0
local params = {
posX = x,--(必填)
posZ = z,--(必填)
-- name ="测试名", --名字
iconName = "0_10074", --图片路径(必填)
-- zoomMin = 0, --最小scale倍率
-- zoomMax = 100, --最大scale倍率
-- isTrace = false, --是否追踪
-- isRadarTrace = false, --雷达上是否追踪
-- appearInBlockFog = true, --
-- isCanUI = false, --是否能点击
-- desc = "", --描述
-- level = 4, --UI层级
}
local result = World:PixelMapAddMarker(targetPlayerId, "markId_123", params, worldId)PixelMapRefreshMarker
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否刷新成功
- ret:
- 该方法的其他说明: 刷新地图上的开发者标记点(params 只需提供要变更的字段)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local x, y, z = Actor:GetPosition(targetPlayerId)
if x == nil or y == nil or z == nil then
x, y, z = GetPlayerPos()
end
x, y, z = x or 0, y or 0, z or 0
local params = {
posX = x,
posZ = z,
-- name = defaultCustomMarkerConfig[1].name, 名字
iconName = "0_10103", --图片ID
-- zoomMin = 0, 最小scale倍率
-- zoomMax = 100, 最大scale倍率
-- isTrace = false, 是否追踪
-- isRadarTrace = false, 雷达上是否追踪
-- appearInBlockFog = true,
-- isCanUI = false, 是否能点击
-- desc = "", 描述
-- level = 4, UI层级
}
local result = World:PixelMapRefreshMarker(targetPlayerId, "markId_123", params, worldId)PixelMapDelMarker
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否删除成功
- ret:
- 该方法的其他说明: 删除地图上的开发者标记点
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local result = World:PixelMapDelMarker(targetPlayerId, "markId_123", worldId)PixelMapAddTexture
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否添加成功
- ret:
- 该方法的其他说明: 在地图纹理节点上叠加一张纹理(可用于背景/遮罩/自定义装饰)
- 具体使用案例如下:
lua
--开发者添加纹理到地图纹理节点,可以修饰原本的地图纹理(比如加背景,遮罩,自定义地图纹理)
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local x, y, z = Actor:GetPosition(targetPlayerId)
if x == nil or y == nil or z == nil then
x, y, z = GetPlayerPos()
end
x, y, z = x or 0, y or 0, z or 0
local params = {
filePath = "0_10103", --图片id
width = 100, --宽度
height = 100, --高度
posX = x, --在地图上的方块位置
posZ = z, --在地图上的方块位置
level = 11, --层级 官方地图纹理层级为10
pivotX = 0, --x轴锚点
pivotY = 0, --z轴锚点
alpha = 1, --透明度
scale = 1, --缩放
rotation = 0, --旋转
colorR = 255, --颜色
colorG = 255, --颜色
colorB = 255, --颜色
}
local result = World:PixelMapAddTexture(targetPlayerId, "textureId_1", params, worldId)PixelMapRefreshTexture
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否刷新成功
- ret:
- 该方法的其他说明: 刷新地图上的开发者纹理标签(params 只需提供要变更的字段)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local x, y, z = Actor:GetPosition(targetPlayerId)
if x == nil or y == nil or z == nil then
x, y, z = GetPlayerPos()
end
x, y, z = x or 0, y or 0, z or 0
local params = {
filePath = "0_10104", --图片id
width = 100, --宽度
height = 100, --高度
posX = x, --在地图上的方块位置
posZ = z, --在地图上的方块位置
level = 11, --层级 官方地图纹理层级为10
pivotX = 0, --x轴锚点
pivotY = 0, --z轴锚点
alpha = 1, --透明度
scale = 1, --缩放
rotation = 0, --旋转
colorR = 255, --颜色
colorG = 255, --颜色
colorB = 255, --颜色
}
local result = World:PixelMapRefreshTexture(targetPlayerId, "textureId_1", params, worldId)PixelMapDelTexture
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否删除成功
- ret:
- 该方法的其他说明: 删除地图上的开发者纹理标签
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local result = World:PixelMapDelTexture(targetPlayerId, "textureId_1", worldId)SetSkyBoxColorAnim
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 给指定玩家设置天空盒颜色参数(带动画过渡)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local result = World:SetSkyBoxColorAnim(targetPlayerId, SkyboxColor.Moon, [=[0xffe082]=], Easing.Linear, 1, worldId)SetTimeVanishingSpeed
lua
local result = World:SetTimeVanishingSpeed(20)SetSkyBoxTemplate
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置天空盒模板(官方模板填数值,自定义模板填ID)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(Player:GetHostUin())
local result = World:SetSkyBoxTemplate(7, worldId)SetSkyBoxMaps
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置天空盒贴图
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(Player:GetHostUin())
local result = World:SetSkyBoxMaps(SkyboxMap.Sky, [=[0_30011]=], worldId)SetSkyBoxColor
- 参数及类型:
- time:
number游戏时间(小时) - itype:
number颜色属性枚举(SkyboxColor)SkyboxColor - color:
string16进制颜色值(如0xffffff) - worldId:
number/ nil 星球ID
- time:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置天空盒在指定时间点的颜色参数
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local time = SkyboxTime.Current
local colorType = SkyboxColor.Top
local color = [=[0x1e88e5]=]
local result = World:SetSkyBoxColor(time, colorType, color, worldId)SetSkyBoxAttr
- 参数及类型:
- time:
number游戏时间(小时) - itype:
number参数类型(SkyboxAttr)SkyboxAttr - value:
number参数值(0~100) - worldId:
number/ nil 星球ID
- time:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置天空盒在指定时间点的属性参数
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local time = SkyboxTime.Current
local attr = SkyboxAttr.SunScale
local value = 20
local result = World:SetSkyBoxAttr(time, attr, value, worldId)SetSkyBoxAttrWithNoTime
- 参数及类型:
- itype:
number参数类型(SkyboxAttrNoTime)SkyboxAttrNoTime - value:
number参数值(0~100) - worldId:
number/ nil 星球ID
- itype:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置天空盒属性参数(不带时间维度,直接作用于当前配置)
- 具体使用案例如下:
lua
local result = World:SetSkyBoxAttrWithNoTime(SkyboxAttrNoTime.Metallic, 50, worldId)SetSkyBoxFilter
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 给指定玩家设置天空盒滤镜参数(数值或颜色)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local result = World:SetSkyBoxFilter(targetPlayerId, SkyboxFilter.Contrast, 50, worldId)SetSkyBoxSwitch
- 参数及类型:
- time:
number游戏时间(小时) - itype:
number参数类型(SkyboxSwitch)SkyboxSwitch - value:
number开关值(0/1) - worldId:
number/ nil 星球ID
- time:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置天空盒属性开关
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(Player:GetHostUin())
local time = SkyboxTime.Current
local switch = SkyboxSwitch.Fogenable
local visible = true
local result = World:SetSkyBoxSwitch(time, switch, visible, worldId)SetSkyBoxMapsAnim
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 给指定玩家设置天空盒贴图(带动画过渡)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local result = World:SetSkyBoxMapsAnim(targetPlayerId, SkyboxMap.Sky, [=[0_30005]=], Easing.BackOut, 1, worldId)SetSkyBoxFilterAnim
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 给指定玩家设置天空盒滤镜参数(带动画过渡)
- 具体使用案例如下:
lua
local targetPlayerId = playerId or Player:GetHostUin()
local worldId = Actor:GetObjWorldId(targetPlayerId)
local result = World:SetSkyBoxFilterAnim(targetPlayerId, SkyboxFilter.Color, [=[0xffee58]=], Easing.Linear, 1, worldId)GetLocalDate
lua
local date = World:GetLocalDate(EventDate.Day)GetLocalDateString
- 参数及类型: 无
- 返回值及类型:
- ret:
string时间字符串
- ret:
- 该方法的其他说明: 获取完整本地设备时间字符串
- 具体使用案例如下:
lua
local dateString = World:GetLocalDateString()GetServerDate
- 参数及类型:
- enum:
number枚举值(EventDate)
- enum:
- 返回值及类型:
- ret:
number时间值(取不到返回0)
- ret:
- 该方法的其他说明: 获取服务器时间的指定字段(云服模式下会回退到本地时间)
- 具体使用案例如下:
lua
local date = World:GetServerDate()GetDateFromTime
- 参数及类型:
- 返回值及类型:
- ret:
number时间值(入参非法返回0)
- ret:
- 该方法的其他说明: 把时间戳拆出指定字段(年/月/日/时/分/秒等)
- 具体使用案例如下:
lua
local date = World:GetDateFromTime(os.time(), EventDate.Day)GetDirRayDetection
- 参数及类型:
- 返回值及类型: ret:number|nil,vec:table|nil:命中ID与命中位置{x=0,y=0,z=0}(未命中返回nil)
- 该方法的其他说明: 从起点沿方向做射线检测,返回命中的对象/方块及命中位置
- 具体使用案例如下:
lua
local uin = targetPlayerId
local worldId = Actor:GetObjWorldId(targetPlayerId)
local ray = Player:GetAimDir(uin)
local x,y,z = Player:GetRayOriginPos(uin)
local id,pos = World:GetDirRayDetection({x=x, y=y, z=z}, {x= ray.x, y= ray.y, z= ray.z}, 10, RayDetectType.Block, worldId)GetRayLength
- 参数及类型:
- 返回值及类型:
- ret:
number/ nil 射线长度(失败返回nil)
- ret:
- 该方法的其他说明: 从起点到终点方向做射线检测,计算射线在遇到方块前的长度
- 具体使用案例如下:
lua
local length = World:GetRayLength(x, y, z, x, y + 20, z, 100, WorldId)GetRayBlock
- 参数及类型:
- 返回值及类型:
- 该方法的其他说明: 从起点沿指定面/方向做射线检测,返回命中的方块ID(未命中返回nil)
- 具体使用案例如下:
lua
local block = World:GetRayBlock(x, y, z, FaceDir.NegY, 100, WorldId)CalcDirectionByYawDirection
- 参数及类型:
- 返回值及类型: ret:table|nil:世界方向向量{x: number, y: number, z: number}(失败返回nil)
- 该方法的其他说明: 把局部坐标方向转换为世界方向(忽略视角仰角)
- 具体使用案例如下:
lua
local direction = World:CalcDirectionByYawDirection(Player:GetHostUin(), 100, 100, 100)CalcDirectionByYawAngle
- 参数及类型:
- 返回值及类型:
- ret:
table/ nil 世界方向向量{x,y,z}(失败返回nil)
- ret:
- 该方法的其他说明: 把局部球坐标方向转换为世界方向(忽略视角仰角)
- 具体使用案例如下:
lua
local direction = World:CalcDirectionByYawAngle(Player:GetHostUin(), 30, 45)CalcDirectionByCoord
- 参数及类型:
- 返回值及类型: ret:table:方向向量{x: number, y: number, z: number}
- 该方法的其他说明: 不做任何数学换算,只是把三个坐标放进一张表里
- 具体使用案例如下:
lua
local direction = World:CalcDirectionByCoord(10 ,20, 30)CalcDirectionByAngle
- 参数及类型:
- 返回值及类型: ret:table|nil:方向向量{x: number, y: number, z: number}(入参非法返回nil)
- 该方法的其他说明: 把水平角和俯仰角转换为方向向量
- 具体使用案例如下:
lua
local direction = World:CalcDirectionByAngle(45, 45)RandomParticleEffectID
- 参数及类型: 无
- 返回值及类型:
- ret:
number/ nil 特效ID(取不到返回nil)
- ret:
- 该方法的其他说明: 从粒子特效表中随机返回一个可触发的特效ID
- 具体使用案例如下:
lua
local id = World:RandomParticleEffectID()RandomSoundID
- 参数及类型: 无
- 返回值及类型:
- ret:
number/ nil 音效ID(取不到返回nil)
- ret:
- 该方法的其他说明: 从音效表中随机返回一个音效ID
- 具体使用案例如下:
lua
local id = World:RandomSoundID()CalcDistance
- 参数及类型:
- posSrc:table:源坐标{x: number, y: number, z: number}
- posDst:table:目标坐标{x: number, y: number, z: number}
- 返回值及类型:
- ret:
number/ nil 两点距离(入参非法返回nil)
- ret:
- 该方法的其他说明: 计算两个三维坐标之间的直线距离
- 具体使用案例如下:
lua
local distance = World:CalcDistance({x = 0, y = 0, z = 0}, {x = 10, y = 0, z = 0})SetGroupWeather
- 参数及类型:
- groupid:
number天气组ID(WeatherGroup)WeatherGroup - weatherid:
number天气ID(GroupWeatherType)GroupWeatherType - worldId:
number/ nil 星球ID(默认当前主机所在星球)
- groupid:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置某个天气组的天气状态
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local result = World:SetGroupWeather(WeatherGroup.Common, GroupWeatherType.Shine, worldId)RandomWeatherID
- 参数及类型: 无
- 返回值及类型:
- ret:
number/ nil 天气ID(取不到返回nil)
- ret:
- 该方法的其他说明: 从可用天气列表中随机一个天气ID
- 具体使用案例如下:
lua
local id = World:RandomWeatherID()GetGroupWeather
- 参数及类型:
- groupid:
number天气组ID(WeatherGroup)WeatherGroup - worldId:
number/ nil 星球ID(默认当前主机所在星球)
- groupid:
- 返回值及类型:
- ret:
number/ nil 天气值(入参非法返回nil)
- ret:
- 该方法的其他说明: 获取指定天气组当前的天气值
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local weather = World:GetGroupWeather(WeatherGroup.Common, worldId)SetSpawnPoint
lua
local result = World:SetSpawnPoint(x, y, z)CalcDirectionByPos2Pos
- 参数及类型:
- 返回值及类型:
- ret:
table/ nil 单位方向{x,y,z}(入参非法返回nil)
- ret:
- 该方法的其他说明: 计算从位置1指向位置2的单位方向向量
- 具体使用案例如下:
lua
local result = World:CalcDirectionByPos2Pos({x = x, y = y, z = z}, {x = x + 10, y = y, z = z})SetWorldCreateMobRule
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置世界生物生成规则,地图没有这个地形会设置失败(不保存,退出游戏后失效)
- 具体使用案例如下:
lua
local cfgs = {
-- 草原
[BiomeType.GrassLand] = {
{
id = 3400, -- 生物id,嘟嘟鸟
weight = 100 -- 权重
},
{
id = 3401, -- 生物id
weight = 100 -- 权重
},
},
[BiomeType.Forest] = {--迷拉星森林
{
id = 3400,
weight = 50
}
}
}
local result = World:SetWorldCreateMobRule(cfgs, worldId)GetWorldCreateMobRule
- 参数及类型:
- 返回值及类型:
- ret:
table/ nil biometype < 0 时返回 {[biomeId]={{id, weight}}}, biometype > 0 时返回 {{id, weight}}
- ret:
- 该方法的其他说明: 获取生物生成密度(不保存,退出游戏后失效)
- 具体使用案例如下:
lua
local grassLandRules = World:GetWorldCreateMobRule(BiomeType.GrassLand, worldId)
local forestRules = World:GetWorldCreateMobRule(BiomeType.Forest, worldId)SetMobSpawnDensity
- 参数及类型:
- mobType:number
- density:number
- worldId:number|nil
- 返回值及类型: ret:boolean
- 该方法的主要作用:
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local result = World:SetMobSpawnDensity(MobType.Passive, 100, worldId) -- 设置动物密度SetPlantGrowRate
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置农作物生长时间倍率(在原时间上乘以系数;不保存,退出游戏后失效)
- 具体使用案例如下:
lua
local worldId = Actor:GetObjWorldId(playerId or Player:GetHostUin())
local result = World:SetPlantGrowRate(0.5, worldId) -- 设置生长速度为原来的0.5倍SetInnerViewEnable
- 参数及类型:
- iview:
number弹窗类型枚举(InnerPopUpview)InnerPopUpview - bopen:
boolean启用(true)/禁用(false)
- iview:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置某类内置界面是否禁用
- 具体使用案例如下:
lua
-- 一般和Player:OpenInnerView 接口配合使用
local ret = World:SetInnerViewEnable(InnerPopUpview.CollectMaps,false)
if ret then
print("设置成功")
endSetMidJoin
lua
local ret = World:SetMidJoin(true)
if ret then
print("设置成功")
endGetGameMode
- 参数及类型: 无
- 返回值及类型:
- ret:
number/ nil 游戏模式(WorldType)
- ret:
- 该方法的其他说明: 获取当前游戏模式
- 具体使用案例如下:
lua
local curmode = World:GetGameMode()
if curmode and curmode == WorldType.GamemakerRun then
print("当前地图是玩法模式")
elseif curmode and curmode == WorldType.Single then
print("当前地图是冒险模式")
endSetLightByPos
- 参数及类型:
- 返回值及类型:
- ret:
boolean是否设置成功
- ret:
- 该方法的其他说明: 设置指定位置的方块光照强度<1.50+>
- 具体使用案例如下:
lua
local result = World:SetLightByPos(x, y, z, 10, WorldId)
print("设置光照强度 10 ", result)