用户:
Mini_edit查看:0 回复:0 评论:0 创建时间:2022-12-16T17:14:45
游玩链接:box3.fun/p/ben-pao-ba-sheng-dan-lao-ren
制作人员:
迷你世界742813666 ()(我自己)
我是全能的……
招人通告:
要会SQL存档
请来https://box3.codemao.cn/e/00d535f2de1e118a3e9d谢谢!
//源代码(都给你们开源了还不关注!?哼╭(╯^╰)╮):
//ctri+H=替换
// 检测玩家是否正在奔跑或者行走,出现对应的粒子效果
world.onPlayerJoin(({ entity }) =>
{
world.onTick((tick) => { PlayerUpdate(entity)});
});
// 蓝色粒子
const particle_blueCrystal = {
particleRate: 1000,
particleLifetime: 2,
particleSize: [8, 6, 4, 2, 0.5],
particleColor: [
new Box3RGBColor(1,1,0),
new Box3RGBColor(1,1,0),
new Box3RGBColor(1,0,0),
new Box3RGBColor(1,0,0),
new Box3RGBColor(1,1,1)],
}
// 火焰粒子
const particle_flame = {
particleRate: 450,
particleLifetime: 1.75,
particleSize: [2, 0.65, 0.23],
particleColor: [
new Box3RGBColor(0,0,1),
new Box3RGBColor(0,1,1),
new Box3RGBColor(1,1,1)],
}
function PlayerUpdate(entity) {
// 判断行走状态
switch (entity.player.walkState) {
// 正在奔跑
case Box喵layerWalkState.RUN:
Object.assign(entity, particle_blueCrystal);
entity.coin = entity.coin + 0.03
break;
// 正在行走
case Box喵layerWalkState.WALK:
Object.assign(entity, particle_flame);
entity.coin = entity.coin + 0.02
break;
// 在其他行走状态不显示粒子
default:
Object.assign(entity, { particleRate: 0 });
entity.coin = entity.coin + 0.01
};
};
world.onPlayerJoin(async ({ entity }) => {
//初始化玩家属性
entity.coin = 0//初始步数
entity.player.onPress(async ({ button }) => {//右键显示状态栏
if (button == Box3ButtonType.ACTION1) {
const sel = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.player.name}的个人中心❤`,
content:
`
❤名字:${entity.player.name}
❤玩家唯一识别码:${entity.player.userKey}
❤当前坐标:${entity.position}
❤当前朝向:${entity.player.facingDirection}
❤步数值:${entity.coin}
`,
options: ['保存系统正在开发中……','退出个人中心'],
})
if (sel) {
if (sel.value == '保存') {//选择【保存】按钮
}
}}
}
)
})
world.onPlayerJoin(({entity})=>{
world.gravity=-0.1
with(entity.player){
cameraDistance=5;
cameraFovY=0.5;
enableDoubleJump=false;
jumpPower=0.6;
jumpAccelerationFactor=0.625
scale=0.5
}
})
//打开3D光标
world.onPlayerJoin(({ entity }) => {
entity.player.enable3DCursor = true // 开启方块光标
})
//将可伤害开启
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();
});
// 点击鼠标右键(B),弹出对话框,视线变为俯视
world.onPlayerJoin(({ entity }) => {
entity.player.onPress(async ({ button }) => {
if (button == Box3ButtonType.ACTION1) {
// 将摄像机看向地图中心
const lookTarget = new Box3Vector3(63, 8, 63);
// 将摄像机的位置置于地图大概中心处,并往上拉升到y轴150处,确保看到完整的地形
const lookEye = new Box3Vector3(63, 150, 63);
// lookUp用来调整相机角度,可以使画面上下左右颠倒。默认值是(0,1,0)
// 由于视线是俯视,需要确保lookUp与相机视线方向不平行,需修改为(1,0,0)或者(0,0,1)
const lookUp = new Box3Vector3(1, 0, 0)
entity.player.dialog({
type: Box3DialogType.TEXT,
content: `卫星云图预览`,
lookEye: lookEye,
lookTarget: lookTarget,
lookUp: lookUp
})
}
})
})
//提示消息函数
async function Outprinthelp(space_time) {
const time = space_time * 1000 //将秒转化成毫秒,方便使用本函数
while (true) {
await sleep(time)
world.say(`按右键可以卫星云图预览哟~`)
}
}
Outprinthelp(100) //每100秒显示提示消息
world.onPlayerJoin(({entity})=>{
entity.time1=0;
})
world.onTick(()=>{
world.querySelectorAll('player').forEach((entity)=>{
if(entity.player.walkState==''){
entity.time1++;
}
else{
entity.time1=0;
}
if(entity.time1>=1000){
entity.player.kick();
world.say(`【系统提示⚠】:${entity.player.name}挂机被踢出服务器`)
entity.time1=0;
}
})
})
//玩家互动系统
world.onPlayerJoin(({ entity }) => {
entity.player.message1 = "";
entity.player.interactTimes = 0;
entity.enableInteract = true;//设置所有玩家互动
entity.interactRadius = 3;//互动格数为三格
entity.interactHint = "与@" + entity.player.name + "@互动";//玩家头顶上会冒出提示语
entity.onInteract(async ({ entity, targetEntity }) => {//新建对话框
const result = await entity.player.dialog({//新建对话框
type: Box3DialogType.SELECT,//设置对话框类型为选择框
title: '访问' + targetEntity.player.name + "的个人主页",//对话框标题。通常对应是讲话人的名字。
content: `和@ ${targetEntity.player.name} 互动\n该用户唯一识别码:${targetEntity.player.userKey}`,
options: ['和TA私聊','退出互动'], // 将提供玩家选择的选项放入数组里。
})
// 如果玩家点击了屏幕其他区域,取消了对话框。
if (!result || result === null) {//判断玩家点击了屏幕其他区域,取消了对话框。
entity.player.directMessage('已为你自动取消互动!');//向玩家发送私聊消息:'已为你自动取消互动!'
return;//回来
}
if (result.index == 0) {//选择【和TA私聊】按钮
const dialog = await entity.player.dialog({
type: Box3DialogType.INPUT,//设置对话框类型为输入框
title: "向 " + targetEntity.player.name + " 发送私聊信息",//对话框标题。通常对应是讲话人的名字。
content: `${entity.player.name},请输入私聊内容`,//输入框提示语
confirmText: '发送消息', // 确定按钮上面的文字。按下确定按钮后,提交回答。
placeholder: '请输入私聊内容', // 输入框背景上的提示文字。
});
targetEntity.player.message1 = dialog;
targetEntity.player.directMessage('收到 ' + entity.player.name + ' 向你发送的私聊信息,正在为你打开查看……')//告诉接收消息的玩家收到 ' + entity.player.name + ' 向你发送的私聊信息,正在为你打开查看……
await sleep(5000);//等待5秒接收时间
targetEntity.player.directMessage('正在查收 ' + entity.player.name + " 发送的私聊信息")//告诉接收消息的玩家'正在查收 ' + entity.player.name + " 发送的私聊信息"
entity.player.directMessage('对方已收到聊天信息')//告诉发送消息的玩家:'对方已收到聊天信息'
if (dialog) {
const dialog = targetEntity.player.dialog({//新建对话框
type: Box3DialogType.TEXT,//设置对话框类型为对话框
title: "来自" + entity.player.name + "的留言", // 对话框标题。通常对应是讲话人的名字。
content: targetEntity.player.message1, // 对话框内容。也就是对话正在讲什么。
});
}
} else if (result.index == 1) {//选择【退出互动】按钮
//因为是退出,所以没有代码
}
}
)
})
//world.onTick卡顿处理
const code = [];
world.onTick((parameter) => {
code.forEach((e) => {
e(parameter);
})
})
world.onTick = (fn) => {
fn.cancel = () => {
const index = code.indexOf(fn);
if (index !== -1) {
code.splice(index, 1);
}
}
code.push(fn);
return fn;
}
console.clear()
world.say(`卡顿处理系统2.0.0版本 开始运行!`)
var kadun = 0
var kadun1 = 0;
world.onTick(({ tick, elapsedTimeMS, skip }) => {
kadun += elapsedTimeMS;
kadun1 += 1
})
async function asda() {
while (1) {
await sleep(15000)
var a = kadun1 * 喵
if (kadun < a) {
var b = a - kadun
}
else {
var b = kadun - a
}
world.say(`当前卡顿为每秒${b}Ms`)
kadun = kadun1 = 0
}
} asda();
//卡顿检测
Object.assign(Box3Entity.prototype, {
async dialog(prams) {
try {
return await this.player.dialog(prams);
} catch (e) {
world.say('⚠地图卡顿严重,可能会崩溃⚠');
}
}
});
const npc = world.querySelector('#排行榜-1');
npc.enableInteract = true;
npc.interactHint = '在线玩家金币排行榜';
npc.interactHint = '在线玩家金币排行榜';
npc.interactRadius = 3;
npc.onInteract( ({entity}) => {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: "在线玩家金币排行榜",
lookEye: entity,
lookTarget: npc,
content: dialogContent(),
});
});
// 对话框内容
function dialogContent() {
// 首先获取当前世界中的所有玩家
const allPlayerEntities = world.querySelectorAll('player');
// 然后将所有的玩家进行排序,排序的规则是按照玩家持有的金币数量降序
const sortedPlayerEntities = allPlayerEntities.sort((a, b)=> b.coin - a.coin);
// 接下来,我们将在排行榜上以: xxx 有 yyy 个金币 的格式展示,并且每一条信息换一行显示!
// 首先声明一个content字符串,一会用来保存每一个玩家的信息
let content = "";
// 在这里需要做一个循环遍历,将刚才得到的有序的玩家数组遍历一遍
for(const entity of sortedPlayerEntities ) {
// 在遍历的过程中,每一次遍历,我们拿到当前的实体(entity),
// 将实体上的玩家名字(player.name)以及玩家金币数量(player.coin)拼接成排行榜上的一行信息
// 这样就得到: xxx 有 yyy 个金币 的格式啦
// 我们在这个文字的末尾加一个\n, 这样我们就能实现换行的效果
// 紧接着,再把这行信息加上content,这样做是为了把每一个玩家的排行榜信息拼接起来,保存到content中
content = content + `❤${entity.player.name}有${entity.coin}金币
`
}
// 最后,把得到的完整的带有玩家名称和金币数量,并且会换行的排行榜数据(content)返回出去
return content
}