用户:
Aoken查看:7 回复:9 评论:7 创建时间:2023-08-24T19:30:07
console.clear()
function Input_dialog(entity,title,text,input_text){
return entity.player.dialog({
type: 'input',// 输入框类型
title: title,// 标题
titleTextColor: new GameRGBAColor(0, 0, 0, 1),
titleBackgroundColor: new GameRGBAColor(0.968, 0.702, 0.392, 1),
content: text, // 文本
placeholder: input_text// 输入框背景上的提示文字。
})
}
async function Target_msg(entity,targetEntity,text){/*entity发起消息的玩家,targetEntity收到消息的玩家,text内容*/
if(!text||text===0)return;//消息为空直接退出函数
const tar_msg=await Input_dialog(
entity,
targetEntity.player.name,
`[${targetEntity.player.name}]说:${text}`,
`请输入你要对[${targetEntity.player.name}]说的话`
);if(!tar_msg||tar_msg===0)return;//消息为空直接退出函数
await Target_msg(targetEntity,entity,tar_msg)//反复调用私聊函数,实现无限互动,不需要在新开
}
world.onPlayerJoin(({entity}) =>{
entity.enableInteract = true; //互动开关
entity.interactRadius = 3; //互动范围
entity.onInteract(async({entity,targetEntity}) =>{
const other = await entity.player.dialog({
type: 'select', //对话框类型为选择框
content: `Ta的个人信息:\n\n昵称:${targetEntity.player.name}`,//提示框内容
options: ['私聊'], //选项
})
if (!other || other === 0)return; //确保对话框不是点击x关闭
else if (other.value === '私聊') { //被点击的是私聊按钮
const msg=await Input_dialog(
entity,
'私聊',
`你要对TA说什么?`,
`请输入你要对[${targetEntity.player.name}]说的话`
)
if(!msg||msg===0)return;//消息为空直接退出函数
await Target_msg(targetEntity,entity,msg)
}
})
})
本代码基础来自 阳光猫的:https://shequ.codemao.cn/community/419980
不喜勿喷