计算K/D

最终效果:

K/D:击杀数÷死亡数

所以你需要建立两个计分板:

  1. /scoreboard objectives add kills totalKillCount
  2. /scoreboard objectives add kd dummy

然后摆放1个ICB,3个CCB

教程图片
  1. scoreboard players operation @p kd = @p kills

将最近的玩家的kills分数赋值给最近的玩家的kd分数,说简单点就是让最近的玩家kd分数与kills分数相等

第一个CCB:

  1. scoreboard players operation @p kd /= @p death

用最近的玩家的kd分数除以death分数,结果储存在kd

第二个CCB:

  1. tellraw @p [{"text":"K/D: ","color":"green"},{"score":{"objective":"kd","name":"*"}}]

告诉最近的玩家它的kd分数

第三个CCB:

  1. scoreboard players reset @p kd

重置kd分数

计算小数

由于MC的计分板并不支持小数,所以我们需要单独建立一个计分板来储存小数部分:

  1. /scoreboard objectives add kdf dummy

假设steve杀了5人死了2次,那么他的k/d是2.5

2.5计算过程:

 

5/2=2......1

1*10=10

10/2=5

这样就可以得到一个公式:K/D = K÷D

K/D小数部分 = (K÷D的余数)*10÷D

MC中正好有求余数的方法,但×10似乎很难实现

×10其实可以通过假名来实现,即不存在的名称,可以新建一个计分板:Math

然后输入:

  1. /scoreboard players set 10 Math 10

然后让余数*Math中的10就好

所以可以得到下面的指令:

  1. scoreboard players operation @p kdf = @p kills

让kdf等于kills

  1. scoreboard players operation @p kdf %= @p death

求kdf÷death的余数,结果储存在kdf

  1. scoreboard players operation @p kdf *= 10 Math

让kdf分数*10

  1. scoreboard players operation @p kdf /= @p death

kdf÷death,结果储存在kdf

完成!然后在前面加上整数就好了!

完整指令:

  1. scoreboard players operation @p kd = @p kills
  2. scoreboard players operation @p kd /= @p death
  3. scoreboard players operation @p kdf = @p kills
  4. scoreboard players operation @p kdf %= @p death
  5. scoreboard players operation @p kdf *= 10 Math
  6. scoreboard players operation @p kdf /= @p death
  7. tellraw @p [{"text":"K/D: ","color":"green"},{"score":{"objective":"kd","name":"*"}},{"text":"."},{"score":{"objective":"kdf","name":"*"}}]
  8. scoreboard players reset @p kd
  9. scoreboard players reset @p kdf

这样就可以计算到1位小数了

如果要计算更多位小数,就将10的Math分数设置为100,1000或更高

例如,计算两位小数:

  1. /scoreboard players set 10 Math 100

虽然名字叫"10",但他的分数是100,然后再运行指令,就可以计算2位小数啦

教程图片
  • what_name2018-04-12

                        
    • what_name2018-04-21

      这是一条回复