服务器玩家传送系统

Ganxiaozhe
2019/07/26

未经作者授权,禁止转载

我的世界服务原版传送邀请,玩家可指定用户进行邀请,被邀请用户可选择同意与拒绝,若超时未处理邀请请求,将自动拒绝。



原理

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

UID分配主要是为了指定玩家。如果你服务器已经做了uid分配,则只需把系统中计分项uid改为你的计分项即可。

该系统为了降低内存占用,全为低频循环激活,即每1s执行一次。代码中cond:意思为该行指令为条件制约。

如何使用:玩家执行/trigger triPro set 1即可触发响应,可将代码加入至你服务器中书之类的功能性物品中。



代码

初始化:

  1. /scoreboard objectives add triPro trigger
  2. /scoreboard objectives add tpto trigger
  3. /scoreboard objectives add g_TTTemp trigger
  4. /scoreboard objectives add tpapply trigger
  5. /scoreboard objectives add tptimer dummy

UID分配 [建议高频]:

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

触发响应:

  1. scoreboard players add @a triPro 0
  2. scoreboard players enable @a[score_triPro_min=0,score_triPro=0] triPro
  3. execute @a[score_triPro_min=1,score_triPro=1] ~ ~ ~ /execute @a ~ ~ ~ tellraw @a[score_triPro_min=1,score_triPro=1] ["➤ \u00a7a玩家名字: ",{"selector":"@s","color":"white","bold":"true"}," \u00a7e玩家UID: ",{"score":{"name":"@s","objective":"uid"},"color":"white","bold":"true"}]
  4. tellraw @a[score_triPro_min=1,score_triPro=1] ["\n\u00a76\u00a7l[传送系统] \u00a7c\u00a7l请输入\u00a7e\u00a7l /trigger tpto set UID \u00a7c\u00a7l选择要邀请的玩家,玩家UID已在上方给出。\n",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger tpto set "}}]
  5. scoreboard players enable @a[score_triPro_min=1,score_triPro=1] tpto
  6. scoreboard players set @a[score_triPro_min=1] triPro 0

处理:

  1. testfor @a[score_tpto_min=1,tag=tping]
  2. cond:tellraw @a[score_tpto_min=1,tag=!tping] ["\u00a76\u00a7l[传送系统] \u00a7e当前系统被占线中,请稍后再试。 当前使用玩家: ",{"selector":"@s"}]
  3. cond:scoreboard players reset @a[score_tpto_min=1,tag=!tping] tpto
  4. scoreboard players tag @a[score_tpto_min=1] add tping
  5. execute @a[score_tpto_min=1] ~ ~ ~ scoreboard players reset @a g_TTTemp
  6. execute @a[score_tpto_min=1] ~ ~ ~ scoreboard players operation @a[rm=0] g_TTTemp = @s tpto
  7. execute @p[score_tpto_min=1,tag=tping] ~ ~ ~ execute @a[rm=0] ~ ~ ~ scoreboard players operation @s g_TTTemp -= @s uid
  8. scoreboard players test @a[tag=!tping] g_TTTemp 0 0
  9. cond:scoreboard players tag @p[score_tpto_min=1,tag=tping] add tptoY
  10. cond:scoreboard players tag @p[score_tpto_min=1,tag=tping] add g_tpto_a
  11. cond:scoreboard players tag @p[score_g_TTTemp_min=0,score_g_TTTemp=0] add g_tpto_b
  12. tellraw @a[score_tpto_min=1,tag=tptoY] ["\u00a76\u00a7l[传送系统] \u00a7e传送邀请已发送至: ",{"selector":"@p[tag=g_tpto_b]"}," \u00a7e请等待对方同意。"]
  13. scoreboard players enable @a[tag=g_tpto_b] tpapply
  14. execute @a[score_tpto_min=1,tag=tptoY] ~ ~ ~ tellraw @a[tag=g_tpto_b] ["\u00a76\u00a7l[传送系统] ",{"selector":"@p[tag=g_tpto_a]"}," \u00a7e邀请您前往他那里。\n",{"text":" [同意邀请]","color":"green","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger tpapply set 1"}},{"text":" [拒绝邀请]","color":"red","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger tpapply set 2"}}]
  15. tellraw @a[score_tpto_min=1,tag=!tptoY] ["\u00a76\u00a7l[传送系统] \u00a7e未知玩家!请重新输入玩家UID。",{"text":" [点击此处自动补全]","color":"aqua","bold":"true","clickEvent":{"action":"suggest_command","value":"/trigger tpto set "}}]
  16. scoreboard players enable @a[score_tpto_min=1,tag=!tptoY] tpto
  17. scoreboard players tag @a[score_tpto_min=1,tag=!tptoY] remove tping
  18. scoreboard players tag @a[score_tpto_min=1] remove tptoY
  19. scoreboard players reset @a[score_tpto_min=1] tptimer
  20. scoreboard players reset @a[score_tpto_min=1] tpto
  21. //玩家拒绝
  22. testfor @a[tag=g_tpto_b,score_tpapply_min=2,score_tpapply=2]
  23. cond:tellraw @a[tag=g_tpto_b] ["\u00a76\u00a7l[传送系统] \u00a7c您拒绝了来自 ",{"selector":"@p[tag=g_tpto_a]"}," \u00a7c的传送邀请。"]
  24. cond:tellraw @a[tag=g_tpto_a] ["\u00a76\u00a7l[传送系统] \u00a7c玩家 ",{"selector":"@p[tag=g_tpto_b]"}," \u00a74\u00a7l拒绝了\u00a7c您的传送邀请。"]
  25. cond:scoreboard players tag @a[tag=g_tpto_a] remove tping
  26. cond:scoreboard players tag @a[tag=g_tpto_a] remove g_tpto_a
  27. cond:scoreboard players tag @a[tag=g_tpto_b] remove g_tpto_b
  28. cond:scoreboard players reset @a[score_tpapply_min=2] tpapply
  29. //玩家同意
  30. testfor @a[tag=g_tpto_b,score_tpapply_min=1,score_tpapply=1]
  31. cond:tellraw @a[tag=g_tpto_a] ["\u00a76\u00a7l[传送系统] \u00a7a玩家 ",{"selector":"@p[tag=g_tpto_b]"}," \u00a7a\u00a7l同意了\u00a7a您的传送邀请。"]
  32. cond:tp @a[tag=g_tpto_b] @a[tag=g_tpto_a]
  33. cond:scoreboard players tag @a[tag=g_tpto_a] remove tping
  34. cond:scoreboard players tag @a[tag=g_tpto_a] remove g_tpto_a
  35. cond:scoreboard players tag @a[tag=g_tpto_b] remove g_tpto_b
  36. cond:scoreboard players reset @a[score_tpapply_min=1] tpapply
  37. //超时处理
  38. scoreboard players add @a[tag=g_tpto_a] tptimer 1
  39. execute @a[tag=g_tpto_a,score_tptimer_min=15] ~ ~ ~ execute @p[tag=g_tpto_b] ~ ~ ~ trigger tpapply set 2
  40. scoreboard players reset @a[score_tptimer_min=15] tptimer

未经作者授权,禁止转载





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