Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function GetMaps()
- return util.JSONToTable( file.Read( "mapvote/maps.txt", "DATA" ) )
- end
- local function SaveMaps( maps )
- file.Write("mapvote/maps.txt", util.TableToJSON( maps ) )
- end
- local function GetLegacy()
- return util.JSONToTable( file.Read( "mapvote/legacy.txt", "DATA" ) )
- end
- local function SaveLegacy( maps )
- file.Write( "mapvote/legacy.txt", util.TableToJSON( maps ) )
- end
- local function GetExisting()
- for _, map in ipairs( file.Find( "maps/*.bsp", "GAME" ) ) do
- existing[map] = true --convert table to be indexed by map name.
- end
- end
- local function NewMap()
- return
- {
- PlayCount = 0,
- --all data in a new map goes here
- }
- end
- if not file.Exists( "maptvote/maps.txt", "DATA" ) then
- local maps = {}
- for _, map in ipairs( file.Find("maps/*.bsp", "GAME") ) do
- maps[map] = NewMap()
- end
- SaveMaps( maps )
- end
- local saved = GetMaps()
- local legacy = GetLegacy()
- local existing = GetExisting()
- for map, data in pairs( saved ) do --get maps that are in the list but not on the server
- if not existing[map] then
- legacy[map] = data
- saved[map] = nil
- end
- end
- SaveLegacy( legacy )
- for map in pairs( existing ) do --get maps on the server
- if not saved[map] then
- saved[map] = NewMap()
- end
- end
- SaveMaps( saved )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement