init.lua 2.0 KB

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