init.lua 908 B

12345678910111213141516171819202122232425262728
  1. maxhp = {}
  2. maxhp.storage = minetest.get_mod_storage()
  3. dofile(minetest.get_modpath('maxhp')..'/functions.lua')
  4. dofile(minetest.get_modpath('maxhp')..'/food.lua')
  5. dofile(minetest.get_modpath('maxhp')..'/potions.lua')
  6. minetest.register_on_joinplayer(function(player)
  7. local name = player:get_player_name()
  8. local max_hp = tonumber(maxhp.storage:get_string(name..'_max_hp'))
  9. if max_hp == nil then
  10. maxhp.storage:set_string(name..'_max_hp', 40)
  11. player:set_properties({hp_max = 40})
  12. else
  13. player:set_properties({hp_max = max_hp})
  14. end
  15. end)
  16. minetest.register_on_dieplayer(function(player)
  17. local name = player:get_player_name()
  18. local max_hp = tonumber(maxhp.storage:get_string(name..'_max_hp'))
  19. local new_max_hp = max_hp - 1
  20. if new_max_hp >= 25 then
  21. player:set_properties({hp_max = new_max_hp})
  22. maxhp.storage:set_string(name..'_max_hp', new_max_hp)
  23. end
  24. end)