【攻略】想制作地图但不会写程序?没关系!您也能使用lua设备方块!

大家好 我是misk。
相信有很多接触studio的玩家都有看过这个方块,但却不知道这个方块的用途,
而这个方块是什么呢?就是函数调用Script方块(这边简称为蓝lua)。
这边先说明这颗方块的用处。
这个方块能在游戏中调用lua函数,举一个比较贴近生活的例子,今天您想跟一位朋友聊天,但是你们身处在不同地点,这时候就需要电话,而电话就是蓝lua,也就是负责连接你(游戏)跟朋友(lua)的桥梁。有的时候你需要使用蓝lua来达成一般设备方块做不到的事情,例如重置设备方块。

但我就是不会写程序阿,怎么办?没关系,本人写了一些比较实用的指令让大家使用,让大家也能在不会写程序的情况下,使用蓝lua达成重置设备方块,更改玩家金钱、血量等功能。

首先介绍一下蓝lua方块的接口。

按E打开蓝lua方块接口,应该会是这个样子。
(上面是指令名称,下方是要设置的参数。)
接下来,您需要复制以下代码到Game.lua中。
(如果不知道Game.lua的文件位置,请参考这篇。

function pos_transform(str)

    — x座标
    locate = string.find(str, “,”, 1)
    x = string.sub(str, 1, locate – 1)
    str = string.gsub(str, x .. “,”, “”, 1)
    x = math.floor(x)

    — y座标
    locate = string.find(str, “,”, 1)
    y = string.sub(str, 1, locate – 1)
    str = string.gsub(str, y .. “,”, “”, 1)
    y = math.floor(y)

    — z座标
    z = math.floor(str)

    return {x = x, y = y, z = z}
end

— 重置设备方块
function Reset(onoff, position)
    if onoff == false then
        return
    end
    EntityBlock = Game.EntityBlock:Create(pos_transform(position))
    EntityBlock:Event({action = “reset”})
end
— 发送玩家位置
function Convey(onoff, position)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end

    player.position = pos_transform(position)
end
— 增加玩家金币
function Add_coin(onoff, coin)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.coin = player.coin + math.floor(coin)
end
— 更改玩家金币
function Change_coin(onoff, coin)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.coin = math.floor(coin)
end
— 更改玩家最大血量
function Change_maxhealth(onoff, maxhealth)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.maxhealth = math.floor(maxhealth)
end
— 增加玩家最大血量
function Add_maxhealth(onoff, maxhealth)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.maxhealth = player.maxhealth + math.floor(maxhealth)
end
— 更改玩家血量
function Change_health(onoff, health)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.health = math.floor(health)
end
— 增加玩家血量
function Add_health(onoff, health)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.health = player.health + math.floor(health)
end
— 更改玩家最大护甲
function Change_maxarmor(onoff, maxarmor)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.maxarmor = math.floor(maxarmor)
end
— 增加玩家最大护甲
function Add_maxarmor(onoff, maxarmor)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.maxarmor = player.maxarmor + math.floor(maxarmor)
end
— 更改玩家护甲
function Change_armor(onoff, armor)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.armor = math.floor(armor)
end
— 更改玩家护甲
function Add_armor(onoff, armor)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end
    
    player.armor = player.armor + math.floor(armor)
end

— 杀死玩家
function Kill(onoff)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end

    player:Kill()
end

— 移除武器
function Remove_weapon(onoff)
    if onoff == false then
        return
    end

    if Game.GetTriggerEntity() ~= nil then
        player = Game.GetTriggerEntity():ToPlayer()
    else
        return
    end

    player:RemoveWeapon()
end

— 所有玩家复活
function Allplayer_spawn(onoff)
    if onoff == false then
        return
    end
    Game.Rule:Respawn()
end

而指令有那些呢?我写了一些自制指令列在下方。
Reset    
重置一个设备方块(参数为位置,详细在下方说明)。
Convey        
将玩家发送(参数为位置,详细在下方说明)。
Add_coin
增加玩家金币(参数为金币数量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。
Change_coin
更改玩家金币(参数为金币数量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。
Add_maxhealth
增加玩家最大血量(参数为血量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。
Change_maxhealth
更改玩家最大血量(参数为血量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。
Add_health         
增加玩家血量(参数为血量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。
Change_health
更改玩家血量(参数为血量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。
Add_maxarmor
增加玩家最大护甲(参数为护甲量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。

Change_maxarmor
更改玩家最大护甲(参数为护甲量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。

Add_armor
增加玩家护甲(参数为护甲量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。

Change_armor
更改玩家护甲(参数为护甲量(整数))。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。

Kill   
杀死玩家(不须填入参数)。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。

Remove_weapon 
移除玩家武器(不须填入参数)。
注意:若使用该指令,设备方块与蓝lua之间不得有任何逻辑方块,例如and, or等。

Allplayer_spawn 
让所有玩家复活(不须填入参数)。

*位置参数
如果位置为(x = 0, y = 0, z = 0),参数就填0,0,0
同样的,如果位置为(x = -80, y = 100, z = 0),参数就填-80,100,0
下方图片为举例(重置一个位置为(x = -80, y = 100, z = 0)的设备方块):
*不允许中间接上逻辑方块的指令
有些指令不允许中间有逻辑方块,下方说明正确的连接方式。
正确(中间无连接逻辑方块)
错误(中间连接了逻辑方块)
也就是说,设备方块下一个连接点必须是蓝lua,另外标靶,怪物目标方块等设备也无法使用于这类指令,因为这些设备方块并未由玩家直接操作。

目前想到了这些指令,如果有新的想法会增加上去,另外如果有问题或是想法也可以提出来,谢谢大家观看,祝大家圣诞节快乐!

本文来自网络,不代表3楼猫立场,转载请注明出处:https://www.3loumao.org/8061.html
返回顶部