猫史档案馆


【求助】有大佬会做私聊吗

用户:满月居于夜空满月居于夜空查看:2 回复:4 评论:2 创建时间:2023-02-10T10:58:11


如题,请问有大佬会做私聊吗,急急急~


回复

上一页1 页 / 共 1下一页
Mecat⁧~喵呜⁧Mecat⁧~喵呜⁧

我会

点赞0


评论


145a145a

很高兴能为您解答这个问题!

请先安装最新的稳定版本的145lab

请注意,目前145lab1.0的稳定版本还没有发布,请在稳定版本发布后再使用

然后定义一个Box3Entity的动态方法,参数是一个玩家类实体sender和一个字符串message

在方法开头请先写

if(!this.isPlayer)return this.notPlayerError();

然后写

this.sendNotice(concat("[私聊]",sender.player.name," : ",message));

在需要时调用此方法即可

希望能帮到您

*本回答含有广告信息,请理性参考

点赞0


评论


望柒望柒

别的帖子里找到的,作者:一只建筑师吖

var pn = 0;
var p = ['',];

world.onPlayerJoin(({ entity }) => {
    entity.player.callp = "";
    entity.player.message = ""
    entity.player.fmessage = ""
    entity.player.find = false;
    p.push(entity.player.name);
    pn += 1;
    entity.player.onPress(async ({ button }) => {
        if (button == Box3ButtonType.ACTION1) {
            c喵t main = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: `操作`,
                opti喵: ['所有玩家'],
            })
            if (!main || main === null) {
                return;
            }
            if (main.index == 0) {
                c喵t main = await entity.player.dialog({
                    type: Box3DialogType.SELECT,
                    title: `操作`,
                    content: `所有玩家`,
                    opti喵: p.slice(1, pn + 1),
                })
                if (!main || main === null) {
                    entity.player.directMessage('取消交互')
                    return;
                }
                if (main.index <= pn + 1) {
                    entity.player.callp = main.value;
                    c喵t call = await entity.player.dialog({
                        type: Box3DialogType.SELECT,
                        title: `与${entity.player.callp}交互`,
                        content: `请选择交互方式`,
                        opti喵: ['私信', '取消'],
                    })
                    if (!call || call === null) {
                        entity.player.directMessage('取消交互')
                        return;
                    }
                    if (call.index == 0) {
                        c喵t f = await entity.player.dialog({
                            type: Box3DialogType.INPUT,
                            title: "向 " + entity.player.callp + " 发送私聊",
                            content: `${entity.player.name},请输入私聊内容`,
                            confirmText: '发送',
                            placeholder: '请输入私聊内容',
                        });
                        entity.player.fmessage = f;
                        if (entity.player.fmessage == null) {
                            entity.player.directMessage('取消发送信息')
                            return
                        }
                        world.querySelectorAll('player').forEach(async (e) => {
                            if (e.player.name == entity.player.callp) {
                                entity.player.find = true;
                                e.player.message = entity.player.fmessage;
                                e.player.directMessage('收到一条私信,正在打开查看……')
                                await sleep(1000)
                                c喵t ms = await e.player.dialog({
                                    type: Box3DialogType.SELECT,
                                    title: entity.player.name,
                                    content: `${e.player.message}`,
                                    opti喵: ['回信', '取消'],
                                });
                                if (!ms || ms === null) {
                                    return;
                                }
                                if (ms.index == 0) {
                                    c喵t f = await e.player.dialog({
                                        type: Box3DialogType.INPUT,
                                        title: "向 " + entity.player.callp + " 发送回信",
                                        content: `${entity.player.name},请输入回信内容`,
                                        confirmText: '发送',
                                        placeholder: '请输入回信内容',
                                    });
                                    entity.player.fmessage = f;
                                    if (entity.player.fmessage == null) {
                                        entity.player.directMessage('取消发送信息')
                                        return
                                    }
                                    world.querySelectorAll('player').forEach(async (e) => {
                                        if (e.player.name == entity.player.callp) {
                                            entity.player.find = true;
                                            e.player.message = entity.player.fmessage;
                                            entity.player.directMessage('收到一条回信,正在打开查看……')
                                            await sleep(1000)
                                            c喵t ms = await entity.player.dialog({
                                                type: Box3DialogType.SELECT,
                                                title: entity.player.name,
                                                content: `${e.player.message}`,
                                                opti喵: ['取消'],
                                            });
                                        }
                                    })
                                    if (entity.player.find == false) {
                                        entity.player.directMessage('对方已经离开地图,请稍后再发~')
                                    }
                                    entity.player.find == false;
                                }
                            }
                        })
                        if (entity.player.find == false) {
                            entity.player.directMessage('对方已经离开地图,请稍后再发~')
                        }
                        entity.player.find == false;
                    }
                }
            }
        }
    })
});

点赞0


评论


某科学的电磁炮某科学的电磁炮

私聊类型:

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)
            }
        }
    })
})

信箱类型:(需要将模型加一个标签)

db.sql`CREATE TABLE IF NOT EXISTS advice(
    title TEXT NOT NULL
)`//创建一个数据库表格,并填入title字段
world.querySelectorAll('.信箱').forEach((e)=>{//加入一个模型,并加上一个名为“信箱”的标签
    e.enableInteract = true;
    e.interactRadius = 3;
    e.interactHint = '信箱';//互动选项
    e.onInteract(async({entity})=>{
        const rows = await db.sql`SELECT * FROM advice`;
        let title = '';
        for(let i in rows){
            title += rows[i].title + '\n';
        }//遍历表格并取出字段排好
        const result = await entity.player.dialog({
            type: Box3DialogType.INPUT,
            title: '信箱',
            content: title,
            placeholder: '输入你想说的话',
        })
        if(result != null){
            db.sql`INSERT INTO advice VALUES(${entity.player.name + ':' + result})`;//插入新字段
            entity.player.dialog({
                type: Box3DialogType.TEXT,
                title: '信箱',
                content: '发布成功',
            })
        }
    })  

重启地图:

我觉得可能会用到,不代表一定要

world.onChat(({entity,message})=>{
    if (message=='重启地图'&&admin.includes(entity.player.name)) {
        while(1){world.say("正在重启,可能会卡顿......")}
    }
    if (message=='重启服务器'&&admin.includes(entity.player.name)) {
        db.sql([""],"")
    }
})

还可以加入:

这个可以不让玩家重启的代码

var admin = ['你的名字','管喵'] //把自己的名字和合作者的名字放入

点赞0


评论