1
0

on_shutdown.lua 629 B

12345678910111213141516171819202122
  1. -- Test whether players still exist on shutdown
  2. local players = {}
  3. core.register_on_joinplayer(function(player)
  4. players[player:get_player_name()] = true
  5. end)
  6. core.register_on_leaveplayer(function(player)
  7. local name = player:get_player_name();
  8. assert(players[name], "Unrecorded player join.")
  9. players[name] = nil
  10. end)
  11. core.register_on_shutdown(function()
  12. for _, player in pairs(core.get_connected_players()) do
  13. local name = player:get_player_name()
  14. assert(players[name], "Unrecorded player join or left too early.")
  15. players[name] = nil
  16. end
  17. assert(not next(players), "Invalid connected players on shutdown.")
  18. end)