Jump to content

file functions


-.Paradox.-

Recommended Posts

Posted

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?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
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...

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

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) 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
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  

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
Like I said: \n
"lollollol\ntest 
  
 

Outputs:

lollollol 
test 

oh lol, sorry i thought that is a kind of smileys xD

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

  • MTA Team
Posted

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.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted

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 
  

Posted
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

Posted
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

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...