init.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. if not minetest.global_exists("heal") then heal = {} end
  2. heal.modpath = minetest.get_modpath("heal")
  3. minetest.register_privilege("heal", {
  4. description = "Player can heal other players or themselves.",
  5. give_to_singleplayer = false,
  6. })
  7. -- API function, can be called by other mods.
  8. function heal.heal_health_and_hunger(pname)
  9. local player = minetest.get_player_by_name(pname)
  10. if not player then return end
  11. local was_dead = false
  12. if player:get_hp() == 0 then
  13. was_dead = true
  14. end
  15. local hp_max = pova.get_active_modifier(player, "properties").hp_max
  16. player:set_hp(hp_max, {reason="heal_command"})
  17. hunger.update_hunger(player, 30)
  18. sprint.set_stamina(player, SPRINT_STAMINA)
  19. portal_sickness.reset(pname)
  20. if was_dead then
  21. minetest.close_formspec(pname, "")
  22. end
  23. end
  24. minetest.register_chatcommand("heal", {
  25. params = "[playername]",
  26. description = "Heal specified player, or heal self if called without arguments.",
  27. privs = {heal=true},
  28. func = function(name, param)
  29. if param == nil or param == "" then
  30. minetest.chat_send_player(name, "# Server: Healing player <" .. rename.gpn(name) .. ">.")
  31. heal.heal_health_and_hunger(name)
  32. return true
  33. end
  34. assert(type(param) == "string")
  35. local player = minetest.get_player_by_name(param)
  36. if not player then
  37. minetest.chat_send_player(name, "# Server: Player <" .. rename.gpn(param) .. "> not found.")
  38. return false
  39. end
  40. minetest.chat_send_player(name, "# Server: Healing player <" .. rename.gpn(param) .. ">.")
  41. minetest.chat_send_player(param, "# Server: Player <" .. rename.gpn(name) .. "> healed you.")
  42. heal.heal_health_and_hunger(param)
  43. return true
  44. end
  45. })