Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Bolodefchoco
- --Made in: 10/07/2016
- --Last update: 10/07/2016
- --[[ Notes:
- Does:
- Gerencia melhor a memória do seu sistema. Funciona apenas para developers.
- Args:
- 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.
- format --> Utiliza algumas formas de formatação do texto.
- *w / *w+ / *r+ --> Salvam em cima.
- *a --> Adiciona algo no início sem salvar em cima.
- *a+ --> Adiciona algo no final sem salvar em cima.
- ]]--
- settings = system.saveFile
- system.saveFile = function(int,data)
- settings(data,int)
- end
- settings = {}
- files = setmetatable({},{__index=function() return "" end})
- playerFiles = setmetatable({},{__index=function() return "" end})
- timers = setmetatable({},{__index=function() return 0 end})
- timers.editFile = 0
- settings.editFile = function(value,format,data)
- local func = (type(value)=="string" and {"savePlayerData","loadPlayerData",playerFiles} or {"saveFile","loadFile",files})
- if func[1]=="saveFile" then
- value = tonumber(value)
- assert(value>=0 and value<=100,"[editFile] <i>value</i> must be a number between 0-99.")
- else
- assert(tfm.get.room.playerList[value],"[editFile] The player <i>"..value.."</i> is not here.")
- end
- assert(data,"[editFile] <i>data</i> must have a value.")
- if os.time() > timers.editFile then
- system.removeTimer(timers.newTimerEditFile)
- timers.editFile = os.time() + (func[1]=="saveFile" and 62000 or 500)
- format = format:match("%**(.*)")
- if format:find("^w%+*") or format=="r+" then
- system[func[1]](value,data)
- elseif format:find("^a") then
- system[func[2]](value)
- local file = func[3][value]
- system[func[1]](value,(format=="a" and data..file or format=="a+" file..data))
- else
- error("[editFile] Wrong <i>format</i>. (w,w+,r+,a,a+)")
- end
- else
- timers.newTimerEditFile = system.newTimer(settings.editFile(value,format,data),1000,true)
- end
- end
- eventFileLoaded=function(id,file)
- files[id] = file
- end
- eventPlayerDataLoaded=function(n,data)
- playerFiles[n] = data
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement