猫史档案馆


【新编辑器小教程】3分钟做好远征商店代码

用户:wxbdztzswxbdztzs查看:0 回复:2 评论:0 创建时间:2024-01-27T12:11:46


第一步:添加2个模型分别命名为`商店'/物流商人 第二步:完善代码 我们先做`商店`的 global.scc=world.querySelector('#商店'); scc.enableInteract=true;//允许进行互动 scc.interactRadius=5;//实体的互动范围 scc.interactHint=scc.id;//互动提示框显示实体的名称 scc.interactColor=newGameRGBColor(1,1,1);//互动提示的文字颜色 scc.onInteract(async({entity})=>{ constarms=['货物']; constmoney=[114511] consts=awaitentity.player.dialog({ type:GameDialogType.SELECT, title:scc.id, content:`内容`, options:['图纸',`武器`], }) if(s.index===0) { consts=awaitentity.player.dialog({ type:GameDialogType.SELECT, content:`......`, options:arms, }) if(s){ constarm=arms[s.index] constext=money[s.index] if(entity.jp>=ext){ entity.jp-=ext entity.itemList.push(armq) entity.player.directMessage(`你已成功购买${arm}`) }elseif(entity.jp<ext){ entity.player.directMessage(`你的钱不够!想要${s.value},共需${ext}钱,你只有${entity.jp}钱`) } } } }) 其中 entity.jp//钱 entity.itemlist//背包 接下来做`物流商人` 这里先定义 entity.mc//木材 //木材补给商品编号为0000001 显示商店: global.scc=world.querySelector('#物流商人'); pq.enableInteract=true;//允许进行互动 pq.interactRadius=5;//实体的互动范围 pq.interactHint='物流商人';//互动提示框显示实体的名称 pq.interactColor=newGameRGBColor(1,1,1);//互动提示的文字颜色 pq.onInteract(async({entity})=>{ entity.player.openMarketplace([0000001]) } 判断玩家的选择: world.onPlayerPurchaseSuccess(async({userId,productId})=>{ //假如商城后台玩家选择id为`0000001`的道具 if(productId===0000001){ //由于可能存在多服的情况,每个服都会收到此购买成功的回调,因此需要判断当前服务器有此玩家 constentity=world.querySelectorAll('player').filter(e=>e.player.userId===userId)[0]; if(entity){ entity.player.dialog({ type:"text", title:"购买成功", content:`你获得:\n300*木材` }) entity.mc=entity.mc+300 entity.player.directMessage("你已购买木材补给~奖励已发放~") world.say(`${entity.player.name}购买了木材补给!`) awaitsavePlayer(entity) } } }) 到此,远征商店代码‘基本’完成了 最后,别忘了 https://dao3.fun/profile/13458695  


回复

上一页1 页 / 共 1下一页
wxbdztzswxbdztzs

center_image

点赞0


评论


羞涩的萌萌熊SeId羞涩的萌萌熊SeId

合作吗?

我有一个项目要代码

 

点赞0


评论