服务器转账系统

Ganxiaozhe
2019/07/15

未经作者授权,禁止转载

服务器原版转账系统,玩家可指定用户转入任意金额。

我的世界原版转账系统

如图:转账分为三部,第一步激活转账(该指令可放在指令书或者告示牌的click事件中,玩家可无权限调用),第二步选择转账目标,第三步输入转账金额即可。

我的世界原版转账系统

若转账目标未知则不会进行下一步。

我的世界原版转账系统

同样,如果玩家输入错误数值、负数金额、超出自身金币范围的金额都会触发提示。



原理

trigger技术、uid分配(玩家唯一标识)。

UID分配主要是为了指定玩家。如果你服务器已经做了uid分配,则只需把转账处理中第3行与13行中的uid改为你的积分项。money积分项需修改第32行与39、40行。

如在服务器中使用,可低频激活,上图为1s执行一次。如在1.8版本中实现只需将@s改为@p[r=0]即可。



代码

初始化:

  1. scoreboard objectives add zz trigger
  2. scoreboard objectives add zzmb trigger
  3. scoreboard objectives add zzje trigger
  4. scoreboard objectives add zz_temp dummy
  5. scoreboard objectives add zz_yz dummy
  6. scoreboard objectives add zz_timer dummy
  7. scoreboard objectives add uid dummy
  8. scoreboard objectives add money dummy

uid分配[低频\高频]:

  1. scoreboard players add @a uid 0
  2. execute @p[score_uid_min=0,score_uid=0] ~ ~ ~ scoreboard players add UIDStats uid 1
  3. execute @p[score_uid_min=0,score_uid=0] ~ ~ ~ scoreboard players operation @s uid = UIDStats uid

转账处理[低频\高频]:

  1. #激活转账系统
  2. scoreboard players enable @a zz
  3. execute @p[score_zz_min=1] ~ ~ ~ /execute @a ~ ~ ~ tellraw @a[score_zz_min=1] ["> \u00a7a玩家名字: ",{"selector":"@p[r=0]","color":"white","bold":"true"}," \u00a7e玩家UID: ",{"score":{"name":"@p[r=0]","objective":"uid"},"color":"white","bold":"true"}]
  4. tellraw @a[score_zz_min=1] ["\n\u00a76\u00a7l[转账系统] \u00a7c\u00a7l您发起了转账请求,请输入\u00a7e\u00a7l/trigger zzmb set N\u00a7c\u00a7l选择收款玩家,N为玩家列表旁的数字(UID)。 \u00a7a[请在一分钟之内完成转账,延期自动取消]\n",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger zzmb set "}}]
  5. scoreboard players enable @a[score_zz_min=1] zzmb
  6. scoreboard players set @a[score_zz_min=1] zz 0
  7. #确定转账目标
  8. testfor @a[score_zzmb_min=1,tag=transfering]
  9. cond:tellraw @a[score_zzmb_min=1,tag=!transfering] ["\u00a76\u00a7l[转账系统] \u00a7e当前转账系统占线中,请稍后再试。"]
  10. cond:scoreboard players reset @a[score_zzmb_min=1,tag=!transfering] zzmb
  11. scoreboard players tag @a[score_zzmb_min=1] add transfering
  12. execute @a[score_zzmb_min=1] ~ ~ ~ scoreboard players operation @a zz_temp = @s zzmb
  13. execute @p[score_zzmb_min=1,tag=transfering] ~ ~ ~ execute @a ~ ~ ~ scoreboard players operation @s zz_temp -= @s uid
  14. scoreboard players test @a[tag=!transfering] zz_temp 0 0
  15. cond:scoreboard players tag @p[score_zzmb_min=1,tag=transfering] add zzmbY
  16. cond:scoreboard players tag @p[score_zzmb_min=1,tag=transfering] add zz_fk
  17. cond:scoreboard players tag @p[score_zz_temp_min=0,score_zz_temp=0] add zz_sk
  18. tellraw @a[score_zzmb_min=1,tag=zzmbY] ["\u00a76\u00a7l[转账系统] \u00a7e入账账户: ",{"selector":"@p[tag=zz_sk]","color":"white","bold":"true"}," \u00a7c\u00a7l请输入\u00a7e\u00a7l/trigger zzje set 转账金额\u00a7c\u00a7l进行转账。\n",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger zzje set "}}]
  19. scoreboard players enable @a[score_zzmb_min=1,tag=zzmbY] zzje
  20. tellraw @a[score_zzmb_min=1,tag=!zzmbY] ["\u00a76\u00a7l[转账系统] \u00a7e未知账户!已自动退出转账系统。"]
  21. execute @a[score_zzmb_min=1,tag=!zzmbY] ~ ~ ~ scoreboard players reset * zz_temp
  22. execute @a[score_zzmb_min=1,tag=!zzmbY] ~ ~ ~ scoreboard players tag * remove zz_fk
  23. execute @a[score_zzmb_min=1,tag=!zzmbY] ~ ~ ~ scoreboard players tag * remove zz_sk
  24. scoreboard players tag @a[score_zzmb_min=1] remove zzmbY
  25. scoreboard players reset @a[score_zzmb_min=1] zzmb
  26. #转账金额处理
  27. scoreboard players test @a[tag=transfering] zzje -2147483648 -1
  28. cond:tellraw @a[tag=transfering] ["\u00a76\u00a7l[转账系统] \u00a7e请输入有效数值!"]
  29. cond:scoreboard players reset @a[tag=transfering,score_zzje=-1] zzje
  30. cond:scoreboard players enable @a[tag=transfering] zzje
  31. scoreboard players operation @a[score_zzje_min=1,tag=transfering] zz_yz = @a[score_zzje_min=1,tag=transfering] zzje
  32. scoreboard players operation @a[score_zzje_min=1,tag=transfering] zz_yz -= @a[score_zzje_min=1,tag=transfering] money
  33. tellraw @a[score_zz_yz_min=1,tag=transfering] ["\u00a76\u00a7l[转账系统] \u00a7e账户余额不足!请重新输入转账金额。"]
  34. scoreboard players reset @a[score_zz_yz_min=1,tag=transfering] zzje
  35. scoreboard players enable @a[score_zz_yz_min=1,tag=transfering] zzje
  36. scoreboard players reset @a[score_zz_yz_min=1,tag=transfering] zz_yz
  37. execute @a[score_zzje_min=1,tag=transfering] ~ ~ ~ tellraw @a[tag=zz_sk] ["\u00a76\u00a7l[账户收款] ",{"selector":"@a[tag=zz_fk]","color":"white","bold":"true"}," \u00a7a向您转账 ",{"score":{"name":"@a[tag=zz_fk]","objective":"zzje"},"color":"yellow","bold":"true"},"\u00a7a元。"]
  38. execute @a[score_zzje_min=1,tag=transfering] ~ ~ ~ tellraw @s ["\u00a76\u00a7l[账户支出] \u00a7a您成功向 ",{"selector":"@a[tag=zz_sk]","color":"white","bold":"true"}," \u00a7a转账 ",{"score":{"name":"@s","objective":"zzje"},"color":"yellow","bold":"true"},"\u00a7a元。"]
  39. execute @a[tag=transfering,score_zzje_min=1] ~ ~ ~ scoreboard players operation @s money -= @s zzje
  40. execute @a[tag=transfering,score_zzje_min=1] ~ ~ ~ scoreboard players operation @a[tag=zz_sk] money += @s zzje
  41. execute @a[tag=transfering,score_zzje_min=1] ~ ~ ~ scoreboard players reset * zz_temp
  42. execute @a[tag=transfering,score_zzje_min=1] ~ ~ ~ scoreboard players tag * remove zz_fk
  43. execute @a[tag=transfering,score_zzje_min=1] ~ ~ ~ scoreboard players tag * remove zz_sk
  44. scoreboard players tag @a[tag=transfering,score_zzje_min=1] remove transfering
  45. scoreboard players reset @a[score_zzje_min=1] zzje
  46. #转账超时处理
  47. scoreboard players add @a[tag=transfering] zz_timer 1
  48. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players reset * zzmb
  49. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players reset * zzje
  50. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players reset * zz_temp
  51. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players tag * remove zz_fk
  52. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players tag * remove zz_sk
  53. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players tag * remove transfering
  54. tellraw @a[score_zz_timer_min=60] ["\u00a76\u00a7l[转账系统] \u00a7e转账时长延期!已自动退出转账系统。"]
  55. execute @a[score_zz_timer_min=60] ~ ~ ~ scoreboard players reset * zz_timer

未经作者授权,禁止转载





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