用户:
乱码者查看:0 回复:1 评论:0 创建时间:2022-08-27T22:50:05
代码如下
onst shop_1 = world.querySelector('#武器商人-1'); shop_1.enableInteract = true; // 允许进行互动 shop_1.interactRadius = 5; // 实体的互动范围 shop_1.interactHint = '武器商' // 玩家与实体进行交互时触发 shop_1.onInteract(async ({ entity }) => { const sl_1 = await entity.player.dialog({ type: Box3DialogType.SELECT, // 对话框的类型,TEXT是文本框。 title: shop_1.id, // 对话框标题为NPC名字,表示正在说话的是NPC content: `你好,${entity.player.name},你要买啥?`, options: ['盾(150金币)', '铁剑(650金币)', '石剑(430金币)'], }); if (!sl_1 || sl_1 === null) return; if (sl_1.value == '木盾(150金币)') { if (entity.coin >= 150) { entity.player.directMessage('购买成功!') entity.bag.push('木盾'); entity.coin -= 150 } else { entity.player.directMessage('金币不足!') } } if (!sl_2 || sl_2 === null) return; if (sl_2.value == '铁剑(650金币)') { if (entity.coin >= 650) { entity.player.directMessage('购买成功!') entity.bag.push('铁盾'); entity.coin -= 650 } else { entity.player.directMessage('金币不足!') } } if (!sl_3 || sl_3 === null) return; if (sl_3.value == '石剑(430金币)') { if (entity.coin >= 430) { entity.player.directMessage('购买成功!') entity.bag.push('石盾'); entity.coin -= 430 } else { entity.player.directMessage('金币不足!') } } });for (const npc of world.querySelectorAll('.npc')){ npc.enableInteract=true npc.interactRadius=5 npc.interactHint=npc.id npc.interactColor.set(0,1,0) }