static_spawn.lua 879 B

123456789101112131415161718192021222324252627282930313233
  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(obj)
  11. warn_invalid_static_spawnpoint()
  12. local static_spawnpoint = core.setting_get_pos("static_spawnpoint")
  13. if not static_spawnpoint then
  14. return false
  15. end
  16. core.log('action', "Moving "..obj:get_player_name()..
  17. " to static spawnpoint at "..
  18. core.pos_to_string(static_spawnpoint))
  19. obj:setpos(static_spawnpoint)
  20. return true
  21. end
  22. core.register_on_newplayer(function(obj)
  23. put_player_in_spawn(obj)
  24. end)
  25. core.register_on_respawnplayer(function(obj)
  26. return put_player_in_spawn(obj)
  27. end)