init.lua 765 B

123456789101112131415161718192021222324252627
  1. minetest.register_chatcommand("killme", {
  2. description = "Kill yourself to respawn",
  3. func = function(name)
  4. local player = minetest.get_player_by_name(name)
  5. local pos = vector.round(player:getpos())
  6. if player then
  7. if minetest.settings:get_bool("enable_damage") then
  8. player:set_hp(0)
  9. lightning.strike(pos)
  10. return true
  11. else
  12. for _, callback in pairs(core.registered_on_respawnplayers) do
  13. if callback(player) then
  14. return true
  15. end
  16. end
  17. -- There doesn't seem to be a way to get a default spawn pos from the lua API
  18. return false, "No static_spawnpoint defined"
  19. end
  20. else
  21. -- Show error message if used when not logged in, eg: from IRC mod
  22. return false, "You need to be online to be killed!"
  23. end
  24. end
  25. })