用户:
1086DRRalsei查看:12 回复:10 评论:12 创建时间:2021-03-14T21:29:42
(可以应用到作品中)
world.onPlayerJoin(({ entity }) => {
entity.player.fall = 0
});
(async function () {
while (true) {
world.querySelectorAll("player").forEach(async (entity) => {
switch (entity.player.moveState) {
case Box喵layerMoveState.FALL:
entity.player.fall += Math.random()
break;
}
entity.onVoxelContact(({ entity }) => {
if (entity.player.fall < 8) {
entity.player.fall = 0;
return;
}
entity.hurt(entity.player.fall)
entity.player.directMessage('[剩余HP:' + entity.hp + ']你受到了' + entity.player.fall + '点摔伤伤害')
entity.player.fall = 0
if (!entity.hp) {
world.say(`${entity.player.name}摔,卒`)
}
});
});
await sleep(60)
}
})()你不能用while True,你要用onTick。你可能不知道为什么,我可以告诉你:两个事件可以嵌套使用,事件传回的属性(如ontick,tick就是属性)不受作用域影响,如果用while true喵循环,那么代码岛3.0的服务器处理不了这么多的指令,并且,onTick会在服务器因为卡顿而跳过某个tick是也一起跳过这次事件,也就是说,onTick起到了调节的作用。
点赞1
评论
//正确代码:
world.onPlayerJoin(({ entity }) => {
entity.player.fall = 0
world.onTick(() => {
if (entity.player.moveState === Box喵layerMoveState.FALL) {
entity.player.fall += Math.random()
break;
}
entity.onVoxelContact(({ entity }) => {
if (entity.player.fall < 4) {
entity.player.fall = 0;
return;
}
entity.hurt(entity.player.fall)
entity.player.directMessage('[剩余HP:' + entity.hp + ']你受到了' + entity.player.fall + '点摔伤伤害')
entity.player.fall = 0
if (!entity.hp) {
world.say(`${entity.player.name}摔,卒`)
}
});
});
await sleep(60);
});
点赞0
评论
幽梦子曦
world.onPlayerJoin(({ entity }) => {
entity.enableDamage = true
entity.player.fall = 0
});
(async function () {
while (true) {
world.querySelectorAll("player").forEach(async (entity) => {
switch (entity.player.moveState) {
case Box喵layerMoveState.FALL:
entity.player.fall += Math.random()
break;
}
entity.onVoxelContact(({ entity }) => {
if (entity.player.fall < 9) {
entity.player.fall = 0;
return;
}
entity.hurt(entity.player.fall)
entity.player.directMessage('[剩余HP:' + entity.hp + ']你受到了' + entity.player.fall + '点摔伤伤害')
entity.player.fall = 0
if (!entity.hp) {
world.say(`${entity.player.name}摔,卒`)
}
});
});
await sleep(60)
}
})()点赞0
评论
科技改变时代world.onVoxelContact(async({entity,x,y,z,voxel})=>{
if (!entity.isPlayer) return;
let i=entity.player.fall-y
if(entity.player.fall-y>15){
entity.hurt(i)
entity.player.directMessage('你受到了'+i+'点摔落伤害,目前血量是:'+entity.hp)
}
entity.player.fall=y
})点赞0
评论