init.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. hb4 = hb4 or {}
  2. hb4.modpath = minetest.get_modpath("hb4")
  3. -- Localize for performance.
  4. local math_random = math.random
  5. local math_max = math.max
  6. dofile(hb4.modpath .. "/leafscatter.lua")
  7. dofile(hb4.modpath .. "/fruitregrow.lua")
  8. dofile(hb4.modpath .. "/floodfill.lua")
  9. dofile(hb4.modpath .. "/breath.lua")
  10. dofile(hb4.modpath .. "/notify.lua")
  11. dofile(hb4.modpath .. "/mailall.lua")
  12. dofile(hb4.modpath .. "/spawn_sanitizer.lua")
  13. dofile(hb4.modpath .. "/nodeinspector.lua")
  14. dofile(hb4.modpath .. "/diving_equipment.lua")
  15. -- Server restart countdown not active in singleplayer.
  16. if not minetest.is_singleplayer() then
  17. dofile(hb4.modpath .. "/countdown.lua")
  18. end
  19. --[[
  20. {name="player", step=2, min=1, max=3, msg="He died!", poison=false}
  21. --]]
  22. function hb4.delayed_harm2(data)
  23. local player = minetest.get_player_by_name(data.name)
  24. if player then
  25. -- finished harming?
  26. if data.step < 1 then
  27. if data.poison then
  28. hud.change_item(player, "hunger", {text="hud_hunger_fg.png"})
  29. end
  30. -- Execute termination callback.
  31. if data.done then
  32. data.done()
  33. end
  34. return
  35. end
  36. if data.poison then
  37. hud.change_item(player, "hunger", {text="hunger_statbar_poisen.png"})
  38. end
  39. local damage = math_random(data.min, data.max)
  40. local hp = player:get_hp()
  41. if hp > (data.hp_min or 0) then
  42. local new_hp = hp - damage
  43. new_hp = math_max(new_hp, (data.hp_min or 0))
  44. player:set_hp(new_hp)
  45. end
  46. -- Message is printed only if player died. Return if we killed them.
  47. if player:get_hp() <= 0 then
  48. if data.poison then
  49. hud.change_item(player, "hunger", {text="hud_hunger_fg.png"})
  50. end
  51. -- Execute termination callback.
  52. if data.done then
  53. data.done()
  54. end
  55. if data.msg then
  56. minetest.chat_send_all(data.msg)
  57. end
  58. return
  59. end
  60. data.step = data.step - 1
  61. local time = (data.time or 1)
  62. minetest.after(time, hb4.delayed_harm2, data)
  63. else
  64. -- Player logged off. Wait until they come back.
  65. -- Player cannot escape harm!
  66. minetest.after(10, hb4.delayed_harm2, data)
  67. end
  68. end
  69. function hb4.delayed_harm(data)
  70. minetest.after(0, hb4.delayed_harm2, data)
  71. end
  72. if not hb4.reload_registered then
  73. local c = "hb4:core"
  74. local f = hb4.modpath .. "/init.lua"
  75. reload.register_file(c, f, false)
  76. hb4.reload_registered = true
  77. end