GhostXoP Posted December 7, 2012 Share Posted December 7, 2012 This is a Server Side Script A couple days ago i had posted about how i went to json a string, and it had turned out to only partially save using setAccountData because of the limits that MTA has set. I have a temporary fix (it works, for what it does) that fragments your long string, and saves it, and can reopen it. You can now save giant arrays to users accounts. This brings me back to the days when i had written a FAT file system driver (In assembler..), with end of file markers in the fat entries. FRAGMENTS ARE NOT DELETED! THEY ARE REUSED function SaveAccountData(Account, Array, Key) -- Player Account, Array to be saved, Key string to be saved under --turn it into string local ArrayString = toJSON(Array) --get its length local ArrayStringLen = string.len(ArrayString) local BlockNum = 1 local StrPos = 1 local StrEnd = 0 while ArrayStringLen ~= 0 do if ArrayStringLen < 64 then -- this is the last --pos = endd POS ALREADY SET StrEnd = StrEnd + ArrayStringLen ArrayStringLen = 0 setAccountData(Account, Key..tostring(BlockNum), string.sub(ArrayString,StrPos,StrEnd).."|\END/|") -- len -6 gets string (removing tag) break end StrEnd = StrEnd + 64 setAccountData(Account,Key..tostring(BlockNum), string.sub(ArrayString,StrPos,StrEnd)) StrPos = StrEnd+1 BlockNum = BlockNum + 1 ArrayStringLen = ArrayStringLen - 64 end end --done --Returns giant array function RetrieveAccountData(Account,Key) --Account, Key string it was saved under local ArrayString = "" local BlockNum = 1 while 1 == 1 do ArrayString = ArrayString..getAccountData(Account, Key..tostring(BlockNum)) --do we have the end of string tag? if so remove dat b and gtfo if string.sub(ArrayString,string.len(ArrayString)-5,string.len(ArrayString)) == "|\END/|" then ArrayString = string.sub(ArrayString,1,string.len(ArrayString)-6) break end BlockNum = BlockNum + 1 end return fromJSON(ArrayString) end I don't really care what you do with it, call it your own whatever. Its only a couple lines of code Hope this solves problems! I had to write it mainly because it was this, or i throw away my little 6kloc brief case resource, and i really didn't want to redo it.. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now