functions.lua 673 B

123456789101112131415161718192021222324252627282930313233
  1. function hud.player_event(player, event)
  2. -- Track player by name. Avoid crash.
  3. local pname = player:get_player_name()
  4. -- Needed for first update called by on_join
  5. minetest.after(0.1, function()
  6. local plr = minetest.get_player_by_name(pname)
  7. if not plr then return end
  8. if event == "health_changed" then
  9. for _,v in pairs(hud.damage_events) do
  10. if v.func then
  11. v.func(plr)
  12. end
  13. end
  14. end
  15. if event == "breath_changed" then
  16. for _,v in pairs(hud.breath_events) do
  17. if v.func then
  18. v.func(plr)
  19. end
  20. end
  21. end
  22. if event == "hud_changed" then --called when flags changed
  23. end
  24. end)
  25. end
  26. core.register_playerevent(hud.player_event)