Advertisement
Guest User

MTA:SA Maploading

a guest
Jul 30th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. sMaps = {}
  2. sMaps.__index = sMaps
  3. sMaps.mapTable = {}
  4.  
  5. function sortCompareFunction(s1, s2)
  6.     if type(s1) == "table" and type(s2) == "table" then
  7.         s1, s2 = s1.name, s2.name
  8.     end
  9.     s1, s2 = s1:lower(), s2:lower()
  10.     if s1 == s2 then
  11.         return false
  12.     end
  13.     local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1))
  14.     if not byte1 then
  15.         return true
  16.     elseif not byte2 then
  17.         return false
  18.     elseif byte1 < byte2 then
  19.         return true
  20.     elseif byte1 == byte2 then
  21.         return sortCompareFunction(s1:sub(2), s2:sub(2))
  22.     else
  23.         return false
  24.     end
  25. end
  26.  
  27. function sMaps:load()
  28.     for i, k in ipairs(getResources()) do
  29.         if getResourceInfo(k,"type") == "map" and getResourceInfo(k,"gamemodes") == "race" then
  30.             table.insert(sMaps.mapTable,{mapName = getResourceName(k), mapAuthor = getResourceInfo(k,"author") or "Unknown", uploadTime = getResourceLoadTime(k) or "00.00.0000"})
  31.         end
  32.     end
  33.     outputDebugString(#sMaps.mapTable.." Maps wurden geladen!")
  34.     table.sort(sMaps.mapTable, sortCompareFunction)
  35. end
  36.  
  37. addEvent("sMaps:getList")
  38. addEventHandler("sMaps:getList", root, function()
  39.     triggerClientEvent(source,"event",root,sMasp.mapTable)
  40. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement