Advertisement
Bolodefchoco_LUAXML

[Function] settings.editFile

Jul 10th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 10/07/2016
  3. --Last update: 10/07/2016
  4. --[[ Notes:
  5.     Does:
  6.         Gerencia melhor a memória do seu sistema. Funciona apenas para developers.
  7.     Args:
  8.         value --> Valor onde deve ser salvo. Caso seja o nickname de alguém, a função usará savePlayerData, caso seja um número, usará saveFile.
  9.         format --> Utiliza algumas formas de formatação do texto.
  10.             *w / *w+ / *r+ --> Salvam em cima.
  11.             *a --> Adiciona algo no início sem salvar em cima.
  12.             *a+ --> Adiciona algo no final sem salvar em cima.
  13. ]]--
  14.  
  15. settings = system.saveFile
  16. system.saveFile = function(int,data)
  17.     settings(data,int)
  18. end
  19.  
  20. settings = {}
  21. files = setmetatable({},{__index=function() return "" end})
  22. playerFiles = setmetatable({},{__index=function() return "" end})
  23. timers = setmetatable({},{__index=function() return 0 end})
  24.  
  25. timers.editFile = 0
  26.  
  27. settings.editFile = function(value,format,data)
  28.     local func = (type(value)=="string" and {"savePlayerData","loadPlayerData",playerFiles} or {"saveFile","loadFile",files})
  29.     if func[1]=="saveFile" then
  30.         value = tonumber(value)
  31.         assert(value>=0 and value<=100,"[editFile] <i>value</i> must be a number between 0-99.")
  32.     else
  33.         assert(tfm.get.room.playerList[value],"[editFile] The player <i>"..value.."</i> is not here.")
  34.     end
  35.     assert(data,"[editFile] <i>data</i> must have a value.")
  36.     if os.time() > timers.editFile then
  37.         system.removeTimer(timers.newTimerEditFile)
  38.         timers.editFile = os.time() + (func[1]=="saveFile" and 62000 or 500)
  39.         format = format:match("%**(.*)")
  40.         if format:find("^w%+*") or format=="r+" then
  41.             system[func[1]](value,data)
  42.         elseif format:find("^a") then
  43.             system[func[2]](value)
  44.             local file = func[3][value]
  45.             system[func[1]](value,(format=="a" and data..file or format=="a+" file..data))
  46.         else
  47.             error("[editFile] Wrong <i>format</i>. (w,w+,r+,a,a+)")
  48.         end
  49.     else
  50.         timers.newTimerEditFile = system.newTimer(settings.editFile(value,format,data),1000,true)
  51.     end
  52. end
  53.  
  54. eventFileLoaded=function(id,file)
  55.     files[id] = file
  56. end
  57. eventPlayerDataLoaded=function(n,data)
  58.     playerFiles[n] = data
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement