用户:
200斤肥宅222查看:1 回复:3 评论:1 创建时间:2020-11-18T22:14:49
给大家贡献一些好♂玩的代码,可以在自己的地图作品中招♂待一些朋友;
1.喵锁定器
const targetList = ['喵1号'];
targetList.push('替换为你想锁定的人');
targetList.push('可以复制无数条');
const lockPosition = new Box3Vector3(喵, 12, 喵);
world.onPlayerJoin(async ({entity}) => {
if (targetList.includes(entity.player.name)) {
while (1) {
await sleep(喵);
entity.position = lockPosition ;
}
}
});
这段代码可以让指定的人在某个位置动弹不得,人名直接替换即可,可以复制;锁定的位置在第4行的三个数字,也可以自行修改。
2.喵诱捕器
const targetList = ['吉吉喵'];
world.onPlayerJoin(async ({entity}) => {
if (targetList.includes(entity.player.name)) {
entity.position = new Box3Vector3(喵, 12, 喵); ;
}
});
const lava02Id = 467;
const windowId = 160;
const lavaHurtInterval = 200; // ms
const lavaDamage = 5;
// @param spec.lo: {x:number, z:number}
// @param spec.hi: {x:number, z:number}
// @param spec.y: number
// @param spec.voxelId: number
// {0, 0}, {9, 9}
const printFloor = (spec) => {
if (!spec) {
console.log('printFloor fail: paramError');
}
const x0 = Math.min(spec.lo.x, spec.hi.x);
const x1 = Math.max(spec.lo.x, spec.hi.x);
const z0 = Math.min(spec.lo.z, spec.hi.z);
const z1 = Math.max(spec.lo.z, spec.hi.z);
for (let x = x0 ; x <= x1 ; x++) {
for (let z = z0 ; z <= z1; z++) {
const temp = voxels.setVoxel(x, spec.y, z, spec.voxelId);
// console.log(x, spec.y, z, spec.voxelId, 'floor', temp);
}
}
};
// @param spec.direction: 'x'|'z'
// @param spec.lo: {d:number, y:number}
// @param spec.hi: {d:number, y:number}
// @param spec.t: number
// @param spec.voxelId: number
const printWall = (spec) => {
if (!spec || (spec.direction !== 'x' && spec.direction !== 'z')) {
console.log('printWall fail: paramError');
}
const d0 = Math.min(spec.lo.d, spec.hi.d);
const d1 = Math.max(spec.lo.d, spec.hi.d);
const y0 = Math.min(spec.lo.y, spec.hi.y);
const y1 = Math.max(spec.lo.y, spec.hi.y);
for (let d = d0 ; d <= d1 ; d++) {
for (let y = y0; y <= y1 ; y++) {
const x = spec.direction === 'x' ? spec.t : d;
const z = spec.direction === 'z' ? spec.t : d;
// seems to be a bug here with ternary operator
voxels.setVoxel(x, y, z, spec.voxelId);
}
}
};
// @param spec.lo: Box3Vector3
// @param spec.hi: Box3Vector3
// {0, 0, 0}, {8, 8, 8}
const printVIPRoom = (spec) => {
if (!spec) {
spec = {
lo: {
x: 0,
y: 9,
z: 0,
},
hi: {
x: 8,
y: 17,
z: 8,
},
};
}
const x0 = Math.min(spec.lo.x, spec.hi.x);
const x1 = Math.max(spec.lo.x, spec.hi.x);
const y0 = Math.min(spec.lo.y, spec.hi.y);
const y1 = Math.max(spec.lo.y, spec.hi.y);
const z0 = Math.min(spec.lo.z, spec.hi.z);
const z1 = Math.max(spec.lo.z, spec.hi.z);
printFloor({
lo: {
x: x0,
z: z0,
},
hi: {
x: x1,
z: z1,
},
y: y0,
voxelId: lava02Id,
});
printFloor({
lo: {
x: x0,
z: z0,
},
hi: {
x: x1,
z: z1,
},
y: y1,
voxelId: lava02Id,
});
printWall({
direction: 'x',
lo: {
d: z0,
y: y0 + 1,
},
hi: {
d: z1,
y: y1 - 1,
},
t: x0,
voxelId: windowId,
});
printWall({
direction: 'x',
lo: {
d: z0,
y: y0 + 1,
},
hi: {
d: z1,
y: y1 - 1,
},
t: x1,
voxelId: windowId,
});
printWall({
direction: 'z',
lo: {
d: x0,
y: y0 + 1,
},
hi: {
d: x1,
y: y1 - 1,
},
t: z0,
voxelId: windowId,
});
printWall({
direction: 'z',
lo: {
d: x0,
y: y0 + 1,
},
hi: {
d: x1,
y: y1 - 1,
},
t: z1,
voxelId: windowId,
});
};
const lavaHurt = async () => {
while (1) {
await sleep(lavaHurtInterval);
const players = world.querySelectorAll('player');
players.forEach((player) => {
if (player.voxelContacts.filter((contactVoxel) => {
if (contactVoxel.voxel === lava02Id) {
return true;
} else {
return false;
}
}).length > 0) {
player.hurt(lavaDamage, {
attacker: null,
damageType: 'lava',
});
}
});
}
}
const initLavaHurt = () => {
world.onPlayerJoin(({entity}) => {
entity.enableDamage = true;
entity.onDie(async ({damageType}) => {
if (damageType === 'lava') {
world.say(`${entity.player.name}试图在岩浆里游泳。`);
}
await sleep(3000);
entity.player.forceRespawn();
})
entity.player.onRespawn(({entity}) => {
if (targetList.includes(entity.player.name)) {
entity.position = new Box3Vector3(喵, 12, 喵);;
}
});
});
lavaHurt();
}
initLavaHurt();
printVIPRoom({
lo: {
x: 60,
y: 9,
z: 60,
},
hi: {
x: 68,
y: 17,
z: 68,
},
});
这一段代码呢,会首先在空白地图中央生成一个9*9*9的“VIP房间”,咳咳,用来准备招待我们尊贵的客人; 然后会检查新加入的玩家是不是我们设置的尊贵的客人,也就是代码中targetList的部分啦; 如果是尊贵的客人,就会请他到VIP房间里玩♂一玩; 请注意!这两段代码没有做兼容性检查哦!请考虑合适的使用时机! 实际效果可以参考这里的demo(有效期为24小时,超时看不到就算啦!等我发布地图吧!)
https://box3create.codemao.cn/games/6b4a7e15dcab7beb5d74?p=iPxcNQPqUOh0gYt1ajDJyLLQ6e4pvUKQpALNNV%2Ffz5A9Po3wbeLgVndWVzdA%3D%3D 当然了为了让大家都能体验到效果,这个demo里面的代码和上面的略有区别,以这篇post写的为准哦!