用户:指令者查看:0 回复:0 评论:0 创建时间:2021-02-22T19:51:37
/*
world.onVoxelContact(({ entity, axis, x, y, z }) => {
if (entity.isPlayer) {
if (axis.y < 1 && axis.y > -1) {
if (voxels.getVoxelId(x, y + 1, z) == voxels.id('air')) {
entity.velocity.y = 0.53;
}
}
}
});
*/
function SIA(Array, Things) {
for (i = 0; i < Array.length; i++) {
if (Things == Array[i]) {
return true
} else {
return false
}
}
}
var cbv = [105, 119, 363, 391, 157, 159]//英文名can't be break voxels(不可被破坏的方块)
world.onPress(({ entity, voxel, button, raycast: { voxelIndex, normal, hitVoxel, hitEntity, direction, distance } }) => {
if (distance >= 8) {
return;
}
if (button === 'action1') {
let pv = hitVoxel
console.log(pv)
if (cbv.includes(pv) == true) { entity.player.directMessage('不可破坏此方块'); return }
voxels.setVoxel(voxelIndex.x, voxelIndex.y, voxelIndex.z, 0)
} else if (button === 'action0') {
let v = voxelIndex.add(normal);
voxels.setVoxel(v.x, v.y, v.z, 'white')
/*
world.onPlayerJoin(({ entity }) => {
entity.enableDamage = true;
if (button !== 'action0' || !hitEntity) {
return;
}
if (hitEntity.team == entity.team) {
return;
}
if (hitEntity.isPlayer === true) {
if (entity.player.lv == 0) {
hitEntity.velocity.x += direction.x;
hitEntity.velocity.y += 0.5;
hitEntity.velocity.z += direction.z;
} else {
hitEntity.velocity.x += direction.x * entity.player.lv;
hitEntity.velocity.y += 0.5 * entity.player.lv;
hitEntity.velocity.z += direction.z * entity.player.lv;
}
}
hitEntity.hurt(20 * Math.random() + 0, {//伤害取值0.2~20
attacker: entity,
}); if (entity.player.name == "指令者") {//这是外挂里面写谁的名字都可以
hitEntity.hurt(Infinity, {
attacker: entity,
});
}
});
*/
//PVP代码,有问题
}
})
world.onPlayerJoin(({ entity }) => {
entity.enableDamage = true;
entity.player.onPress(({ button, raycast: { hitEntity, direction } }) => {
if (entity.pt === hitEntity.pt) return; // 相同队伍不处理
if (distance >= 8) {
return;
}
if (button !== 'action0' || !hitEntity) {
return;
}
if (hitEntity.isPlayer === true) {
if (entity.player.lv == 0) {
hitEntity.velocity.x += direction.x;
hitEntity.velocity.y += 0.5;
hitEntity.velocity.z += direction.z;
} else {
hitEntity.velocity.x += direction.x * entity.player.lv;
hitEntity.velocity.y += 0.5 * entity.player.lv;
hitEntity.velocity.z += direction.z * entity.player.lv;
}
}
hitEntity.hurt(20 * Math.random() + 5, {
attacker: entity,
});
if (entity.player.name == "指令者") {//这是外挂里面写谁的名字都可以
hitEntity.hurt(999, {
attacker: entity,
});
}
});
});
world.onDie(({ entity, attacker }) => {
if (attacker) {
world.say(attacker.player.name + ' 击杀了 ' + entity.player.name)
attacker.player.exp += 10
entity.player.exp -= 10
}
});
world.onTakeDamage(({ entity, damage, attacker }) => {
if (!entity.isPlayer) return;
const attackerName = attacker.isPlayer ? attacker.player.name : attacker.id;
entity.player.directMessage(`[剩余HP: ${entity.hp}]: 你受到了${damage}点来自@${attackerName}的伤害`);
});
const teams = ['红', '黄', '蓝', '绿'];
const tpx = [121, 5, 5, 121]; const tpz = [5, 4, 121, 121]; const color = [[1, 0, 0], [1, 1, 0], [0, 0, 1], [0, 1, 0]]
world.onPlayerJoin(({ entity: e }) => {
e.player.pt = Math.floor(Math.random() * 4)
e.player.team = teams[e.player.pt]
e.position.set(tpx[e.player.pt], 11, tpz[e.player.pt])
e.player.spawnPoint.copy(e.position)
e.player.forceRespawn()
e.player.color = new Box3RGBColor(color[e.player.pt][0], color[e.player.pt][1], color[e.player.pt][2])
e.player.dialog({
type: Box3DialogType.SELECT,
title: '分队提示',
content: `${e.player.name},你被分到了${teams[e.player.pt]}队`,
options: ['确定'],
})
e.player.cameraMode = "fps"//第一人称视角
e.player.exp = 0
e.player.lv = 0
e.player.enable3DCursor = true;
e.player.enableDoubleJump = false;
})
world.querySelectorAll('.奖杯').forEach((e) => {
e.onEntityContact(({ other }) => {
let maxKd = 0; // 最高的kd
let maxKdPlayer; // 最高kd的玩家
// 计算每个玩家的KD并记录最高值
const kd = exp/10
// 告知每个玩家本局的kd
other.player.directMessage(`你本场游戏的评分为${kd.toFixed(2)}`);
// 更新最大kd
if (kd > maxKd) {
maxKd = kd;
maxKdPlayer = name;
}
// 喵家设置为非游戏状态
other.enableDamage = false;
other.player.cameraMode = 'FOLLOW';
other.player.color.set(1, 1, 1);
// 广播MVP(kd最高者)
world.say(`本场游戏MVP为@${maxKdPlayer}, 评分是${maxKd.toFixed(2)}`);
(async () => {
for (y = 0; y < 128; y++) {
for (x = 0; x < 128; x++) {
for (z = 0; z < 128; z++) {
if (voxels.getVoxel(x, y, z) == voxels.id('white')) {
voxels.setVoxel(x, y, z, voxels.id('air'))
}
}
}
}
})()
other.player.pt = Math.floor(Math.random() * 4)
other.player.team = teams[other.player.pt]
other.position.set(tpx[other.player.pt], 11, tpz[other.player.pt])
other.player.spawnPoint.copy(other.position)
other.player.forceRespawn()
other.player.color = new Box3RGBColor(color[other.player.pt][0], color[other.player.pt][1], color[other.player.pt][2])
other.player.dialog({
type: Box3DialogType.SELECT,
title: '分队提示',
content: `${other.player.name},你被分到了${teams[other.player.pt]}队`,
options: ['确定'],
})
other.player.cameraMode = "fps"//第一人称视角
other.player.exp = 0
other.player.lv = 0
other.player.enable3DCursor = true;
other.player.enableDoubleJump = false;
})
})
/*
async function chongsheng(entity) {//定义函数名为重生(chongsheng)
for (let i = 5; i > 0; --i) {
entity.position = new Box3Vector3(喵, 160, 喵)//位置为地图中间的高处
entity.fixed = true//禁止移动
entity.player.directMessage(`你将在 ${String(i)} 秒后重生`);//私信玩家
await sleep(1000);
};//倒计时5秒后重生
entity.player.forceRespawn();//强制重生
world.say(entity.player.name + '重生了');//广播重生消息
entity.fixed = false//禁止移动
}//万能框架
world.onDie(({ entity }) => {
chongsheng(entity)
});//当玩家喵亡时执行重生函数
console.log('event handlers installed');
*/
//背包
world.onPlayerJoin(async ({ entity }) => {
world.addCollisionFilter('player', 'player');
if (entity.player.boxId === null) { return; }
//entity.enableDamage = true;
//entity.player.Presss=0
//entity.player.armss='加特林'
//entity.player.cameraMode='fps';
//entity.player.cooling=0
world.createEntity({
mesh: 'mesh/我的世界背包.vb',
id: entity.player.boxId,
position: entity.position,
enableInteract: true,
interactRadius: 5,
})
world.querySelectorAll('#' + entity.player.boxId).forEach(async (b) => {
b.addTag('玩家背包')
b.ps = entity
b.meshInvisible = true;
b.collides = false
b.gravity = false
b.onInteract(async ({ entity: user, targetEntity }) => {
const re = await user.player.dialog({
type: Box3DialogType.SELECT,
title: `背包`,
content: '请选择:',
options: [
'击退1阶',
'击退2阶',
'击退3阶',
'击退4阶',
'击退5阶',
],
})
if (!re || re === null) { return; }
// 判断玩家选了什么选项。
switch (re.index) {
case 0:
if (entity.player.lv >= 1) {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你有了更高级别的击退`,
options: ['确定'],
})
} else if (entity.player.exp >= 20) {
entity.player.exp -= 20
entity.player.lv = 1
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级成功',
content: `${entity.player.name}` / n`exp-20` / n`lv+1` / n`击退升到1阶!`,
options: ['确定'],
})
} else {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你的exp不够`,
options: ['确定'],
})
}
break;
case 1:
if (entity.player.lv >= 2) {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你有了更高级别的击退`,
options: ['确定'],
})
} else if (entity.player.exp >= 40) {
entity.player.exp -= 40
entity.player.lv = 2
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级成功',
content: `${entity.player.name}` / n`exp-40` / n`lv+1` / n`击退升到2阶!`,
options: ['确定'],
})
} else {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你的exp不够`,
options: ['确定'],
})
}
break;
case 2:
if (entity.player.lv >= 3) {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你有了更高级别的击退`,
options: ['确定'],
})
} else if (entity.player.exp >= 80) {
entity.player.exp -= 80
entity.player.lv = 3
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级成功',
content: `${entity.player.name}` / n`exp-80` / n`lv+1` / n`击退升到3阶!`,
options: ['确定'],
})
} else {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你的exp不够`,
options: ['确定'],
})
}
break;
case 3:
if (entity.player.lv >= 4) {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你有了更高级别的击退`,
options: ['确定'],
})
} else if (entity.player.exp >= 160) {
entity.player.exp -= 160
entity.player.lv = 4
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级成功',
content: `${entity.player.name}` / n`exp-160` / n`lv+1` / n`击退升到4阶!`,
options: ['确定'],
})
} else {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你的exp不够`,
options: ['确定'],
})
}
break;
case 4:
if (entity.player.lv = 5) {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你的击退是满级了!`,
options: ['确定'],
})
} else if (entity.player.exp >= 320) {
entity.player.exp -= 320
entity.player.lv = 5
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级成功',
content: `${entity.player.name}` / n`exp-320` / n`lv+1` / n`击退升到5阶!`,
options: ['确定'],
})
} else {
entity.player.dialog({
type: Box3DialogType.SELECT,
title: '升级失败',
content: `${entity.player.name},你的exp不够`,
options: ['确定'],
})
}
break;
default:
// 注意,使用 switch 分支的时候,不要漏了后面的 break;
}
})
})
})
setInterval(() => {
world.querySelectorAll('.玩家背包').forEach(async (b) => {
const pl = b.ps
b.position.set(b.ps.position.x, b.ps.position.y + 3, b.ps.position.z)
})
}, 1);