-.Paradox.- Posted September 2, 2014 Posted September 2, 2014 Hey guys, I currently want to save player database using file functions, and for testing i used country as test, and actually it should write a line everytime a player login but actually it just replace it, This is my code. Server: if fileExists(country..".txt") then local file = fileOpen(country..".txt") fileWrite(file, "Name:"..name.." Serial:"..serial) fileClose(file) else local file = fileCreate(country..".txt") fileWrite(file, "Name:"..name.." Serial:"..serial) fileClose(file) end What i'm doing wrong?
ixjf Posted September 2, 2014 Posted September 2, 2014 (edited) Everything. Don't ever do that. Use a database management system. MTA supports the SQLite library and MySQL. But just for the record, you should call fileSetPos to set the position where reads and writes will take place. Edited September 2, 2014 by Guest
-.Paradox.- Posted September 2, 2014 Author Posted September 2, 2014 Everything. Don't ever do that. Use a database management system. MTA supports the SQLite library and MySQL. Okay i won't use that, Would you please tell me what's wrong? Because i'd like to know what's wrong with it...
ixjf Posted September 2, 2014 Posted September 2, 2014 I edited my previous message by the time you posted this, take a look.
-.Paradox.- Posted September 2, 2014 Author Posted September 2, 2014 I dont quietly understand, Should it be like this? local file = fileOpen(country..".txt") fileSetPos(file, 51) fileWrite(file, "Name:"..name.." Serial:"..serial) fileClose(file)
Et-win Posted September 2, 2014 Posted September 2, 2014 local gSize = getFileSize(file) fileSetPos(file, gSize) This will be the last character of the file. You may want to use this to start drawing on a new line: \n
-.Paradox.- Posted September 2, 2014 Author Posted September 2, 2014 local gSize = getFileSize(file) fileSetPos(file, gSize) This will be the last character of the file. You may want to use this to start drawing on a new line: \n fileGetSize(file) * It works, thanks, And there is one thing, How i can make it write a line everyplayer join in? Because currently it output like this Name: Test Serial: 0123456789Name: Test Serial: 0123456789
Et-win Posted September 2, 2014 Posted September 2, 2014 Like I said: \n "lollollol\ntest Outputs: lollollol test
-.Paradox.- Posted September 2, 2014 Author Posted September 2, 2014 Like I said: \n "lollollol\ntest Outputs: lollollol test oh lol, sorry i thought that is a kind of smileys
vx89 Posted September 2, 2014 Posted September 2, 2014 Do you really want a database, or just to log players?
MTA Team 0xCiBeR Posted September 2, 2014 MTA Team Posted September 2, 2014 I also recomend using \r since if you read it with notepad it sometimes doesn't read the \n. So, you would have to add \n\r.
Anubhav Posted September 2, 2014 Posted September 2, 2014 Did you ever save it? if fileExists(country..".txt") then local file = fileOpen(country..".txt") fileWrite(file, "Name:"..name.." Serial:"..serial) fileSave(file) fileClose(file) end
xTravax Posted September 2, 2014 Posted September 2, 2014 Did you ever save it? if fileExists(country..".txt") then local file = fileOpen(country..".txt") fileWrite(file, "Name:"..name.." Serial:"..serial) fileSave(file) fileClose(file) end fileSave doesnt exist
Anubhav Posted September 2, 2014 Posted September 2, 2014 Wasn't it there? I think its a misunderstanding.
-.Paradox.- Posted September 2, 2014 Author Posted September 2, 2014 Did you ever save it? if fileExists(country..".txt") then local file = fileOpen(country..".txt") fileWrite(file, "Name:"..name.." Serial:"..serial) fileSave(file) fileClose(file) end Everything. Don't ever do that. Use a database management system. MTA supports the SQLite library and MySQL.But just for the record, you should call fileSetPos to set the position where reads and writes will take place. I'm not planning to save it anymore... And your function doesn't exist
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