Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. local function GetMaps()
  2. return util.JSONToTable( file.Read( "mapvote/maps.txt", "DATA" ) )
  3. end
  4.  
  5. local function SaveMaps( maps )
  6. file.Write("mapvote/maps.txt", util.TableToJSON( maps ) )
  7. end
  8.  
  9.  
  10.  
  11. local function GetLegacy()
  12. return util.JSONToTable( file.Read( "mapvote/legacy.txt", "DATA" ) )
  13. end
  14.  
  15. local function SaveLegacy( maps )
  16. file.Write( "mapvote/legacy.txt", util.TableToJSON( maps ) )
  17. end
  18.  
  19. local function GetExisting()
  20.  
  21. for _, map in ipairs( file.Find( "maps/*.bsp", "GAME" ) ) do
  22.  
  23. existing[map] = true --convert table to be indexed by map name.
  24.  
  25. end
  26.  
  27. end
  28.  
  29. local function NewMap()
  30.  
  31. return
  32. {
  33. PlayCount = 0,
  34. --all data in a new map goes here
  35. }
  36.  
  37. end
  38.  
  39. if not file.Exists( "maptvote/maps.txt", "DATA" ) then
  40.  
  41. local maps = {}
  42. for _, map in ipairs( file.Find("maps/*.bsp", "GAME") ) do
  43.  
  44. maps[map] = NewMap()
  45.  
  46. end
  47.  
  48. SaveMaps( maps )
  49.  
  50. end
  51.  
  52. local saved = GetMaps()
  53. local legacy = GetLegacy()
  54. local existing = GetExisting()
  55.  
  56. for map, data in pairs( saved ) do --get maps that are in the list but not on the server
  57.  
  58. if not existing[map] then
  59.  
  60. legacy[map] = data
  61. saved[map] = nil
  62.  
  63. end
  64.  
  65. end
  66.  
  67. SaveLegacy( legacy )
  68.  
  69. for map in pairs( existing ) do --get maps on the server
  70.  
  71. if not saved[map] then
  72.  
  73. saved[map] = NewMap()
  74.  
  75. end
  76.  
  77. end
  78.  
  79. SaveMaps( saved )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement