猫史档案馆


求助QAQ人物互动代码怎么写?

用户:BlackShadowBlackShadow查看:283 回复:4 评论:25 创建时间:2022-12-17T11:03:07


需要的效果:人物名字:请选择游戏模式,选择:末世生存,传送到一个坐标,我实在不会了(又又又一次)


回复

上一页第 1 页 / 共 1 页下一页
名探酱名探酱

// 先在场景中放置一个名称为 NPC 的实体。
const npc = world.querySelector('#NPC');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 8;   // 实体的互动范围
npc.interactHint = npc.id; // 互动提示框显示实体的名称
npc.interactColor = new Box3RGBColor(1,0,1);  // 互动提示的文字颜色

// 玩家与实体进行交互时触发
npc.onInteract(async({entity}) => {
        const xz = await entity.player.dialog({
            type: Box3DialogType.SELECT,
            title: npc.id,
            content: `请选择游戏模式:`,
            options: ["末世生存"],
        })
        if (!xz)return;
        if (xz.index == 0){
        entity.poistion.set(x,y,z)
        }
})

点赞2


评论

这个在enable和Interact里报错了咋回事啊...

模型名字改一下

这个模型的名字叫Sapnap,可以帮我改下嘛?我改了,但是他还是报错,可能是我改错了

蟹蟹了,可以了awa

踩到方块后怎么随机出生啊awa


名探酱名探酱

world.onVoxelContact(async({entity,voxel})=>{
if(voxel!=voxels.id('方块名称')||!entity.isPlayer)return;
entity.poistion.set(Math.random()*随机值,y(如果要改就按照之前的),Math.random()*随机值)
})

点赞0


评论

我想问一下,我想做到一个效果:就是在聊天区输入并发送/hc打开一个框,上面有选项,可以简写为选项1,选项2,点击选项会告诉你它的合成方式,这个框的名字叫做MINEZ特殊合成表,麻烦帮我一下,蟹蟹awa


名探酱名探酱

world.onChat(({ entity, message }) => {
    if (message === '/hc') {
        const xz = await entity.player.dialog({
        type:Box3DialogType.SELECT,
        title:'MINEZ特殊合成表',
        content:'',
        options:['选项1','选项2'],
        })
        if(!xz)return;
        if(xz.index == 0){
        const hc = await entity.player.dialog({
        type:Box3DialogType.TEXT,
        title:'选项1',
        content:'', 
        })
    } 
        if(xz.index == 1){
        const hc = await entity.player.dialog({
        type:Box3DialogType.TEXT,
        title:'选项2',
        content:'', 
        })
    } 
})

onchat后面第一个括号里面加async

点赞0


评论

contect里填合成方式

蟹蟹awa

咋报错了啊...

说是(报错内容):SyntaxEorror:await only valid in async function

我说了要加async啊(恼)你看最后

在哪加来着?我有点痴呆...


BlackShadowBlackShadow

world.onChat(async({ entity, message }) => {
    if (message === '/hc') {
        const xz = await entity.player.dialog({
        type:Box3DialogType.SELECT,
        title:'MINEZ特殊合成表',
        content:'请选择',
        options:['木锤','基地核心'],
        })
        if(!xz)return;
        if(xz.index == 0){
        const hc = await entity.player.dialog({
        type:Box3DialogType.TEXT,
        title:'木锤',
        content:'木板×2,木棍×1(其它材质的锤子合成方法类似)', 
        })
    } 
        if(xz.index == 1){
        const hc = await entity.player.dialog({
        type:Box3DialogType.TEXT,
        title:'基地核心',
        content:'金锭×7,电路板×1,天线×1', 
        })
    } 
})

点赞0


评论

报错了吗

是的...

报错了怎么办?

报错内容是什么

就是我几个小时前说的内容...

那个箱子的也会报错...

position

?什么?

太小了箱子,需要要不能推移,而且不能有重力...你那个还是会报错啊...咋办

...探酱,我看见你来了,我那时候在玩实验系列...

我今天下午6点可以做a

我先退MINEZ,要找我6点来MINEZ awa

从高处摔落时,有10%的几率骨折,这个骨折就是跳不了一格高,然后1分30秒后回复正常,就是只能跳一格 求助QWQ