猫史档案馆


【Pro编辑器】可以在GUI窗口显示玩家说话内容的代码!(修订版)

用户:追梦ez追梦ez查看:7 回复:3 评论:7 创建时间:2023-09-10T12:55:16


gui.GREY = '#aaa';
gui.YELLOW = '#ff5';
gui.RED = '#f55';
gui.GREEN = '#5f5';
gui.BLUE = '#55f';
gui.Purple = '#a0a';

yadmin=[]//文字为黄色的特权列表(填名字)
radmin=[]//文字为红色的特权列表(填名字)
gadmin=[]//文字为绿色的特权列表(填名字)
badmin=[]//文字为蓝色的特权列表(填名字)
padmin=['Dream不想变屑awa']//文字为紫色的特权列表(示例)

world.onPlayerJoin(async ({ entity }) => {
    entity.guicolor=gui.GREY
    if(yadmin.indexOf(entity.player.name) > -1){
        entity.guicolor=gui.YELLOW
    }
    if(radmin.indexOf(entity.player.name) > -1){
        entity.guicolor=gui.RED
    }
    if(gadmin.indexOf(entity.player.name) > -1){
        entity.guicolor=gui.GREEN
    }
    if(badmin.indexOf(entity.player.name) > -1){
        entity.guicolor=gui.BLUE
    }
    if(padmin.indexOf(entity.player.name) > -1){
        entity.guicolor=gui.Purple
    }
    await sleep(3000);
    await gui.init(entity, {
        '': {
            display: true,
            data: `
                <dialog percentWidth="100" percentHeight="100" id="fullscreen">
                </dialog>
            `
        }
    });
    [entity.player.screenWidth, entity.player.screenHeight] = await Promise.all([gui.getAttribute(entity, "#fullscreen", "width"), gui.getAttribute(entity, "#fullscreen", "height")]);
    await gui.remove(entity, "#fullscreen");
    entity.player.isComputer = entity.player.screenWidth > entity.player.screenHeight;
    if (entity.player.isComputer) {
        entity.player.guiMessageCnt = 0;
        entity.player.guiMessages = [];
        entity.player.guiMessaging = false;
        await gui.init(entity, {
            'title': {
                display: true,
                data: `
                    <label text="" left="100" top="${entity.player.screenHeight / 2 - 72}" percentWidth="0" height="72" color="#0000" fontSize="72" id="title"></label>
                `
            },
            'subtitle': {
                display: true,
                data: `
                    <label text="" top="${entity.player.screenHeight / 2 + 36}" percentWidth="0" height="24" color="#0000" fontSize="36" id="subtitle"></label>
                `
            },
            'chat': {
                display: true,
                data: `
                    <group bottom="160" left="9" width="${entity.player.screenWidth * 0.675}" height="0" backgroundColor="#00000080" borderColor="#0000" id="chat"></group>
                `
            }
        });
        world.onChat(({ message, entity: entity1 }) => {
            if ((message.includes('{')) && (message.includes('}')) && (message.includes(':')) && (message.includes(','))) {
                gui.message(entity, entity1.player.name + '发送了个表情包,打开对话框查看', entity1)
            }
            else {
                gui.message(entity, entity1.player.name + ':' + message, entity1);
            }
        })
    }
});

gui.message = async (entity, text,chatentity) => {
    try{
        if (!entity.player.isComputer) {
            entity.player.directMessage(text);
            return;
        }
        while (!entity.player.guiMessages) {
            await sleep(32);
        }
        if (entity.player.guiMessages.length > 30) {
            return;
        }
        while (entity.player.guiMessaging) {
            await sleep(32);
        }
        setTimeout(async () => {
            if (entity.destroyed) {
                return;
            }
            entity.player.guiMessages.shift();
            gui.remove(entity, '#' + _id);
            gui.remove(entity, '#' + id);
            gui.setAttribute(entity, '#chat', 'height', Math.min(entity.player.guiMessages.length, 10) * 36);
        }, 10000);
        entity.player.guiMessaging = true;
        entity.player.guiMessageCnt++;
        entity.player.guiMessages.push({
            id: entity.player.guiMessageCnt,
            bottom: 124
        });
        let id = 'msg' + entity.player.guiMessageCnt;
        let _id = '_msg' + entity.player.guiMessageCnt;
        let data = {};
        data[_id] = {
            display: true,
            data: `
                <label text="${text}" bottom="158" left="11" width="${entity.player.screenWidth * 0.675}" height="36" color="#2a2a2a" fontSize="32" id="${_id}"></label>
            `
        };
        data[id] = {
            display: true,
            data: `
                <label text="${text}" bottom="160" left="9" width="${entity.player.screenWidth * 0.675}" height="36" color="${chatentity.guicolor}" fontSize="32" id="${id}"></label>
            `
        };
        gui.setAttribute(entity, '#chat', 'height', Math.min(entity.player.guiMessages.length, 10) * 36);
        gui.init(entity, data);
        entity.player.guiMessages.forEach(async msg => {
            msg.bottom += 36;
            if (msg.bottom >= 520) {
                gui.remove(entity, '#msg' + msg.id);
                gui.remove(entity, '#_msg' + msg.id);
                return;
            }
            gui.setAttribute(entity, '#msg' + msg.id, 'bottom', msg.bottom);
            gui.setAttribute(entity, '#_msg' + msg.id, 'bottom', msg.bottom - 2);
        });
        entity.player.guiMessaging = false;
    }
    catch(e){
        return
    }
};


回复

上一页1 页 / 共 1下一页
追梦ez追梦ez

旧版:https://shequ.codemao.cn/community/563976

点赞0


评论


Star_Ink_sansStar_Ink_sans

本来就看得到啊()不是发了消息右下角能显示一个小窗的吗()

点赞0


评论


SCS_user_i1eril0dUySCS_user_i1eril0dUy

收藏

点赞0


评论