请选择 进入手机版 | 继续访问电脑版
查看: 9285|回复: 29

[命令方块] 【命令方块实现箱子商店】卖卖卖!在原版服中拥有你自己的商店~创建与设置部分已修复

[复制链接]

65

主题

791

帖子

370

积分

Lv.5 农牧专家

UID
14859
小麦
92
金锭
425
下界之星
0
发表于 2017-11-18 22:41:15 | 显示全部楼层 |阅读模式
本帖最后由 MCSugar_cane 于 2017-12-1 22:47 编辑

说在前面:代码在1.11.2版本下编写
箱子商店
整体思路:
  要实现这个系统难点就在于如何区分不同玩家所创建的不同商店,将创建者与他所创建的商店所匹配。在这里,我利用了流动ID分配,在创建时为每个商店分配不同ID,并且时这个ID值=创建者ID值。这样一来,只需要用玩家ID值-商店ID值的结果来区分其是否为该商店创建者。本帖只介绍箱子商店的创建与设置。详情见链接。(此帖未经允许请勿转载)

  此系统OOC链接:  
戳我前去

  实现效果: shop-base.gif

关于修复:
修复了补货时物品会重叠的bug。(利用给物品新的nbt让其与其它物品产生差别)

代码:
  创建变量:
  1. /scoreboard objectives add createitem dummy
  2. /scoreboard objectives add createfacing dummy
  3. /scoreboard objectives add whocreate stat.useItem.minecraft.spawn_egg
  4. /scoreboard objectives add shopSetting dummy
  5. /scoreboard objectives add shopID dummy
  6. /scoreboard objectives add isale trigger
  7. /scoreboard objectives add getsalep dummy
  8. /scoreboard objectives add getshopid dummy
  9. /scoreboard objectives add items dummy
复制代码

  生成商店蛋:[高频循环]
  1. /scoreboard players set @e[type=Item] createitem 1 {Item:{id:"minecraft:chest",Count:1b,Damage:0s},OnGround:1b}
  2. /scoreboard players set @e[type=Item] createitem 2 {Item:{id:"minecraft:sign",Count:1b,Damage:0s},OnGround:1b}

  3. /execute @e[type=Item,score_createitem_min=1,score_createitem=1] ~ ~ ~ execute @e[score_createitem_min=2,score_createitem=2,r=1,c=1] ~ ~ ~ summon Item ~ ~0.5 ~ {Item:{id:"minecraft:spawn_egg",Count:1b,tag:{EntityTag:{id:"minecraft:bat",CustomName:"CreateShop",NoAI:1,Silent:1b,ActiveEffects:[{Id:14,Duration:9999999,Amplifier:50,Ambient:1}]},HideFlags:127,ench:[{id:34,lvl:10}],display:{Name:"创建商店",Lore:["www.Ganxiaozhe.com"]}}},Motion:[0.0,0.4,0.0]}
  4. /execute @e[type=Item,score_createitem_min=1,score_createitem=1] ~ ~ ~ execute @e[score_createitem_min=2,score_createitem=2,r=1,c=1] ~ ~ ~ playsound minecraft:entity.armorstand.break voice @a[r=8]
  5. /execute @e[type=Item,score_createitem_min=1,score_createitem=1] ~ ~ ~ execute @e[score_createitem_min=2,score_createitem=2,r=1,c=1] ~ ~ ~ particle totem ~ ~1 ~ 0.2 0.6 0.2 0.2 80
  6. /execute @e[type=Item,score_createitem_min=1,score_createitem=1] ~ ~ ~ execute @e[score_createitem_min=2,score_createitem=2,r=1,c=1] ~ ~ ~ kill @e[type=Item,score_createitem_min=1,r=1]
复制代码

  检测玩家朝向以放置正确位置商店:[高频循环]
  1. /scoreboard players set @a[score_whocreate_min=1,rym=-135,ry=-45] createfacing 1
  2. /scoreboard players set @a[score_whocreate_min=1,rym=135,ry=-135] createfacing 2
  3. /scoreboard players set @a[score_whocreate_min=1,rym=46,ry=135] createfacing 3
  4. /scoreboard players set @a[score_whocreate_min=1,rym=-45,ry=45] createfacing 4
复制代码

  放置商店:[高频循环]
  1. /execute @a[score_whocreate_min=1,score_createfacing_min=1,score_createfacing=1] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~ ~ ~ chest 4 masked {Lock:"Locked by ganxiaozhe"}
  2. /execute @a[score_whocreate_min=1,score_createfacing_min=1,score_createfacing=1] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~-1 ~ ~ wall_sign 4

  3. /execute @a[score_whocreate_min=1,score_createfacing_min=2,score_createfacing=2] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~ ~ ~ chest 3 masked {Lock:"Locked by ganxiaozhe"}
  4. /execute @a[score_whocreate_min=1,score_createfacing_min=2,score_createfacing=2] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~ ~ ~1 wall_sign 3

  5. /execute @a[score_whocreate_min=1,score_createfacing_min=3,score_createfacing=3] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~ ~ ~ chest 5 masked {Lock:"Locked by ganxiaozhe"}
  6. /execute @a[score_whocreate_min=1,score_createfacing_min=3,score_createfacing=3] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~1 ~ ~ wall_sign 5

  7. /execute @a[score_whocreate_min=1,score_createfacing_min=4,score_createfacing=4] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~ ~ ~ chest 1 masked {Lock:"Locked by ganxiaozhe"}
  8. /execute @a[score_whocreate_min=1,score_createfacing_min=4,score_createfacing=4] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ setblock ~ ~ ~-1 wall_sign 1

  9. /execute @a[score_whocreate_min=1] ~ ~ ~ execute @e[name=CreateShop,c=1] ~ ~ ~ /summon Villager ~ ~ ~ {CustomName:"cShop",NoAI:1b,Silent:1b,Offers:{Recipes:[]},ActiveEffects:[{Id:14,Duration:9999999,Amplifier:50,Ambient:1}]}
  10. /execute @a[score_whocreate_min=1] ~ ~ ~ scoreboard players set @e[name=cShop,c=1] shopSetting 1
  11. /kill @e[type=bat,name=CreateShop]
  12. /scoreboard players tag @a[score_whocreate_min=1] add wcreate
  13. /scoreboard players reset @a[score_whocreate_min=1] whocreate
复制代码

  商店设置部分:[高频循环]
  1. /execute @e[name=cShop,score_shopSetting_min=1,score_shopSetting=1] ~ ~ ~ tp @p[tag=wcreate] @e[name=cShop,c=1]
  2. /execute @e[name=cShop,score_shopSetting_min=1,score_shopSetting=1] ~ ~ ~ tellraw @p[tag=wcreate] [{"text":"[甘小蔗] ","color":"dark_green","bold":"true"},{"selector":"@p[tag=wcreate]","color":"gold","bold":"true"},{"text":" 请丢弃(一个)你要出售的物品以进行设置(在过程中请勿移动)","color":"green","bold":true}]
  3. /scoreboard players set @e[name=cShop,score_shopSetting_min=1,score_shopSetting=1] shopSetting 2

  4. /execute @e[name=cShop,score_shopSetting_min=2,score_shopSetting=2] ~ ~ ~ scoreboard players set @e[type=Item,r=1] createitem -1 {Item:{id:"minecraft:iron_ingot",Count:1b,Damage:0s}}
  5. /execute @e[name=cShop,score_shopSetting_min=2,score_shopSetting=2] ~ ~ ~ scoreboard players set @e[type=Item,r=1] createitem -2 {Item:{id:"minecraft:reeds",Count:1b,Damage:0s}}

  6. /execute @e[type=Item,score_createitem_min=-1,score_createitem=-1] ~ ~ ~ scoreboard players tag @e[name=cShop,c=1] add s_iron_ingot
  7. /execute @e[type=Item,score_createitem_min=-2,score_createitem=-2] ~ ~ ~ scoreboard players tag @e[name=cShop,c=1] add s_reeds

  8. /scoreboard players tag @e[type=Item,score_createitem=-1,tag=!ishow] add ishow

  9. /execute @e[type=cShop,score_shopSetting_min=2,score_shopSetting=2] ~ ~ ~ teleport @e[type=Item,score_createitem=-1,c=1] ~ ~0.5 ~
  10. /entitydata @e[type=Item,score_createitem=-1] {PickupDelay:10000,Age:-23333,NoGravity:1,Item:{tag:{Ganxiaozhe:1}}}
  11. /execute @e[name=cShop,score_shopSetting_min=2,score_shopSetting=2] ~ ~ ~ scoreboard players set @p[tag=wcreate] isale -1
  12. /execute @e[type=Item,score_createitem=-1] ~ ~ ~ scoreboard players set @e[name=cShop,score_shopSetting_min=2,score_shopSetting=2,r=1] shopSetting 3

  13. /execute @e[name=cShop,score_shopSetting_min=3,score_shopSetting=3] ~ ~ ~ scoreboard players enable @p[tag=wcreate] isale
  14. /execute @e[name=cShop,score_shopSetting_min=3,score_shopSetting=3] ~ ~ ~ title @p[tag=wcreate] actionbar [{"text":"[甘小蔗] ","color":"dark_green","bold":"true"},{"selector":"@p[tag=wcreate]","color":"gold","bold":"true"},{"text":" 请输入","color":"green","bold":true},{"text":" /trigger isale set 价钱 ","color":"red","bold":true},{"text":"以设置你的物品单价(价位0-100000)","color":"green","bold":true}]

  15. /scoreboard players tag @a[tag=wcreate,score_isale_min=0,score_isale=100000] add setsale
  16. /execute @a[tag=setsale] ~ ~ ~ scoreboard players set @e[name=cShop,score_shopSetting_min=3,score_shopSetting=3,c=1] shopSetting 4

  17. /execute @a[tag=setsale] ~ ~ ~ scoreboard players operation @e[name=cShop,score_shopSetting_min=4,score_shopSetting=4,c=1] isale = @p[tag=setsale] isale
  18. /execute @e[name=cShop,score_shopSetting_min=4,score_shopSetting=4] ~ ~ ~ scoreboard players operation @p[tag=setsale] shopID = @e[name=cShop,c=1,score_shopID_min=0] shopID
  19. /execute @a[tag=setsale] ~ ~ ~ /tellraw @p[tag=wcreate] [{"text":"[甘小蔗] ","color":"dark_green","bold":"true"},{"selector":"@p[tag=setsale]","color":"gold","bold":"true"},{"text":" 您的商店已经设置完毕","color":"green","bold":true}]
  20. /scoreboard players tag @a[tag=setsale] remove wcreate
  21. /scoreboard players tag @a[tag=setsale] add createdShop
  22. /scoreboard players tag @a[tag=createdShop] remove setsale
  23. /execute @e[name=cShop,score_shopSetting_min=4,score_shopSetting=4] ~ ~ ~ teleport @e[score_createitem=-1,c=1] ~ ~0.5 ~
  24. /scoreboard players add @e[name=cShop,score_shopSetting_min=4,score_shopSetting=4] items 1
  25. /scoreboard players set @e[name=cShop,score_shopSetting_min=4,score_shopSetting=4] shopSetting -1
复制代码

shopID分配部分:[高频循环](创建载体:summon armor_stand ~ ~ ~ {CustomName:"shopIDStats"} )
  1. /scoreboard players add @e[name=cShop,score_shopSetting_min=1,score_shopSetting=1] shopID 0
  2. /execute @e[name=cShop,score_shopID_min=0,score_shopID=0] ~ ~ ~ scoreboard players add @e[type=armor_stand,name=shopIDStats] shopID 1
  3. /execute @e[name=cShop,score_shopID_min=0,score_shopID=0] ~ ~ ~ scoreboard players operation @e[r=0,c=1] shopID = @e[type=armor_stand,name=shopIDStats] shopID
复制代码

告示牌信息显示部分:[高频循环]
  1. <b>信息获取</b>
  2. /execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ scoreboard players operation @p getsalep = @e[name=cShop,c=1] isale
  3. /execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ scoreboard players operation @p getshopid = @e[name=cShop,c=1] shopID
  4. /execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ scoreboard players operation @p items = @e[name=cShop,c=1] items

  5. <b>信息显示</b>
  6. execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ blockdata ~-1 ~ ~ {Text1:"{"text":"ShopID:","bold":"true","color":"dark_red","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text2:"{"score":{"name":"@p","objective":"getshopid"},"color":"red","bold":"true","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text3:"{"score":{"name":"@p","objective":"getsalep"},"color":"black","bold":"true","extra":["¥/每份"],"clickEvent":{"action":"run_command","value":"say More on Ganxiaozhe.com"}}",Text4:"{"score":{"name":"@p","objective":"items"},"color":"black","bold":"true","extra":["份/剩余"],"clickEvent":{"action":"run_command","value":""}}"}

  7. execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ blockdata ~1 ~ ~ {Text1:"{"text":"ShopID:","bold":"true","color":"dark_red","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text2:"{"score":{"name":"@p","objective":"getshopid"},"color":"red","bold":"true","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text3:"{"score":{"name":"@p","objective":"getsalep"},"color":"black","bold":"true","extra":["¥/每份"],"clickEvent":{"action":"run_command","value":"say More on Ganxiaozhe.com"}}",Text4:"{"score":{"name":"@p","objective":"items"},"color":"black","bold":"true","extra":["份/剩余"],"clickEvent":{"action":"run_command","value":""}}"}

  8. execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ blockdata ~ ~ ~-1 {Text1:"{"text":"ShopID:","bold":"true","color":"dark_red","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text2:"{"score":{"name":"@p","objective":"getshopid"},"color":"red","bold":"true","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text3:"{"score":{"name":"@p","objective":"getsalep"},"color":"black","bold":"true","extra":["¥/每份"],"clickEvent":{"action":"run_command","value":"say More on Ganxiaozhe.com"}}",Text4:"{"score":{"name":"@p","objective":"items"},"color":"black","bold":"true","extra":["份/剩余"],"clickEvent":{"action":"run_command","value":""}}"}

  9. execute @e[name=cShop,score_shopSetting=-1] ~ ~ ~ blockdata ~ ~ ~1 {Text1:"{"text":"ShopID:","bold":"true","color":"dark_red","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text2:"{"score":{"name":"@p","objective":"getshopid"},"color":"red","bold":"true","extra":[""],"clickEvent":{"action":"run_command","value":""}}",Text3:"{"score":{"name":"@p","objective":"getsalep"},"color":"black","bold":"true","extra":["¥/每份"],"clickEvent":{"action":"run_command","value":"say More on Ganxiaozhe.com"}}",Text4:"{"score":{"name":"@p","objective":"items"},"color":"black","bold":"true","extra":["份/剩余"],"clickEvent":{"action":"run_command","value":""}}"}
复制代码

使玩家只能有1个商店:[高频循环]
  1. clear @a[tag=createdShop] spawn_egg 0 64 {display:{Name:"创建商店"}}
复制代码



By 甘小蔗
感谢@DHK的提议

评分

参与人数 4 小麦 +2 金锭 +17 收起 理由
小白on1 + 1 666666
Msure + 3 优秀作品
WJK123456789 + 1 + 3 天哪,做出来了
DHK + 1 + 10 乐于助人

查看全部评分

甘小蔗是我,我是甘小蔗!不是盗取什么的!委屈!

5

主题

38

帖子

15

积分

Lv.1 新手木匠

UID
3336249
小麦
0
金锭
98
下界之星
0
发表于 2017-11-18 22:45:54 来自手机 | 显示全部楼层
谢谢楼主,我正筹划开个租赁服呢,正在寻找箱子商店的命令方块指令呢

65

主题

791

帖子

370

积分

Lv.5 农牧专家

UID
14859
小麦
92
金锭
425
下界之星
0
 楼主| 发表于 2017-11-18 22:54:59 | 显示全部楼层
Tbolw丶二冰 发表于 2017-11-18 22:45
谢谢楼主,我正筹划开个租赁服呢,正在寻找箱子商店的命令方块指令呢

谢谢,你的支持便是我更新的动力
甘小蔗是我,我是甘小蔗!不是盗取什么的!委屈!

6

主题

410

帖子

1500

积分

Lv.7 下界居民

UID
3302
小麦
1371
金锭
4011
下界之星
0
发表于 2017-11-19 10:46:32 | 显示全部楼层
啊啊啊我感觉要看好几天才能学会了
   
DHK
网易我的世界开发者平台认证   个人开发者 / 皮肤作者 / 指令玩家
   

7

主题

26

帖子

15

积分

Lv.1 新手木匠

UID
61875
小麦
1
金锭
55
下界之星
0
发表于 2017-11-19 14:34:58 | 显示全部楼层
很好,谢谢楼主,就是难一点

0

主题

1

帖子

0

积分

Lv.1 新手木匠

UID
2668522
小麦
0
金锭
18
下界之星
0
发表于 2017-11-19 17:23:34 来自手机 | 显示全部楼层
有人吗!

56

主题

1388

帖子

1297

积分

攻略组

以离别的的速度抬起头,在夜尽天明的那一天,快睁开眼看一看吧。

UID
15812
小麦
884
金锭
3695
下界之星
0

二周年纪念勋章一周年纪念勋章玩家团队勋章

发表于 2017-11-19 17:35:31 | 显示全部楼层
竟然做出来了qwq....大佬大佬

24

主题

116

帖子

55

积分

Lv.3 矿物能手

UID
40235
小麦
1
金锭
222
下界之星
0
发表于 2017-11-19 20:08:33 | 显示全部楼层
本帖最后由 HXF31 于 2017-11-19 20:31 编辑

一个人只能创建一个商店,限制比较大还有就是不知道上面的东西怎么掉下来了,虽然还是有点问题,不能算是完整版的,但大佬这就牛逼了,支持,加油,希望能看到完美的商店。
[attach]*47[/attach]
[attach]*36[/attach]

9

主题

56

帖子

26

积分

Lv.2 石器学徒

UID
15801
小麦
3
金锭
134
下界之星
0
发表于 2017-11-19 22:26:35 | 显示全部楼层
HXF31 发表于 2017-11-19 21:08
一个人只能创建一个商店,限制比较大还有就是不知道上面的东西怎么掉下来了,虽然还是有点问题,不能算是完 ...

掉下来其实要搞比较简单
把它tp回去就好
可以叫作者修复一下

65

主题

791

帖子

370

积分

Lv.5 农牧专家

UID
14859
小麦
92
金锭
425
下界之星
0
 楼主| 发表于 2017-11-19 22:49:38 | 显示全部楼层
HXF31 发表于 2017-11-19 20:08
一个人只能创建一个商店,限制比较大还有就是不知道上面的东西怎么掉下来了,虽然还是有点问题,不能算是完 ...

谢谢支持,掉下来的原因是因为你补货的时候将物品丢在了箱子上方导致物品在指令没有反映过来前就融合了。在补货时请将物品扔在箱子附近即可解决你的问题哦
甘小蔗是我,我是甘小蔗!不是盗取什么的!委屈!

0

主题

12

帖子

3

积分

Lv.1 新手木匠

UID
919368
小麦
0
金锭
13
下界之星
0
发表于 2017-11-20 05:04:34 | 显示全部楼层
东西会掉下来咋办

65

主题

791

帖子

370

积分

Lv.5 农牧专家

UID
14859
小麦
92
金锭
425
下界之星
0
 楼主| 发表于 2017-11-20 06:40:56 | 显示全部楼层
Untforos 发表于 2017-11-20 05:04
东西会掉下来咋办

掉下来的原因是因为你补货的时候将物品丢在了箱子上方导致物品在指令没有反映过来前就融合了。在补货时请将物品扔在箱子附近即可解决你的问题哦,这个问题在后面我会更新修复
甘小蔗是我,我是甘小蔗!不是盗取什么的!委屈!

46

主题

553

帖子

289

积分

Lv.5 农牧专家

UID
16359
小麦
89
金锭
1640
下界之星
0
发表于 2017-11-20 12:42:02 来自手机 | 显示全部楼层
欢迎来到甘蔗逼死插件系列

178

主题

5263

帖子

1627

积分

等待验证会员

会玩不熊听指挥

UID
11683
小麦
113
金锭
3436
下界之星
0

一周年纪念勋章内测精英勋章

发表于 2017-11-23 10:35:15 来自手机 | 显示全部楼层
谢谢楼主分享

4

主题

111

帖子

35

积分

Lv.2 石器学徒

UID
7280
小麦
1
金锭
319
下界之星
0
发表于 2017-11-25 13:33:57 来自手机 | 显示全部楼层
学习了,感谢大佬心血付出~

点评

谢谢支持  发表于 2017-11-25 13:35
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部