用户:
飞跃的流星丨冲四千粉查看:15 回复:4 评论:15 创建时间:2022-04-15T11:49:43
这个代码报错了,谁能帮帮我
全部代码:
world.onPlayerJoin(({ entity }) => {
entity.onVoxelContact(async({ entity , voxel}) => {
if(voxel == voxels.id('lava02')) {
entity.enableDamage = true;
entity.hurt(10);
sleep(2)
}
})
})
world.onVoxelContact(({ entity, voxel, x, y, z }) => {
if (voxel === voxels.id('carpet_08')) {
entity.hp = entity.maxHp
}
})
world.onDie(async({ entity }) => {
if (!entity.isPlayer) return;
for (let t = 1; t <= 6; t++) {
entity.player.directMessage(`你还有 ${String(6 - t)} 秒后复活`);
await sleep(1000);
}
entity.player.forceRespawn();
});
for (const e of world.querySelectorAll('*')) {//遍历所有实体
if (e.id.startsWith('存档点')) {//如果当前实体名左边部分刚好是"存档点", 比如 存档点-1 存档点-2...
e.collides = true //开启碰撞
e.fixed = true //固定实体不被推移
e.meshScale = e.meshScale.scale(1) //放大2倍
e.onEntityContact(({ other }) => { //每当存档点碰到另一个实体
if (other.isPlayer) { //另一个实体是玩家
if (e.position !== other.player.spawnPoint) { // 检测当前存档点是否玩家重生点, 避免反复在同一个存档点做多余的保存
other.player.directMessage('到达新的重生点') // 给玩家发消息,存档点信息
other.player.spawnPoint = e.position // 玩家重生点坐标设置成存档点的坐标
}
}
})
}
}
world.onPlayerJoin(({ entity }) => {
entity.cundang = 100000000
});
world.onPress(async ({ button, entity, raycast: { hitEntity, distance } }) => {
if (button == "action1") {
const s = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: "操作台",
content: `请选择操作`,
options: [`存档(还剩${entity.cundang}次)`, '退出', '回到存档点']
});
if(!s){return}
if (s.value == `存档(还剩${entity.cundang}次)`) {
if (entity.cundang >= 1) {
entity.cundang -= 1
entity.player.spawnPoint.copy(entity.position)
entity.player.directMessage(`存档成功,次数剩余${entity.cundang}`)
}
else { entity.player.directMessage(`次数不足`) }
}
if (s.value == '回到存档点') {
entity.position.set(entity.player.spawnPoint)}
return
}
})
for (const e of world.querySelectorAll('*')) {//遍历所有实体
if (e.id.startsWith('终点')) {//如果当前实体名左边部分刚好是"终点", 比如 终点-1 终点-2...
e.collides = true //开启碰撞
e.fixed = true //固定实体不被推移
// e.meshScale = e.meshScale.scale(2) //放大2倍
e.onEntityContact(({ other }) => { //每当存档点碰到另一个实体
if (other.isPlayer) { //另一个实体是玩家
if (e.position !== other.player.spawnPoint) { // 检测当前存档点是否玩家重生点, 避免反复在同一个存档点做多余的保存
other.player.directMessage('到达终点!') // 给玩家发消息
other.player.canFly = true
world.say(`恭喜${other.player.name}到达了跑酷终点并获得了飞行奖励`)
other.player.spawnPoint = e.position // 喵家重生点坐标设置成存档点的坐标
}
}
})
}
}
//world.onPress(async({entity,button})=>{
//if(button == Box3ButtonType.ACTION0){
//const say = await entity.player.dialog({
// type:'input',
// title:'请输入要说的话:',
// content:'',
// confirmText:'发送',
//})
//if(say == null||say.length >= 20 ){return}
// world.say(entity.player.name+':'+say)
//}
//})
world.onPlayerJoin(({ entity }) => {
entity.onFluidEnter(() => {
entity.position.copy(entity.player.spawnPoint)
entity.position.y += 0
})
})
world.querySelectorAll('.invisible').forEach((e)=>{e.meshInvisible=true})
const TEST_PLAYER = ['飞跃的流星']
world.onPlayerJoin(({ entity }) => {
if (!TEST_PLAYER.includes(entity.player.name)) return;
world.say(`创作者——${entity.player.name} 出现了!`);
}
world.onDie(({entity})=>{
if(entity.isPlayer){
entity.player.forceRespawn();
}
})
points.forEach((e)=>{
e.level = Number(e.tags()[0]);
e.onEntityContact(({other})=>{
const spawnPoint = e.position.add({x: 0,y: 2.5,z: 0});
if(spawnPoint.equals(other.player.spawnPoint))return;
other.player.spawnPoint = spawnPoint;
other.player.directMessage('存档成功!');
other.level = e.level;
update.call(other);
})
})
function getRecord(){
const result = {};
Object.keys(INIT).forEach((e)=>{
result[e] = this[e];
})
return JSON.stringify(result);
}
function update(){
if(!this.player.userKey)return;
this.x = this.position.x;
this.y = this.position.y;
this.z = this.position.z;
this.qx = this.player.spawnPoint.x;
this.qy = this.player.spawnPoint.y;
this.qz = this.player.spawnPoint.z;
db.sql`UPDATE leaderboard SET record = ${getRecord.call(this)} WHERE id = ${this.player.userKey}`;
}
world.onPlayerLeave(({entity})=>{
update.call(entity);
world.onPlayerJoin(({ entity }) => {
entity.onVoxelContact(async({ entity , voxel}) => {
if(voxel == voxels.id('lava02')) {
entity.enableDamage = true;
entity.hurt(10);
sleep(2)
}
})
})
world.onVoxelContact(({ entity, voxel, x, y, z }) => {
if (voxel === voxels.id('carpet_08')) {
entity.hp = entity.maxHp
}
})
world.onDie(async({ entity }) => {
if (!entity.isPlayer) return;
for (let t = 1; t <= 6; t++) {
entity.player.directMessage(`你还有 ${String(6 - t)} 秒后复活`);
await sleep(1000);
}
entity.player.forceRespawn();
});
for (const e of world.querySelectorAll('*')) {//遍历所有实体
if (e.id.startsWith('终点')) {//如果当前实体名左边部分刚好是"终点", 比如 终点-1 终点-2...
e.collides = true //开启碰撞
e.fixed = true //固定实体不被推移
// e.meshScale = e.meshScale.scale(2) //放大2倍
e.onEntityContact(({ other }) => { //每当存档点碰到另一个实体
if (other.isPlayer) { //另一个实体是玩家
if (e.position !== other.player.spawnPoint) { // 检测当前存档点是否玩家重生点, 避免反复在同一个存档点做多余的保存
other.player.directMessage('到达终点!') // 给玩家发消息
other.player.canFly = true
world.say(`恭喜${other.player.name}到达了跑酷终点并获得了飞行奖励`)
other.player.spawnPoint = e.position // 喵家重生点坐标设置成存档点的坐标
}
}
})
}
}
//world.onPress(async({entity,button})=>{
//if(button == Box3ButtonType.ACTION0){
//const say = await entity.player.dialog({
// type:'input',
// title:'请输入要说的话:',
// content:'',
// confirmText:'发送',
//})
//if(say == null||say.length >= 20 ){return}
// world.say(entity.player.name+':'+say)
//}
//})
world.onPlayerJoin(({ entity }) => {
entity.onFluidEnter(() => {
entity.position.copy(entity.player.spawnPoint)
entity.position.y += 0
})
})
world.querySelectorAll('.invisible').forEach((e)=>{e.meshInvisible=true})
const TEST_PLAYER = ['飞跃的流星']
world.onPlayerJoin(({ entity }) => {
if (!TEST_PLAYER.includes(entity.player.name)) return;
world.say(`创作者——${entity.player.name} 出现了!`);
}
world.onPlayerJoin(({ entity }) => {
entity.cundang = 100000
});
world.onPress(async ({ button, entity, raycast: { hitEntity, distance } }) => {
if (button == "action1") {
const s = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: "操作台",
content: `请选择操作`,
options: [`存档(还剩${entity.cundang}次)`, '退出', '回到存档点']
});
if(!s){return}
if (s.value == `存档(还剩${entity.cundang}次)`) {
if (entity.cundang >= 1) {
entity.cundang -= 1
entity.player.spawnPoint.copy(entity.position)
entity.player.directMessage(`存档成功,次数剩余${entity.cundang}`)
}
else { entity.player.directMessage(`次数不足`) }
}
if (s.value == '回到存档点') {
entity.position.set(entity.player.spawnPoint)}
return
}
})