huds.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. function sabotage.show_hud_timed(map_id, timer, desc)
  2. for _, player in pairs(minetest.get_connected_players()) do
  3. local name = player:get_player_name()
  4. local id = lobby.game[name]
  5. if id == map_id or id == map_id..'_ghost' then
  6. sabotage.hud[name] = {
  7. desc = player:hud_add({
  8. hud_elem_type = 'text',
  9. position = {x = 1, y = 0.125},
  10. offset = {x = -20, y = -20},
  11. text = 'Find '..desc,
  12. alignment = {x = -1, y = 0},
  13. scale = {x = 100, y = 100},
  14. }),
  15. title = player:hud_add({
  16. hud_elem_type = 'text',
  17. position = {x = 1, y = 0.125},
  18. offset = {x = -20, y = 0},
  19. text = 'Time until sabotage ends:',
  20. alignment = {x = -1, y = 0},
  21. scale = {x = 100, y = 100},
  22. }),
  23. timer = player:hud_add({
  24. hud_elem_type = 'text',
  25. position = {x = 1, y = 0.125},
  26. offset = {x = -60, y = 20},
  27. text = timer..' seconds',
  28. alignment = {x = -1, y = 0},
  29. scale = {x = 100, y = 100},
  30. })
  31. }
  32. end
  33. end
  34. minetest.after(1, function()
  35. sabotage.update_hud(map_id)
  36. end)
  37. end
  38. function sabotage.clear_hud(map_id)
  39. for _, player in pairs(minetest.get_connected_players()) do
  40. local name = player:get_player_name()
  41. local id = lobby.game[name]
  42. if id == map_id or id == map_id..'_ghost' then
  43. local idx = sabotage.hud[name]
  44. for key,value in pairs(idx) do
  45. player:hud_remove(value)
  46. end
  47. end
  48. end
  49. end
  50. function sabotage.update_hud(map_id)
  51. local time = sabotage.timer[map_id] - 1
  52. if time < 0 then
  53. sabotage.clear_hud(map_id)
  54. sabotage.finish(map_id)
  55. return
  56. end
  57. sabotage.timer[map_id] = time
  58. for _, player in pairs(minetest.get_connected_players()) do
  59. local name = player:get_player_name()
  60. local id = lobby.game[name]
  61. if id == map_id or id == map_id..'_ghost' then
  62. local idx = sabotage.hud[name]
  63. player:hud_change(idx.timer, 'text', time..' seconds')
  64. end
  65. end
  66. minetest.after(1, function()
  67. sabotage.update_hud(map_id)
  68. end)
  69. end
  70. function sabotage.show_hud(map_id, desc)
  71. for _, player in pairs(minetest.get_connected_players()) do
  72. local name = player:get_player_name()
  73. local id = lobby.game[name]
  74. if id == map_id or id == map_id..'_ghost' then
  75. sabotage.hud[name] = {
  76. desc = player:hud_add({
  77. hud_elem_type = 'text',
  78. position = {x = 1, y = 0.125},
  79. offset = {x = -20, y = -20},
  80. text = 'Find '..desc,
  81. alignment = {x = -1, y = 0},
  82. scale = {x = 100, y = 100},
  83. }),
  84. title = player:hud_add({
  85. hud_elem_type = 'text',
  86. position = {x = 1, y = 0.125},
  87. offset = {x = -20, y = 0},
  88. text = 'Items still require repairs!!!',
  89. alignment = {x = -1, y = 0},
  90. scale = {x = 100, y = 100},
  91. }),
  92. }
  93. end
  94. end
  95. end