首页
课程中心
LUA实例应用
世界管理(二)
世界管理(二)
小燕 更新时间: 2022-08-25 11:20:35

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)
课程目录
共50节
1 事件系统
2 世界事件
3 游戏逻辑事件
4 玩家事件(一)
5 玩家事件(二)
6 玩家事件(三)
7 玩家事件(四)
8 生物事件
9 方块与道具事件
10 世界管理(一)
11 世界管理(三)
12 世界管理(二)
13 方块管理(一)
14 方块管理(二)
15 Actor管理(一)
16 Actor管理(二)
17 Actor管理(三)
18 玩家管理(一)
19 玩家管理(二)
20 生物管理
21 区域管理(一)
22 区域管理(二)
23 区域管理(三)
24 联机管理
25 背包管理
26 文字板管理
27 容器管理
28 自定义UI管理(一)
29 自定义UI管理(二)
30 自定义UI管理(三)
31 自定义UI应用(一)
32 自定义UI应用(二)
33 自定义UI应用(三)
34 自定义UI应用(四)
35 考试系统
36 购物商城(一)
37 购物商城(二)
38 计算器
39 打击类音游
40 弹球游戏
41 追逐游戏
42 空战游戏(一)
43 空战游戏(二)
44 空战游戏(三)
45 颜色跳跳
46 炮台挑战
47 炸弹游戏
48 推箱子
49 心跳水立方
50 塔防游戏
站点有内容要更新是否更新。
更新
忽略