Hello, I want to make a user file. Something like a bank system
Ex:
User: Nicksf13
SteamID: XXXXXXXXXXX
Credits: 1000
VIP: 4
There's anyway to do that? I know C++ Has the io.open and C has fopen(). Also garry's mod has file.read, but I didn't see anyway to write a structured file in gmod.Can anyone help me?
There's the [url=http://wiki.garrysmod.com/page/Category:file]file library[/url] which has pretty much everything you'd need. If you wanted a format you could use [url=http://wiki.garrysmod.com/page/string/format]string.format[/url] to easily fill it in, something like this:
[lua]local format = [[User: %s
SteamID: %s
Credits: %i]]
file.Write( "register/"..ply:SteamID()..".txt", string.format( format, ply:Nick(), ply:SteamID(), ply:GetPoints() ) )[/lua]
However, if you're using this as a form of storing information about players to be collected by the server, not by you, I suggest looking into more efficient methods, such as serializing tables using [url=http://wiki.garrysmod.com/page/util/TableToJSON]util.TableToJSON[/url] instead. Even better, learn yourself SQL and use the in-built SQLite database with the [url=http://wiki.garrysmod.com/page/Category:sql]sql library[/url]
To read saved data easier in code, util.tabletojson and util.jsonfromtable
Harder to read as a human opening the file in a text editor though.
[QUOTE=Internet1001;46377918]There's the [url=http://wiki.garrysmod.com/page/Category:file]file library[/url] which has pretty much everything you'd need. If you wanted a format you could use [url=http://wiki.garrysmod.com/page/string/format]string.format[/url] to easily fill it in, something like this:
[lua]local format = [[User: %s
SteamID: %s
Credits: %i]]
file.Write( "register/"..ply:SteamID()..".txt", string.format( format, ply:Nick(), ply:SteamID(), ply:GetPoints() ) )[/lua]
However, if you're using this as a form of storing information about players to be collected by the server, not by you, I suggest looking into more efficient methods, such as serializing tables using [url=http://wiki.garrysmod.com/page/util/TableToJSON]util.TableToJSON[/url] instead. Even better, learn yourself SQL and use the in-built SQLite database with the [url=http://wiki.garrysmod.com/page/Category:sql]sql library[/url][/QUOTE]
I think I'll try with SQL, but I didn't found any SQL tutorial, do You have one? Some simple SQL tutorial explaning which function is to open a section in sql, which function with user, pw, hostname?
Sorry, you need to Log In to post a reply to this thread.