用户:
坦率的血翼蝠5801查看:1 回复:5 评论:1 创建时间:2022-04-18T19:18:05
本期教程难度★★☆☆☆ 直接上代码 world.onPlayerJoin(({entity})=>{//当玩家进入地图 entity.coin=5//初始化玩家金币为5 }) constshop=world.querySelector('#服务员') shop.enableInteract=true//让服务员可以互动 shop.interactRadius=5//设置互动范围 shop.interactHint=`商人`//当玩家靠近时出现的提示语 shop.onInteract(async({entity})=>{//当玩家与服务员互动 constbuy=awaitentity.player.dialog({//弹出对话框 type:Box3DialogType.SELECT,//选项框类型为单选 title:`商店`,//标题 content:`有什么想买的吗?您有${entity.coin}金币`,//提示玩家目前的金币数量 options:['有BUG的代码2金币/段','喵5金币/次'],//给出商品列表 }) if(!buy||buy==null)return;//如果玩家按下了×,跳过后面的代码,避免报错 switch(buy.index){ case0: if(entity.coin<2){ entity.player.directMessage(`金币不足!`)//提示玩家金币不够 }else{ entity.coin-=2//减去玩家金币 entity.bug=1//给玩家商品(下同) entity.player.directMessage(`购买成功!`)//提示玩家(下同) } break; case1: if(entity.coin<5){ entity.player.directMessage(`金币不足!`) }else{ entity.coin-=5 entity.enableDamage=true entity.hurt(10000) entity.player.directMessage(`购买成功!`) } break; default: //注意:在使用switch语句时,别忘记了break和default } }) 还是最后献上体验链接!https://box3.codemao.cn/e/8d3d21be066710bc4ae6
坦率的血翼蝠5801排版被吃了!
world.onPlayerJoin(({entity}) => {// 当玩家进入地图
entity.coin = 5 // 初始化玩家金币为5
})
const shop = world.querySelector('#服务员')
shop.enableInteract = true // 让服务员可以互动
shop.interactRadius = 5 // 设置互动范围
shop.interactHint = `商人` // 当玩家靠近时出现的提示语
shop.onInteract(async({entity}) => { // 当玩家与服务员互动
const buy = await entity.player.dialog({ // 弹出对话框
type: Box3DialogType.SELECT, // 选项框类型为单选
title: `商店`, // 标题
content: `有什么想买的吗?您有${entity.coin}金币`, // 提示玩家目前的金币数量
options: ['有BUG的代码 2金币/段', '喵 5金币/次'], // 给出商品列表
})
if (!buy || buy == null) return; // 如果玩家按下了×,跳过后面的代码,避免报错
switch(buy.index){
case 0:
if (entity.coin < 2){
entity.player.directMessage(`金币不足!`) // 提示玩家金币不够
} else {
entity.coin -= 2 // 减去玩家金币
entity.bug = 1 // 给玩家商品(下同)
entity.player.directMessage(`购买成功!`) // 提示玩家(下同)
}
break;
case 1:
if (entity.coin < 5){
entity.player.directMessage(`金币不足!`)
} else {
entity.coin -= 5
entity.enableDamage = true
entity.hurt(10000)
entity.player.directMessage(`购买成功!`)
}
break;
default:
// 注意:在使用switch语句时,别忘记了break和default
}
})点赞0
评论
Robot一只屑代码师world.onPlayerJoin(({entity}) => {// 当玩家进入地图
entity.coin = 5 // 初始化玩家金币为5
})
const shop = world.querySelector('#服务员')
shop.enableInteract = true // 让服务员可以互动
shop.interactRadius = 5 // 设置互动范围
shop.interactHint = `商人` // 当玩家靠近时出现的提示语
shop.onInteract(async({entity}) => { // 当玩家与服务员互动
const buy = await entity.player.dialog({ // 弹出对话框
type: Box3DialogType.SELECT, // 选项框类型为单选
title: `商店`, // 标题
content: `有什么想买的吗?您有${entity.coin}金币`, // 提示玩家目前的金币数量
options: ['有BUG的代码 2金币/段', '喵 5金币/次'], // 给出商品列表
})
if (!buy || buy == null) return; // 如果玩家按下了×,跳过后面的代码,避免报错
switch(buy.index){
case 0:
if (entity.coin < 2){
entity.player.directMessage(`金币不足!`) // 提示玩家金币不够
} else {
entity.coin -= 2 // 减去玩家金币
entity.bug = 1 // 给玩家商品(下同)
entity.player.directMessage(`购买成功!`) // 提示玩家(下同)
}
break;
case 1:
if (entity.coin < 5){
entity.player.directMessage(`金币不足!`)
} else {
entity.coin -= 5
entity.enableDamage = true
entity.hurt(10000)
entity.player.directMessage(`购买成功!`)
}
break;
default:
// 注意:在使用switch语句时,别忘记了break和default
}
})点赞0
评论