签到系统

By Msure    2018/12/08

今天给大家带来的是签到系统,一般租赁服里的签到系统都是每天计时(通过每秒20gt)重置一次。但是一般其他游戏里都会有显示连续签到天数之类的,所以这次带来了类似功能的签到系统。


如图:可以显示连续签到天数,并达到一定天数给予额外奖励

我的世界签到系统

若数天不签到,再次签到时会显示未签到天数

我的世界签到系统

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


详情:

[原理]

  • 重置和校准 - 和计时重置不同,计时重置会由于卡顿造成时间偏差,还需要手动设置当前时间。受到素学姐丢人钟的原理启发,使用testforblock来读取现实中的时间。(执行命令时返回信息前会有一个时间,通过testforblock来检测命令方块的时间是否到达某时间点,再执行命令)
  • 连续签到天数和未签到天数 - 创建了一个day记分板来记录当前天数,每天24点重置时都会给这个记分板分数+1。当玩家签到时,会把当前天数和上次签到时记录的天数相减,通过差值来判断玩家是否每天连续签到。同时: 差值=未签到天数+1 即可得到未签到天数。
  • 两个签到版本 - 为了照顾服务器资源,做了两个签到,一个低配版(乞丐版),一个正常版。低配版没有显示连续签到、未签到天数、给予连续签到奖励的功能,只能每天让玩家签到一次,给予固定的签到奖励。但是命令较少,占用资源少。正常版功能如开始的展示图所示,所有功能一应俱全。正常版的连续签到奖励只写了第7天的,需要更多天数的可插入命令方块自己添加(插入位置命令方块内有文字说明)。


代码:

基础部分:

  1. rcb:/scoreboard players enable @a click
  2. /give @a[score_click_min=1,score_sign=0] diamond 1 0
  3. /execute @a[score_click_min=1,score_sign=0] ~ ~ ~ scoreboard players operation @p day1 = @p day
  4. /execute @a[score_click_min=1,score_sign=0] ~ ~ ~ scoreboard players operation @p day1 -= @p day2
  5. /scoreboard players set @a[score_click_min=1,score_sign=0,score_day1_min=2] day3 0
  6. /scoreboard players add @a[score_click_min=1,score_sign=0] day3 1
  7. /scoreboard players remove @a[score_click_min=1,score_sign=0] day1 1
  8. /execute @a[score_day3=1,score_click_min=1,score_sign=0] ~ ~ ~ tellraw @p {"text":"","extra":[{"text":"签到成功!您之前有 ","color":"gold","bold":true},{"score":{"name":"@p","objective":"day1"},"color":"red","bold":true},{"text":" 天未签到。","color":"gold","bold":true}]}
  9. /execute @a[score_day3_min=2,score_click_min=1,score_sign=0] ~ ~ ~ tellraw @p {"text":"","extra":[{"text":"签到成功!您已经连续签到 ","color":"gold","bold":true},{"score":{"name":"@p","objective":"day3"},"color":"green","bold":true},{"text":" 天。","color":"gold","bold":true}]}
  10. /execute @a[score_click_min=1,score_sign_min=1] ~ ~ ~ tellraw @p {"text":"","extra":[{"text":"今天已经签过到了!当前连续签到天数: ","color":"red","bold":true},{"score":{"name":"@p","objective":"day3"},"color":"green","bold":true},{"text":" 天。","color":"red","bold":true}]}
  11. /give @a[score_click_min=1,score_day3_min=7,score_day3=7,score_sign=0] diamond_block 1 0
  12. /give @a[score_click_min=1,score_day3_min=15,score_day3=15,score_sign=0] 15天签到奖励,可在此继续插入命令方块自定义连续签到奖励
  13. /execute @a[score_click_min=1,score_sign=0] ~ ~ ~ scoreboard players operation @p day2 = @p day
  14. /scoreboard players set @a[score_click_min=1,score_sign=0] sign 1
  15. /scoreboard players set @a[score_click_min=1] click 0
  16. /gamemode
  17. /testforblock ~ ~-1 ~ chain_command_block 1 {LastOutput:"{"extra":[{"color":"red","translate":"commands.generic.usage","with":[{"translate":"commands.gamemode.usage"}]}],"text":"[23:59:58] "}"}
  18. cond:/scoreboard players set * sign 0
  19. cond:/setblock ~ ~4 ~ minecraft:redstone_block
  20. /testforblock ~ ~-4 ~ chain_command_block 1 {LastOutput:"{"extra":[{"color":"red","translate":"commands.generic.usage","with":[{"translate":"commands.gamemode.usage"}]}],"text":"[29:59:59] "}"}
  21. cond:/setblock ~ ~2 ~ minecraft:air
  22. icb:/scoreboard players add * day 1

OOC:低配版

  1. /summon falling_block ~ ~1.5 ~ {Time:1,Block:"minecraft:redstone_block",Motion:[0d,-1d,0d],Passengers:[{id:falling_block,Time:1,Block:"minecraft:activator_rail",Passengers:[{id:commandblock_minecart,Command:"blockdata ~ ~-2 ~ {auto:0b,Command:\"\"}"},{id:commandblock_minecart,Command:"/scoreboard objectives add click trigger"},{id:commandblock_minecart,Command:"/scoreboard objectives add sign dummy"},{id:commandblock_minecart,Command:"setblock ~2 ~7 ~0 chain_command_block 9 replace {Command:\"/scoreboard players set * sign 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~6 ~0 chain_command_block 1 replace {Command:\"/testforblock ~ ~-1 ~ chain_command_block 1 {LastOutput:\\\"{\\\\\\\"extra\\\\\\\":[{\\\\\\\"color\\\\\\\":\\\\\\\"red\\\\\\\",\\\\\\\"translate\\\\\\\":\\\\\\\"commands.generic.usage\\\\\\\",\\\\\\\"with\\\\\\\":[{\\\\\\\"translate\\\\\\\":\\\\\\\"commands.gamemode.usage\\\\\\\"}]}],\\\\\\\"text\\\\\\\":\\\\\\\"[23:59:59] \\\\\\\"}\\\"}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~5 ~0 chain_command_block 1 replace {Command:\"/gamemode\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~4 ~0 chain_command_block 1 replace {Command:\"/scoreboard players set @a[score_click_min=1] click 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~3 ~0 chain_command_block 1 replace {Command:\"/scoreboard players set @a[score_click_min=1,score_sign=0] sign 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~2 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_click_min=1,score_sign_min=1] ~ ~ ~ tellraw @p [{\\\"selector\\\":\\\"@p\\\",\\\"color\\\":\\\"gold\\\"},{\\\"text\\\":\\\" 不能重复签到!\\\",\\\"color\\\":\\\"red\\\"}]\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~1 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_click_min=1,score_sign=0] ~ ~ ~ tellraw @p [{\\\"selector\\\":\\\"@p\\\",\\\"color\\\":\\\"gold\\\"},{\\\"text\\\":\\\" 您已签到成功!\\\",\\\"color\\\":\\\"green\\\"}]\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~0 chain_command_block 1 replace {Command:\"/give @a[score_click_min=1,score_sign=0] minecraft:diamond 1 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~0 chain_command_block 1 replace {Command:\"/scoreboard players add @a[score_click_min=1] sign 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-2 ~0 repeating_command_block 1 replace {Command:\"/scoreboard players enable @a click\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~ ~1 ~ command_block 0 replace {auto:1b,Command:\"fill ~ ~ ~ ~ ~-2 ~ air\"}"},{id:commandblock_minecart,Command:"kill @e[type=commandblock_minecart,r=1]"}]}]}

获取签到书

  1. /give @p minecraft:written_book 1 0 {title:"Msure",author:"签到书",pages:["{\"text\":\"\",\"extra\":[{\"text\":\"【签到】\",\"color\":\"gold\",\"bold\":true,\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/trigger click set 1\"}}]}"]}

OOC:正常版

初始化

  1. /summon falling_block ~ ~1.5 ~ {Time:1,Block:"minecraft:redstone_block",Motion:[0d,-1d,0d],Passengers:[{id:falling_block,Time:1,Block:"minecraft:activator_rail",Passengers:[{id:commandblock_minecart,Command:"blockdata ~ ~-2 ~ {auto:0b,Command:\"\"}"},{id:commandblock_minecart,Command:"/scoreboard objectives add day dummy"},{id:commandblock_minecart,Command:"/scoreboard objectives add day1 dummy"},{id:commandblock_minecart,Command:"/scoreboard objectives add day2 dummy"},{id:commandblock_minecart,Command:"/scoreboard objectives add day3 dummy"},{id:commandblock_minecart,Command:"/scoreboard objectives add sign dummy"},{id:commandblock_minecart,Command:"/scoreboard objectives add click trigger"},{id:commandblock_minecart,Command:"setblock ~2 ~3 ~0 chain_command_block 1 replace {Command:\"/scoreboard players tag @a[tag=!sign] add sign\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~2 ~0 chain_command_block 1 replace {Command:\"/scoreboard players add @a[tag=!sign] sign 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~1 ~0 chain_command_block 1 replace {Command:\"/scoreboard players add @a[tag=!sign] day3 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~0 chain_command_block 1 replace {Command:\"/scoreboard players add @a[tag=!sign] day2 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~0 chain_command_block 1 replace {Command:\"/scoreboard players add @a[tag=!sign] day1 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-2 ~0 repeating_command_block 1 replace {Command:\"/scoreboard players set @a[tag=!sign] day 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~ ~1 ~ command_block 0 replace {auto:1b,Command:\"fill ~ ~ ~ ~ ~-2 ~ air\"}"},{id:commandblock_minecart,Command:"kill @e[type=commandblock_minecart,r=1]"}]}]}

签到部分

  1. /summon falling_block ~ ~1.5 ~ {Time:1,Block:"minecraft:redstone_block",Motion:[0d,-1d,0d],Passengers:[{id:falling_block,Time:1,Block:"minecraft:activator_rail",Passengers:[{id:commandblock_minecart,Command:"blockdata ~ ~-2 ~ {auto:0b,Command:\"\"}"},{id:commandblock_minecart,Command:"setblock ~2 ~19 ~0 command_block 1 replace {Command:\"/scoreboard players add * day 1\"}"},{id:commandblock_minecart,Command:"setblock ~2 ~18 ~0 chain_command_block 9 replace {Command:\"/setblock ~ ~2 ~ minecraft:air\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~17 ~0 chain_command_block 1 replace {Command:\"/testforblock ~ ~-4 ~ chain_command_block 1 {LastOutput:\\\"{\\\\\\\"extra\\\\\\\":[{\\\\\\\"color\\\\\\\":\\\\\\\"red\\\\\\\",\\\\\\\"translate\\\\\\\":\\\\\\\"commands.generic.usage\\\\\\\",\\\\\\\"with\\\\\\\":[{\\\\\\\"translate\\\\\\\":\\\\\\\"commands.gamemode.usage\\\\\\\"}]}],\\\\\\\"text\\\\\\\":\\\\\\\"[23:59:59] \\\\\\\"}\\\"}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~16 ~0 chain_command_block 9 replace {Command:\"/setblock ~ ~4 ~ minecraft:redstone_block\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~15 ~0 chain_command_block 9 replace {Command:\"/scoreboard players set * sign 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~14 ~0 chain_command_block 1 replace {Command:\"/testforblock ~ ~-1 ~ chain_command_block 1 {LastOutput:\\\"{\\\\\\\"extra\\\\\\\":[{\\\\\\\"color\\\\\\\":\\\\\\\"red\\\\\\\",\\\\\\\"translate\\\\\\\":\\\\\\\"commands.generic.usage\\\\\\\",\\\\\\\"with\\\\\\\":[{\\\\\\\"translate\\\\\\\":\\\\\\\"commands.gamemode.usage\\\\\\\"}]}],\\\\\\\"text\\\\\\\":\\\\\\\"[23:59:58] \\\\\\\"}\\\"}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~13 ~0 chain_command_block 1 replace {Command:\"/gamemode\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~12 ~0 chain_command_block 1 replace {Command:\"/scoreboard players set @a[score_click_min=1] click 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~11 ~0 chain_command_block 1 replace {Command:\"/scoreboard players set @a[score_click_min=1,score_sign=0] sign 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~10 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_click_min=1,score_sign=0] ~ ~ ~ scoreboard players operation @p day2 = @p day\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~9 ~0 chain_command_block 1 replace {Command:\"/give @a[score_click_min=1,score_day3_min=15,score_day3=15,score_sign=0] 15天签到奖励,可在此继续插入命令方块自定义连续签到奖励\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~8 ~0 chain_command_block 1 replace {Command:\"/give @a[score_click_min=1,score_day3_min=7,score_day3=7,score_sign=0] diamond_block 1 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~7 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_click_min=1,score_sign_min=1] ~ ~ ~ tellraw @p {\\\"text\\\":\\\"\\\",\\\"extra\\\":[{\\\"text\\\":\\\"今天已经签过到了!当前连续签到天数: \\\",\\\"color\\\":\\\"red\\\",\\\"bold\\\":true},{\\\"score\\\":{\\\"name\\\":\\\"@p\\\",\\\"objective\\\":\\\"day3\\\"},\\\"color\\\":\\\"green\\\",\\\"bold\\\":true},{\\\"text\\\":\\\" 天。\\\",\\\"color\\\":\\\"red\\\",\\\"bold\\\":true}]}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~6 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_day3_min=2,score_click_min=1,score_sign=0] ~ ~ ~ tellraw @p {\\\"text\\\":\\\"\\\",\\\"extra\\\":[{\\\"text\\\":\\\"签到成功!您已经连续签到 \\\",\\\"color\\\":\\\"gold\\\",\\\"bold\\\":true},{\\\"score\\\":{\\\"name\\\":\\\"@p\\\",\\\"objective\\\":\\\"day3\\\"},\\\"color\\\":\\\"green\\\",\\\"bold\\\":true},{\\\"text\\\":\\\" 天。\\\",\\\"color\\\":\\\"gold\\\",\\\"bold\\\":true}]}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~5 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_day3=1,score_click_min=1,score_sign=0] ~ ~ ~ tellraw @p {\\\"text\\\":\\\"\\\",\\\"extra\\\":[{\\\"text\\\":\\\"签到成功!您之前有 \\\",\\\"color\\\":\\\"gold\\\",\\\"bold\\\":true},{\\\"score\\\":{\\\"name\\\":\\\"@p\\\",\\\"objective\\\":\\\"day1\\\"},\\\"color\\\":\\\"red\\\",\\\"bold\\\":true},{\\\"text\\\":\\\" 天未签到。\\\",\\\"color\\\":\\\"gold\\\",\\\"bold\\\":true}]}\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~4 ~0 chain_command_block 1 replace {Command:\"/scoreboard players remove @a[score_click_min=1,score_sign=0] day1 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~3 ~0 chain_command_block 1 replace {Command:\"/scoreboard players add @a[score_click_min=1,score_sign=0] day3 1\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~2 ~0 chain_command_block 1 replace {Command:\"/scoreboard players set @a[score_click_min=1,score_sign=0,score_day1_min=2] day3 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~1 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_click_min=1,score_sign=0] ~ ~ ~ scoreboard players operation @p day1 -= @p day2\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~0 ~0 chain_command_block 1 replace {Command:\"/execute @a[score_click_min=1,score_sign=0] ~ ~ ~ scoreboard players operation @p day1 = @p day\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-1 ~0 chain_command_block 1 replace {Command:\"/give @a[score_click_min=1,score_sign=0] diamond 1 0\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~2 ~-2 ~0 repeating_command_block 1 replace {Command:\"/scoreboard players enable @a click\",auto:1b}"},{id:commandblock_minecart,Command:"setblock ~ ~1 ~ command_block 0 replace {auto:1b,Command:\"fill ~ ~ ~ ~ ~-2 ~ air\"}"},{id:commandblock_minecart,Command:"kill @e[type=commandblock_minecart,r=1]"}]}]}

获取签到书

  1. /give @p minecraft:written_book 1 0 {title:"Msure",author:"签到书",pages:["{\"text\":\"\",\"extra\":[{\"text\":\"【签到】\",\"color\":\"gold\",\"bold\":true,\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/trigger click set 1\"}}]}"]}


LOADING | 此框架正在加载中
QQ群:771363745