猫史档案馆


代码求助(抢沙发的代码有没有什么需要完善的地方?注意自己的眼睛,不要被看花)

用户:一只双鱼的狐狸一只双鱼的狐狸查看:3 回复:3 评论:3 创建时间:2022-07-15T16:56:51


//时间代码
console.clear();
world.onPlayerJoin(async({entity})=>{
    if (entity.isPlayer) {
        entity.addTag('NotInGame');
        if (world.querySelectorAll('player').length >= 2) {
            for (const c of world.querySelectorAll('.NotInGame')) {
                c.player.forceRespawn();
                c.removeTag('NotInGame');
                c.player.dialog({
                    type: Box3DialogType.TEXT,
                    title: `欢迎`,
                    content: `人数已超过 2 人,可进入游戏~~`
                })
                for (let time = 10 ; time>0 ; time--){
    world.say('离开始游戏还有:'+time+'秒钟!')
    await sleep(1000)
                }
if( time = 1){
    world.say('游戏开始!')
}
            }
        } 
        else {
            entity.player.spawnPoint.set(41, 37, 44);
            entity.player.forceRespawn(); 
            entity.player.dialog({  
                type: Box3DialogType.TEXT,
                title: `欢迎`,
                content: `目前人数未达到 2 人,请等待其他玩家进入~~`
            })
        }
    }
})

//告示牌
const a = world.querySelector('#告示牌');
a.enableInteract = true;
a.interactRadius = 5;  
a.interactHint = '游玩须知'; 
a.interactColor = new Box3RGBColor(1,0,1); 
a.onInteract(async({entity}) => {
    const result1 = await entity.player.dialog({
        type: Box3DialogType.TEXT, 
        title: '告示牌',                  
        content:'抢沙发游玩规则,新手必看!!!(外加答疑解惑)'
    });
     const result2 = await entity.player.dialog({
        type: Box3DialogType.TEXT, 
        title: '告示牌',                  
        content: '1 游戏场景:游戏开始时在一块特定的地面上会多出几个沙发,你一定要站到这个上面,不然倒计时结束你就会掉下去'
    });
     const result3 = await entity.player.dialog({
        type: Box3DialogType.TEXT, 
        title: '告示牌',             
        content: '2 如果喵了会怎么样:喵了就会自动进入观战台,观战台里有一个按钮,按一下就可以回到出生点(休息大厅)'
    });
     const result4 = await entity.player.dialog({
        type: Box3DialogType.TEXT, 
        title: '告示牌',             
        content: '3 重要须知:游玩本地图不可作弊,若发现管喵滥用全职的话可以举报,举报内容发在本地图评论区,作者大大会及时查看的!(双狐:反正我除了周末以外,每天都在[滑稽])'
    });
     const result5 = await entity.player.dialog({
        type: Box3DialogType.TEXT, 
        title: '告示牌',             
        content: '4 一些小技巧:当两个人想同时跳上一个沙发的时候,一个人可以把另外一个人挤下去哦'
    });
});

const b = world.querySelector('#按钮1');
b.enableInteract = true;
b.interactRadius = 4;  
b.interactHint = '点我传送回【观战台1楼】'; 
b.onInteract(async({entity}) => {
    entity.position.set(51,19,59)
})
const c = world.querySelector('#按钮2');
c.enableInteract = true;
c.interactRadius = 4;  
c.interactHint = '点我传送回【休息大厅】'; 
c.onInteract(async({entity}) => {
    entity.position.set(51,10,106)
})

//私聊
async function chats(entity, other, text) {
    other.player.directMessage('收到一条私信')
    const has = await other.player.dialog({
        type: Box3DialogType.SELECT,
        title: "私聊",
        titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
        titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
        content: `${entity.player.name}:\n${text}`,
        options: ['回复', '取消'],
    });
    if (!has || has === null) {
        entity.player.directMessage('你被TA无视了');
        return;
    }
    if (has.value === '回复') {
        entity.player.directMessage('对方收到了你的私信')
        const returns = await other.player.dialog({
            type: Box3DialogType.INPUT,
            title: "私聊-回复",
            titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
            titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
            content: `${other.player.name},请输入回复内容`,
            confirmText: '发送',
            placeholder: '输入回复内容',
        });
        if (!returns || returns === null) {
            return;
        }
        chats(other, entity, returns)
    }
    else if (has.value === '取消') {
        entity.player.directMessage('对方收到了你的私信')
    }
}
world.onPlayerJoin(({ entity }) => {
    entity.player.interactTimes = 0;
    entity.enableInteract = true;
    entity.interactRadius = 1.5;
    entity.interactHint = '互动';
    entity.onInteract(async ({ entity, targetEntity }) => {
        targetEntity.player.directMessage('你被 ' + entity.player.name + ' 访问了')
        while (!entity.destroyed) {
            const others = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: targetEntity.player.name + ' 的信息',
                titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
                titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
                content: `私聊菜单`,
                options: ['和TA私聊'],
            })
            if (!others || others === null) {
                return;
            }
            if (others.value == '和TA私聊') {
                const chating = await entity.player.dialog({
                    type: Box3DialogType.INPUT,
                    title: "私聊",
                    titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
                    titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
                    content: `${entity.player.name},请输入私聊内容`,
                    confirmText: '发送',
                    placeholder: '输入私聊内容',
                });
                if (!chating || chating === null) {
                    return;
                }
                chats(entity, targetEntity, chating)
            }
        }
    })
})

//观战
world.onChat(({entity,message}) => {
    world.querySelectorAll('player').forEach((x) => {
        if(x.player.name == message){
            entity.player.cameraEntity = x
        }
    });
});

//管喵特权/其余功能
world.onPlayerJoin(({ entity }) => {
entity.player.onPress(async ({ button }) => {
        if (button == Box3ButtonType.ACTION1) {
    const result = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: "操作面板",
        titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
        titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
        content: `${entity.player.name},你想……?`,
        options: ['阿巴阿巴(还没想好做啥)', '管喵特权(如果你不是管喵,会遭到系统的无视)'], 
    });
    if(!result || result === null){ 
        entity.player.directMessage('');
        return; 
    }
    switch (result.index) {
        case 0:
            break;
        case 1:
        const TEST_PLAYER = ['HOR.堕天使丿银天', '聪明的重生点1号', '聰明的花捲捲1號', 'HoR.神圣天使丿星陨','-双鱼屑狐狸-']
    if (!TEST_PLAYER.includes(entity.player.name)) return;
        const result1 = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: "特权",
        titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
        titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
        content: `管喵${entity.player.name},你想用什么特权?`,
        options: ['变大', '变小','还原大小','开启飞行','关闭飞行','开启隐身','关闭隐身','增加速度','还原速度','增加跳跃','还原跳跃','开启穿墙','关闭穿墙','显示名字','隐藏名字','清屏'], 
    });
    if(!result1 || result1 === null){ 
        entity.player.directMessage('');
        return; 
    }
    switch (result1.index) {
        case 0:
         entity.player.scale = 6;
         entity.player.walkAcceleration = 1;
         entity.player.runSpeed = 0.25;
            break;
        case 1:
         entity.player.scale =0.5;
         entity.player.runSpeed = 1.6;
          entity.player.runAcceleration = 1.4 ;
            break;
        case 2: 
        entity.player.scale = 1;
        entity.player.walkSpeed = 0.5;
        entity.player.walkAcceleration = 0.68;
        entity.player.runSpeed = 0.4;
        entity.player.runAcceleration = 0.35;
            break;
        case 3:
         entity.player.canFly=true;
            break;
        case 4:
        entity.player.canFly=false;
            break;
        case 5:
         for (const bodyPart in entity.player.skinInvisible) {entity.player.skinInvisible[bodyPart] = true};
            break;
        case 6:
         for (const bodyPart in entity.player.skinInvisible) {entity.player.skinInvisible[bodyPart] = false};
            break;
        case 7:
         entity.player.walkSpeed=1;
         entity.player.runSpeed = 1.6;
            break;
        case 8:
         entity.player.walkSpeed=0.5;
         entity.player.runSpeed = 0.4;
            break;
        case 9: 
        entity.player.jumpPower = 0.96 * 2;
            break;
        case 10:
         entity.player.jumpPower = 0.96;
            break;
        case 11:
         entity.player.spectator = true;
            break;
        case 12: 
        entity.player.spectator = false;
            break;
        case 13: 
        entity.player.showName=true;
            break;
        case 14:
         entity.player.showName=false;
            break;
        case 15: 
        for (let x = 0; x < 100; x++) world.say('') ;
            break; 
            break;
            default:
    }
            break;
       
        }
        }
})
})


回复

上一页1 页 / 共 1下一页
egg鸡蛋蛋egg鸡蛋蛋

沙发

点赞0


评论


卑微OIer卑微OIer

写的不好

点赞0


评论


FML饭米粒FML饭米粒

缩进问题很大

还有就是不要用abcd之类的变量名

私聊可以用递归实现,不用这么复杂

交互最好用world.onInteract实现,每进一个玩家另来一个监听。。。

dialog为什么不封装成函数

entity.player.directMessage('对方收到了你的私信' )

这段出现了两次,完全可以在另一处增加这段并把这两处删掉,效果不变

还有好多问题不想再说了

反正我不会告诉你修改完的全部/代码片段,也别找我了

拒绝白嫖,从我做起

点赞0


评论