猫史档案馆


《天空神域》私聊系统开源

用户:阳光猫阳光猫查看:1 回复:7 评论:1 创建时间:2022-01-11T18:21:12


//玩家进入地图时,开起玩家互动
world.onPlayerJoin(async ({ entity }) => {

    entity.enableInteract = true; //互动开关
    entity.interactRadius = 3;  //互动范围
    entity.interactHint = '天空萌新' //互动显示的名称

    //互动被触发时
    entity.onInteract(async ({ entity, targetEntity }) => {
        //显示被互动的玩家信息,以及选项
        const selections = await entity.player.dialog({
            type: Box3DialogType.SELECT, //对话框类型为选择框
            content: `Ta的个人信息:\n\n昵称:${targetEntity.player.name} →[${targetEntity.interactHint}]`, //提示框内容
            options: ['私聊'], //选项
        })
        if (selections) { //确保对话框不是点击x关闭
            if (selections.value === '私聊') { //被点击的是私聊按钮
                const msgconn = await INPUTDialog(entity, `你想对Ta说什么?`, `给[${targetEntity.player.name}]发消息`)
                if (!msgconn || msgconn === null) { return };
                await simsg(entity, targetEntity, msgconn); //调用私聊函数
            }
        }
    });


    /*-------------------------------私聊函数 ---------------------------*/
    async function simsg(entity, targetEntity, conn) { //entity发起消息的玩家,targetEntity收到消息的玩家,conn内容

        if (!conn || conn === null) { return }; //消息为空直接退出函数
        targetEntity.player.directMessage(`[${entity.player.name}]对你说:(${conn})`) //在聊天区也显示私聊记录
        entity.player.directMessage(`你对[${targetEntity.player.name}]说:(${conn})`)

        const ttmsgsl = await INPUTDialog(targetEntity, `[${entity.player.name}]说:${conn}`, `回复[${entity.player.name}]的消息`)
        if (!ttmsgsl || ttmsgsl === null) {return;}
        await simsg(targetEntity, entity, ttmsgsl); //反复调用私聊函数,实现无限互动,不需要在新开

    }

});


回复

上一页1 页 / 共 1下一页
时当日色QWQ时当日色QWQ

沙发

点赞0


评论


吃饱去干伏地魔吃饱去干伏地魔

前排!

点赞0


评论


难起的名字难起的名字

额如果是老岛民的话应该知道很多人发过私聊教程()

点赞0


评论


此号已被封067此号已被封067

代码出错了()()

点赞0


评论


墨染云天墨染云天

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

点赞0


评论


AokenAoken

挖()

点赞0


评论


AokenAoken

ddd

点赞0


评论