static_spawn.lua 915 B

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