用户:
阳光猫查看: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); //反复调用私聊函数,实现无限互动,不需要在新开
}
});
墨染云天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
评论