猫史档案馆


【教程贴】BOX3-制作摔落伤害

用户:Star_Ink_sansStar_Ink_sans查看:29 回复:17 评论:29 创建时间:2022-03-15T11:14:49


代码如下:

//将可伤害开启
world.onPlayerJoin(({ entity }) => {
    entity.enableDamage = true;
});

//摔落伤害
world.onVoxelContact(async ({ entity, x, y, z, voxel }) => {
    if (!entity.isPlayer) return;
    let i = entity.player.fall - y
    if (entity.player.fall - y > 10) {
        entity.hurt(i * 3)
        entity.player.directMessage('你受到了' + i * 3 + '点摔落伤害,目前血量是:' + entity.hp)
    }
    entity.player.fall = y
});

//处理特殊情况:水方块
world.onFluidEnter(async({entity,voxel})=>{
        if(!entity.isPlayer){return;}
        entity.player.fall=0
    })


//这里的复活代码@吉吉喵
world.onDie(async({ entity }) => { 
    if (!entity.isPlayer) return;  

    for (let t = 1; t <= 5; t++) {
        entity.player.directMessage(`倒计时 ${String(5 - t)} 秒后复活`);
        await sleep(1000);
    }

    entity.player.forceRespawn();  
});

 


回复

上一页1 页 / 共 1下一页
Stephan轩Stephan轩

其实方块检测有缺陷的,如果你从半空中落下,而且在摔落前没有接触到任何方块,那就没有摔落伤害了

点赞1


评论


小白鸡小白鸡

~~~~

点赞0


评论


该账号已停用该账号已停用

你这个不可以叫教程贴了,可以叫个干货贴(emotion_doge

点赞0


评论


yee089yee089

喵d

点赞0


评论


我爱Kitten我爱Kitten

这……bug用个axis就可以解决

点赞0


评论


Star_Ink_sansStar_Ink_sans

为啥要挖坟啊啊啊啊啊()

点赞0


评论


此号已被封067此号已被封067

center_image

点赞0


评论


我爱Kitten我爱Kitten

私有属性都不定义;控制台:“我直接给你来个报错()”()))))

点赞0


评论


我爱Kitten我爱Kitten

()()()

点赞0


评论


马云编程猫马云编程猫

收藏夹里见!

点赞0


评论


源码工厂蓝仔源码工厂蓝仔

 

entity.player.fall
//这是什么?

点赞0


评论


源码工厂蓝仔源码工厂蓝仔

怎么在图形化里判断有没有碰到东西?

点赞0


评论


kessicekessice

好码收下

点赞0


评论


永恒跳动的红色火焰永恒跳动的红色火焰

顶上去

点赞0


评论


Initially_silenceInitially_silence

怎么没效果

点赞0


评论


SCS_user_rUu1OtmY5iSCS_user_rUu1OtmY5i

挖坟

点赞0


评论


SCS_user_teLeIed6GGSCS_user_teLeIed6GG

挖。

点赞0


评论