functions.lua 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. --minetest.log('health_changed_event')
  10. for _,v in pairs(hud.damage_events) do
  11. if v.func then
  12. v.func(plr)
  13. end
  14. end
  15. end
  16. if event == "breath_changed" then
  17. for _,v in pairs(hud.breath_events) do
  18. if v.func then
  19. v.func(plr)
  20. end
  21. end
  22. end
  23. if event == "hud_changed" then --called when flags changed
  24. end
  25. -- Tested, works.
  26. if event == "properties_changed" then
  27. --minetest.log('properties changed!')
  28. end
  29. end)
  30. end
  31. -- 'Da ****? This function isn't documented in MT's Lua API?
  32. core.register_playerevent(hud.player_event)