rebuild.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. function serveressentials.check_outback_reset()
  2. local meta = serveressentials.modstorage
  3. local stime = meta:get_string("outback_reset_time")
  4. -- If timestamp is missing, then initialize it to the current time.
  5. -- Outback reset will be schedualed after the timeout.
  6. if not stime or stime == "" then
  7. stime = tostring(os.time())
  8. meta:set_string("outback_reset_time", stime)
  9. -- Note: we reach here only when a new world is first started.
  10. serveressentials.rebuild_outback()
  11. return
  12. end
  13. local time = tonumber(stime) -- Time of last reset (or initialization).
  14. local days = serveressentials.reset_timeout -- Timeout in days.
  15. local timeout = 60 * 60 * 24 * days
  16. local now = os.time() -- Current time.
  17. local later = time + timeout -- Time of next reset.
  18. if now >= later then
  19. stime = tostring(later)
  20. meta:set_string("outback_reset_time", stime)
  21. serveressentials.rebuild_outback()
  22. minetest.chat_send_all("# Server: The desert wind ceases to blow across the Outback.")
  23. minetest.chat_send_all("# Server: When it resumes, there is nothing left of what went before.")
  24. end
  25. end
  26. minetest.after(0, function() serveressentials.check_outback_reset() end)