attachment.lua 640 B

12345678910111213141516171819202122232425262728
  1. local invmap = {}
  2. mail.getAttachmentInventory = function(playername)
  3. return invmap[playername]
  4. end
  5. mail.getAttachmentInventoryName = function(playername)
  6. return "mail:" .. playername
  7. end
  8. minetest.register_on_joinplayer(function(player)
  9. local name = player:get_player_name()
  10. local inv = minetest.create_detached_inventory(mail.getAttachmentInventoryName(name), {})
  11. invmap[name] = inv
  12. end)
  13. minetest.register_on_leaveplayer(function(player)
  14. local name = player:get_player_name()
  15. invmap[name] = nil
  16. if minetest.remove_detached_inventory then
  17. minetest.remove_detached_inventory(mail.getAttachmentInventoryName(name))
  18. end
  19. end)