static_spawn.lua 809 B

12345678910111213141516171819202122232425
  1. -- Minetest: builtin/static_spawn.lua
  2. local function warn_invalid_static_spawnpoint()
  3. if core.setting_get("static_spawnpoint") and
  4. not core.setting_get_pos("static_spawnpoint") then
  5. core.log("error", "The static_spawnpoint setting is invalid: \""..
  6. core.setting_get("static_spawnpoint").."\"")
  7. end
  8. end
  9. warn_invalid_static_spawnpoint()
  10. local function put_player_in_spawn(player_obj)
  11. local static_spawnpoint = core.setting_get_pos("static_spawnpoint")
  12. if not static_spawnpoint then
  13. return false
  14. end
  15. core.log("action", "Moving " .. player_obj:get_player_name() ..
  16. " to static spawnpoint at " .. core.pos_to_string(static_spawnpoint))
  17. player_obj:setpos(static_spawnpoint)
  18. return true
  19. end
  20. core.register_on_newplayer(put_player_in_spawn)
  21. core.register_on_respawnplayer(put_player_in_spawn)