世界管理(二)
LUA实例应用:世界管理(二)
本本课将会继续学习世界管理接口的相关知识。首先,我们会学习生成和移除道具的方法,接着,我们会学习三角函数和分量的概念,并了解特效的生成和清除方法
视频时间节点:
- 生成和移除道具:14:52
- 投掷物设置:26:04
- 特效设置:34:01
老师介绍:
冰西瓜之战
-- 创建地图区域
local result,areaid=Area:createAreaRectByRange({x=15,y=7,z=15},{x=-16,y=7,z=-16})
if(result == 1001)
then
Chat:sendSystemMsg("创建区域失败")
end
local result,pos=Area:getRandomPos(areaid)
if(result == 1001)
then
Chat:sendSystemMsg("随机区域内的点失败")
end
Block:replaceBlock(239,pos.x,pos.y,pos.z,0)
-- 西瓜片列表
local melon_list = {}
-- 向某个水平方向发射投掷物,参数是发射者,投掷物id,发射的位置xyz,角度以及速度
local function turret(eventobjid, itemid, x, y, z, angle, speed)
World:spawnProjectileByDir(eventobjid, itemid, x, y, z, math.cos(angle), 0, math.sin(angle), speed)
end
-- 方块被破坏时运行
local function Block_DestroyBy(event)
if(event.blockid == 239)
then
-- 重置西瓜
for k,v in pairs(melon_list)
do
World:despawnItemByObjid(v)
end
result,pos=Area:getRandomPos(areaid)
if(result == 1001)
then
Chat:sendSystemMsg("随机区域内的点失败")
end
Block:replaceBlock(239,pos.x,pos.y,pos.z,0)
-- 创建西瓜片
for i=1,5
do
local result,pos=Area:getRandomPos(areaid)
if(result == 1001)
then
Chat:sendSystemMsg("随机区域内的点失败")
end
local result,objid=World:spawnItem(pos.x,pos.y,pos.z,12508,1)
melon_list[#melon_list + 1] = objid
if(result == 1001)
then
Chat:sendSystemMsg("创建西瓜片失败")
end
end
-- 创建动物肥料
for i=1,5
do
local result,pos=Area:getRandomPos(areaid)
if(result == 1001)
then
Chat:sendSystemMsg("随机区域内的点失败")
end
local result,objid=World:spawnItem(pos.x,pos.y,pos.z,11311,1)
if(result == 1001)
then
Chat:sendSystemMsg("创建动物肥料失败")
end
end
end
end
-- 道具被拾取时运行
local function Item_Pickup(event)
if(event.itemid == 11311)
then
Actor:addBuff(event.eventobjid,1000,3,100)
elseif(event.itemid == 12508)
then
local result,num,arr=Backpack:getItemNumByBackpackBar(event.eventobjid,1,event.itemid)
if(result == 1001)
then
Chat:sendSystemMsg("获取道具数量失败")
end
if(num >= 10)
then
local result=Player:setGameWin(event.eventobjid)
if(result == 1001)
then
Chat:sendSystemMsg("使玩家胜利失败")
end
end
end
end
-- 投掷物击中目标时运行
local function Actor_Projectile_Hit(event)
--Chat:sendSystemMsg(event.itemid)
end
-- 注册方块被破坏监听器
ScriptSupportEvent:registerEvent([=[Block.DestroyBy]=], Block_DestroyBy)
-- 注册道具被拾取监听器
ScriptSupportEvent:registerEvent([=[Item.Pickup]=], Item_Pickup)
-- 注册投掷物击中目标监听器
ScriptSupportEvent:registerEvent([=[Actor.Projectile.Hit]=], Actor_Projectile_Hit)