init.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. -- already dead?
  37. if player:get_hp() <= 0 then
  38. if data.poison then
  39. hud.change_item(player, "hunger", {text="hud_hunger_fg.png"})
  40. end
  41. -- Execute termination callback.
  42. if data.done then
  43. data.done()
  44. end
  45. return
  46. end
  47. if data.poison then
  48. hud.change_item(player, "hunger", {text="hunger_statbar_poisen.png"})
  49. end
  50. local damage = math_random(data.min, data.max)
  51. local hp = player:get_hp()
  52. if hp > (data.hp_min or 0) then
  53. local new_hp = hp - damage
  54. new_hp = math_max(new_hp, (data.hp_min or 0))
  55. player:set_hp(new_hp)
  56. end
  57. -- Message is printed only if player died.
  58. if data.msg and player:get_hp() <= 0 then
  59. minetest.chat_send_all(data.msg)
  60. end
  61. data.step = data.step - 1
  62. local time = (data.time or 1)
  63. minetest.after(time, hb4.delayed_harm2, data)
  64. else
  65. -- Player logged off. Wait until they come back.
  66. -- Player cannot escape harm!
  67. minetest.after(10, hb4.delayed_harm2, data)
  68. end
  69. end
  70. function hb4.delayed_harm(data)
  71. minetest.after(0, hb4.delayed_harm2, data)
  72. end
  73. if not hb4.reload_registered then
  74. local c = "hb4:core"
  75. local f = hb4.modpath .. "/init.lua"
  76. reload.register_file(c, f, false)
  77. hb4.reload_registered = true
  78. end