init.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. heal = heal or {}
  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. player:set_hp(player:get_properties().hp_max)
  12. hunger.update_hunger(player, 30)
  13. sprint.set_stamina(player, SPRINT_STAMINA)
  14. portal_sickness.reset(pname)
  15. end
  16. minetest.register_chatcommand("heal", {
  17. params = "[playername]",
  18. description = "Heal specified player, or heal self if called without arguments.",
  19. privs = {heal=true},
  20. func = function(name, param)
  21. if param == nil or param == "" then
  22. minetest.chat_send_player(name, "# Server: Healing player <" .. rename.gpn(name) .. ">.")
  23. heal.heal_health_and_hunger(name)
  24. return true
  25. end
  26. assert(type(param) == "string")
  27. local player = minetest.get_player_by_name(param)
  28. if not player then
  29. minetest.chat_send_player(name, "# Server: Player <" .. rename.gpn(param) .. "> not found.")
  30. return false
  31. end
  32. minetest.chat_send_player(name, "# Server: Healing player <" .. rename.gpn(param) .. ">.")
  33. minetest.chat_send_player(param, "# Server: Player <" .. rename.gpn(name) .. "> healed you.")
  34. heal.heal_health_and_hunger(param)
  35. return true
  36. end
  37. })