abm.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. statistic_awards.globaltimer=tonumber(minetest.settings:get("statistic_awards.globaltime")) or 1
  2. minetest.register_globalstep(function(dtime)
  3. statistic_awards.globaltimer=statistic_awards.globaltimer+dtime
  4. if statistic_awards.globaltimer > 1 then
  5. statistic_awards.globaltimer = 0
  6. local players = minetest.get_connected_players()
  7. for i=1, #players do
  8. local player=players[i]
  9. local player_awards=awards.player(player:get_player_name())
  10. local player_walked=xpfw.player_get_attribute(player,"walked")
  11. local hike_award=statistic_awards.hiking[1]
  12. if player_walked ~= nil then
  13. if player_walked > 0 then
  14. local hike_i=1
  15. local bhike = true
  16. local aw_def=statistic_awards.hiking[hike_i]
  17. while bhike do
  18. local aw_def=statistic_awards.hiking[hike_i]
  19. if aw_def ~= nil then
  20. if basic_functions.has_value(player_awards.unlocked,aw_def.basename..aw_def.level) == false then
  21. bhike=false
  22. hike_award=aw_def
  23. end
  24. else
  25. bhike = false
  26. end
  27. hike_i=hike_i+1
  28. end
  29. if aw_def ~= nil then
  30. if aw_def.threshold<player_walked then
  31. awards.unlock(player:get_player_name(),aw_def.basename..aw_def.level)
  32. end
  33. end
  34. end
  35. end
  36. local player_swam=xpfw.player_get_attribute(player,"swam")
  37. local swam_award=statistic_awards.swimming[1]
  38. if player_swam ~= nil then
  39. if player_swam > 0 then
  40. local swim_i=1
  41. local bswim = true
  42. local aw_def=statistic_awards.swimming[swim_i]
  43. while bswim do
  44. local aw_def=statistic_awards.swimming[swim_i]
  45. if aw_def ~= nil then
  46. if basic_functions.has_value(player_awards.unlocked,aw_def.basename..aw_def.level) == false then
  47. bswim=false
  48. swam_award=aw_def
  49. end
  50. else
  51. bswim = false
  52. end
  53. swim_i=swim_i+1
  54. end
  55. if aw_def ~= nil then
  56. if aw_def.threshold<player_swam then
  57. awards.unlock(player:get_player_name(),aw_def.basename..aw_def.level)
  58. end
  59. end
  60. end
  61. end
  62. end
  63. end
  64. end)
  65. minetest.register_on_respawnplayer(function(player)
  66. if player ~= nil then
  67. if xpfw.player_get_attribute(player,"deaths") > 0 then
  68. local player_awards=awards.player(player:get_player_name())
  69. print(dump2(player_awards))
  70. local death_award=statistic_awards.deaths[1]
  71. local death_i=1
  72. local bdeath = true
  73. local aw_def=statistic_awards.deaths[death_i]
  74. while bdeath do
  75. local aw_def=statistic_awards.deaths[death_i]
  76. if aw_def ~= nil then
  77. if basic_functions.has_value(player_awards.unlocked,aw_def.basename..aw_def.level) == false then
  78. bdeath=false
  79. death_award=aw_def
  80. end
  81. else
  82. bdeath = false
  83. end
  84. death_i=death_i+1
  85. end
  86. if aw_def ~= nil then
  87. if aw_def.threshold<xpfw.player_get_attribute(player,"deaths") then
  88. print(player:get_player_name())
  89. print(dump2(aw_def))
  90. awards.unlock(player:get_player_name(),aw_def.basename..aw_def.level)
  91. end
  92. end
  93. end
  94. end
  95. end
  96. )