分段在线奖励

By MCSugar_cane    2017/12/10

用命令方块实现玩家在线时长奖励,在线时间越长奖励越丰厚哦,还可设置为你喜欢的在线时长,代码适用版本为1.11.2-1.12

PS: 在写完代码后我才惊喜的发现:我拓麻为什么要用tag来分段!直接计分板不是更好吗!(但懒癌缠身的我已经不想改了:[)


分段在线奖励

图片就介绍到这里,下面是思路以及代码部分~


整体思路:

总体上来说非常的简单,就是计分板计时的处理,可能唯一的逻辑难点就是tag那部分。

而tag...这个本来可以更简单的实现,鬼知道我为什么会想到tag。这里我说一下更简单的方法,给玩家计分板G不断加分,当达到第一个值例如4400,则给予铁锭;到达第二个值8800时给予金锭...到达最后值的时候重置该玩家G分数,1次循环完毕。下面的代码用的tag分段,可能比较绕,见谅。不过此逻辑可能在其他地方起到重要作用。(让我骗过自己!)


代码:

创建变量:

  1. /scoreboard objectives add gifttimer dummy
  2. /scoreboard objectives add ini dummy 初始化

初始化Tag:[高频循环]

  1. /scoreboard players add @a ini 0
  2. /scoreboard players tag @a[score_ini=0,score_ini_min=0] add m1
  3. /scoreboard players set @a[score_ini=0,score_ini_min=0] ini 1

奖励获取:[高频循环]

  1. /scoreboard players add @a gifttimer 1
  2. /execute @a[tag=m1,score_gifttimer_min=4400,score_gifttimer=4400] ~ ~ ~ tellraw @p[tag=m1,r=0] [{"text":"[在线奖励] ","color":"dark_green","bold":"true"},{"selector":"@p","color":"gold","bold":"true"},{"text":",您已经呆了一段时间了,这是您的奖励~","color":"green","bold":true}]
  3. /execute @a[tag=m2,score_gifttimer_min=4400,score_gifttimer=4400] ~ ~ ~ tellraw @p[tag=m2,r=0] [{"text":"[在线奖励] ","color":"dark_green","bold":"true"},{"selector":"@p","color":"gold","bold":"true"},{"text":",您在服务器观望了一段时间了,这是您的奖励~","color":"green","bold":true}]
  4. /execute @a[tag=m3,score_gifttimer_min=4400,score_gifttimer=4400] ~ ~ ~ tellraw @p[tag=m3,r=0] [{"text":"[在线奖励] ","color":"dark_green","bold":"true"},{"selector":"@p","color":"gold","bold":"true"},{"text":",你已在线较长时间,请注意休息哦,这是您的奖励~","color":"green","bold":true}]
  5. /give @a[tag=m1,score_gifttimer_min=4400,score_gifttimer=4400] minecraft:iron_ingot 8 0
  6. /give @a[tag=m2,score_gifttimer_min=4400,score_gifttimer=4400] minecraft:gold_ingot 6 0
  7. /give @a[tag=m3,score_gifttimer_min=4400,score_gifttimer=4400] minecraft:diamond 3 0

Tag分段处理:[高频循环]

  1. /scoreboard players tag @a[tag=m3,score_gifttimer_min=4401] add m1
  2. /scoreboard players tag @a[tag=m2,score_gifttimer_min=4401] add m3
  3. /scoreboard players tag @a[tag=m1,tag=!m3,score_gifttimer_min=4401] add m2
  4. /scoreboard players tag @a[tag=m3,tag=!m2,score_gifttimer_min=4401] remove m3
  5. /scoreboard players set @a[score_gifttimer_min=4401] gifttimer 0
  6. /scoreboard players tag @a[tag=m2] remove m1
  7. /scoreboard players tag @a[tag=m3] remove m2


OOC:

v1.11.2-v1.12
展开


欢迎加群交流划水:481528679