SA-MP Forums Archive
[Include] tfile 1.0 - file system based on file lines - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] tfile 1.0 - file system based on file lines (/showthread.php?tid=354467)



tfile 1.0 - file system based on file lines - Terminator3 - 26.06.2012

This include allow you to write and get data from each line of file by number of this line
It's using my plugin directory (click) what it's more faster then without it, but you can still use just include, without plugin, just before you add to the script #include write a macro:
pawn Code:
#define DO_NOT_USE_PLUGIN
#include <tfile>
(it's not recommended)

How i can use it? in normal file system you use a key name to find data in file, here it is more like create an array, you assign each data a id, is faster then other because file system don't need to search key name, just skipping lines to the right

Functions:

GetFileLine(const filename[], dest[], line, len = sizeof dest)
Gets the data from line of file
Return true if succeeded get data


SetFileLine(const filename[], const substr[], line)
Save/change data in file line
Return true if succeeded save data


DeleteFileLine(const filename[], line)
Deletes full line from file
Return true if succeeded delete line



ClearFileLine(const filename[], line)
Clears the line in file (not deletes)
Return true if succeeded clear line



AddFileLine(const filename[], const strline[], line = -1)
Adds line to file,if we add something in line 1, line 1, 2, 3 etc. will be moved forward
Return true if succeeded add line


LinesInFile(const filename[])
Returns the number of lines in the file

Additional functions

denter(string[])
Deletes special chars from the string/text ( \r \n )
Returns nothing

Attention:
1. If you manually modify the file, just remember to set last line in file empty, example:
Quote:

1000
mypass
true
//empty line!

2. If you want to use this include to save players data, remember that's functions 'DeleteFileLine' & 'AddFileLine' can change numbers of file lines
3. Lines in file begins from 0



DOWNLOAD; Mirror


example how to save player data to file:
pawn Code:
#define MONEY 0
#define SCORE 1
#define PASS 2
#define VIP 3
pawn Code:
//creating new player file:
new str[64]
format(str, sizeof str, "%d\r\n%d\r\n%s\r\n%d\r\n", GetPlayerMoney(playerid), GetPlayerScore(playerid), inputtext, true);
new File:x = fopen(PlayerName(playerid), io_write);
fwrite(x, str);
fclose(x);
pawn Code:
//changing the data in the file:
new str[30];
valstr(str, GetPlayerMoney(playerid));
SetFileLine(PlayerName(playerid), str, MONEY);
valstr(str, GetPlayerScore(playerid));
SetFileLine(PlayerName(playerid), str, SCORE);
str[0] = EOS;
strcat(str, inputtext); // inputtext as password?
SetFileLine(PlayerName(playerid), str, PASS);
SetFileLine(PlayerName(playerid), "1", VIP);
pawn Code:
//gets data from file
new str[30];
GetFileLine(PlayerName(playerid), str, MONEY);
GivePlayerMoney(playerid, strval(str));
GetFileLine(PlayerName(playerid), str, SCORE);
SetPlayerScore(playerid, strval(str));
GetFileLine(PlayerName(playerid), str, VIP);
if(str[0] != '0')
SetPVarInt(playerid, "VIP", true); // for example



Re: tfile 1.0 - file system based on file lines - @Riichard - 26.06.2012

Not Bad.


Re: tfile 1.0 - file system based on file lines - RyDeR` - 26.06.2012

You better use enumerators instead of defines for that.


Re: tfile 1.0 - file system based on file lines - Terminator3 - 26.06.2012

Quote:
Originally Posted by RyDeR`
View Post
You better use enumerators instead of defines for that.
you mean
pawn Code:
enum info
{
money,
score,
pass,
vip
};

SetFileLine(PlayerName(playerid), "1", info:vip);
?
Honestly? I do not see the difference
and I prefer to use a macro