用户:
阳光猫查看:0 回复:2 评论:0 创建时间:2022-01-18T11:42:52
//1.首先把需要加房卡系统的模型加上标签 房门
//2.加入以下代码,就能获取你背包中是否有房卡
//3.建立:entity.player.bitemList 为玩家背包列表
for (const e of world.querySelectorAll('.房门')) {//遍历所有实体
e.enableInteract = true; // 允许进行互动
e.interactRadius = 3; // 实体的互动范围
e.interactHint = e.id.match(/\d+/g) + "号房间"; // 互动提示框显示实体的名称
e.interactColor = new Box3RGBColor(1, 0, 1); // 互动提示的文字颜色
// 玩家与实体进行交互时触发
e.onInteract(async ({ entity }) => {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT, // 对话框的类型,TEXT是文本框。
title: '开门', // 对话框标题为NPC名字,表示正在说话的是NP
content: `提示:拥有[${e.id.match(/\d+/g)}]号房间房卡才能进入!`,
options: ['开门'],
});
if (!result || result === null || result.index === 1) {
//entity.player.directMessage('你似乎无视了提示。');
return;
}
let fk = e.id.match(/\d+/g) + '号房卡'
if (result.value === '开门') { /*持有房卡 */
if (entity.player.bitemList.includes(fk)) {
entity.player.directMessage(`开门成功!`)
//e.meshInvisible=true;
e.collides = false
e.meshInvisible = true
await sleep(2000)
e.collides = true
e.meshInvisible = false
}
else {
entity.player.directMessage(`你背包里面没有此房卡!`)
}
}
})
}