用户:
金色传说1查看:3 回复:2 评论:3 创建时间:2021-05-29T17:06:31
见上题,互动怎么写。。
https://shequ.codemao.cn/community/373542
world.onPlayerJoin(({ entity }) => {
entity.player.message1 = "";
entity.player.interactTimes = 0;
entity.enableInteract = true;
entity.interactRadius = 3;
entity.interactHint = "与 " + entity.player.name + " 互动";
entity.onInteract(async ({ entity, targetEntity }) => {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: targetEntity.player.name,
content: `和 ${targetEntity.player.name} 互动?`,
options: ['和TA私聊','查看TA的信息'], // 将提供玩家选择的选项放入数组里。
})
// 如果玩家点击了屏幕其他区域,取消了对话框。
if (!result || result === null) {
entity.player.directMessage('取消互动');
return;
}
if (result.index == 0) {
const dialog = await entity.player.dialog({
type: Box3DialogType.INPUT,
title: "向 "+targetEntity.player.name+" 发送私聊",
content: `${entity.player.name},请输入私聊内容`,
confirmText: '发送', // 确定按钮上面的文字。按下确定按钮后,提交回答。
placeholder: '请输入私聊内容', // 输入框背景上的提示文字。
});
targetEntity.player.message1 = dialog;
targetEntity.player.directMessage('收到 '+entity.player.name+' 向你发送的私聊信息,正在打开查看……')
await sleep(2000);
targetEntity.player.directMessage('正在查收 '+entity.player.name+" 发送的私聊信息")
entity.player.directMessage('对方已收到聊天信息')
if (dialog) {
const dialog = targetEntity.player.dialog({
type: Box3DialogType.TEXT,
title: entity.player.name, // 对话框标题。通常对应是讲话人的名字。
content: targetEntity.player.message1, // 对话框内容。也就是对话正在讲什么。
});
}
}
})
})点赞0
评论