[Include] HSA - Easy and fast Saving!
#1

HSA is the probably the easiest way to store data in a file.
There is always a function for reading and for writing strings, integers and floats.
Of course, HSA has some advantages to other includes, which are provided for storing.
  • HSA is very easy to use!
  • HSA is normally faster than other includes
  • HSA secures data automatically
Here is a speed comparison of HSA to SII. In this 10 times in a row 100 entries have been written single to a file and read again.
From the values ​​of the arithmetic mean was determined.
You can see, that HSA is faster. (This chart is based on writing & reading single entries)

Functions:
  • getInt:
    pawn Код:
    getInt:"Filename"("Datasetname");

    Returns the saved integer "Datasetname" in the file "Filename".
  • getFloat:
    pawn Код:
    getFloat:"DateiName"("Datasetname");

    Returns the saved float "Datasetname" in the file "Filename".
  • getString:
    pawn Код:
    getString:"DateiName"("Datasetname");

    Returns the saved text "Datasetname" in the file "Filename".
  • setInt:
    pawn Код:
    setInt:"DateiName"("Datasetname",12356789);

    Saves the integer "12356789" in the file "Filename" under the name "Datasetname".
  • setFloat:
    pawn Код:
    setFloat:"DateiName"("Datasetname",1234.56789);

    Saves the float "1234.56789" in the file "Filename" under the name "Datasetname".
  • setString:
    pawn Код:
    setString:"DateiName"("Datasetname","Any text");

    Saves the text "Any text" in the file "Filename" under the name "Datasetname".
More features does not require the system!
Files are created automatically.

Examples:
  • Easy saving of players:
    pawn Код:
    new PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,PlayerName,MAX_PLAYER_NAME);

    setString:PlayerName("password","I like trains");
    setInt:PlayerName("money",4125);
    setFloat:PlayerName("health",74.12);

    printf("the players password is %s",getString:PlayerName("password"));
    printf("%s has %d$.",PlayerName,getInt:PlayerName("money"));
    printf("%s has %f health.",PlayerName,getFloat:PlayerName("health"));
  • Easy fraction cash system:
    pawn Код:
    setInt:"fraction_money"("police",81921);
    setInt:"fraction_money"("firedepartment",56121);
    setInt:"fraction_money"("yakuza",1912);
    setInt:"fraction_money"("lufthansa",917251);

    printf("Die police has %d$",getInt:"fraction_money"("police"));
    printf("Die fire department has %d$",getInt:"fraction_money"("firedepartment"));
    printf("Die yakuza has %d$",getInt:"fraction_money"("yakuza"));
    printf("Die lufthansa has %d$",getInt:"fraction_money"("lufthansa"));
When storing data was ever so simple?
Links:
Reply
#2

Hmmm Nice one!
Reply
#3

Thanks
Reply
#4

Epic! + Rep!
Reply
#5

this is great it will make creating gang and faction files way easier.
Reply
#6

Really nice
Reply
#7

Very very nice, looks so beatiful
Reply
#8

pawn Код:
setInt:"fraction_money"("police",81921);
setInt:"fraction_money"("firedepartment",56121);
setInt:"fraction_money"("yakuza",1912);
setInt:"fraction_money"("lufthansa",917251);

printf("Die police has %d$",getInt:"Fraktionskassen"("police"));
printf("Die fire department has %d$",getInt:"Fraktionskassen"("firedepartment"));
printf("Die yakuza has %d$",getInt:"Fraktionskassen"("yakuza"));
printf("Die lufthansa has %d$",getInt:"Fraktionskassen"("lufthansa"));
wrong translate. :/ "Fraktionskassen"

WRONG:
pawn Код:
printf("the players %s password is %s",getString:PlayerName("Passwort"));
GOOD:
pawn Код:
printf("the players %s password is %s",PlayerName, getString:PlayerName("Passwort"));
Reply
#9

looks very nice
thank you.
Reply
#10

Nice
Reply
#11

Looks good to me. Will test with my new script! Thanks for the release (Repped+)
Reply
#12

Nice.. But I got an other result for testing.

Код:
[09:32:17]   Loading filterscript 'test.amx'...
[09:32:17] SII write started
[09:32:17] SII test done in 196

[09:32:17] HSA write started
[09:32:18] HSA test done in 391

[09:32:18] SII read started
[09:32:18] SII test done in 84

[09:32:18] this is a short string 1234567890 0.123400

[09:32:18] HSA read started
[09:32:18] HSA test done in 145

[09:32:18] this is a short string 1234567890 0.123450

[09:32:18]   Loaded 1 filterscripts.
the test script.

Код:
#include <a_samp>
#include <sii>
#include <hsa>

#define TEST_TIME   100

public OnFilterScriptInit() {
	new tick = GetTickCount();
	print("SII write started");
	for(new i = 0; i < TEST_TIME; i++) {
	    INI_Open("sii.ini");
	    INI_WriteString("string", "this is a short string");
	    INI_WriteInt("int", 1234567890);
	    INI_WriteFloat("float", 0.12345);
	    INI_Save();
	    INI_Close();
	}
	printf("SII test done in %d\n", GetTickCount() - tick);
	
	tick = GetTickCount();
	
	print("HSA write started");
	for(new i = 0; i < TEST_TIME; i++) {
		setString:"hsa"("string", "this is a short string");
	    setInt:"hsa"("int", 1234567890);
		setFloat:"hsa"("float", 0.12345);
	}
	printf("HSA test done in %d\n", GetTickCount() - tick);
	
	new rstring[256], rint, Float:rfloat;
	
	tick = GetTickCount();
	
	print("SII read started");
	for(new i = 0; i < TEST_TIME; i++) {
	    INI_Open("sii.ini");
	    INI_ReadString(rstring, "string");
	    rint = INI_ReadInt("int");
	    rfloat = INI_ReadFloat("float");
	    INI_Close();
	}
	printf("SII test done in %d\n", GetTickCount() - tick);
	printf("%s %d %f\n", rstring, rint, rfloat);
	
	rstring[0] = EOS;
	rint = 0;
	rfloat = 0.0;
	
	tick = GetTickCount();
	
	print("HSA read started");
	for(new i = 0; i < TEST_TIME; i++) {
		format(rstring, sizeof(rstring), "%s", getString:"hsa"("string"));
	    rint = getInt:"hsa"("int");
		rfloat = getFloat:"hsa"("float");
	}
	printf("HSA test done in %d\n", GetTickCount() - tick);
	printf("%s %d %f\n", rstring, rint, rfloat);
	return 1;
}
Reply
#13

This is really nice +rep
Reply
#14

@kacper55331: Thanks! i translated a little bit too fast...
@All: this is a single entry writer. You should not loop saves, with more than 1,000 writings. because than SII is much faster.
Reply
#15

Very neat syntax! Nice job!
Reply
#16

Quote:
Originally Posted by [LoD]Hauke
Посмотреть сообщение
@kacper55331: Thanks! i translated a little bit too fast...
@All: this is a single entry writer. You should not loop saves, with more than 1,000 writings. because than SII is much faster.
If your tests were made with a single entry then they are a complete fail...

If you admit that SII is much faster why did you just posted wrong tests?
Reply
#17

Preety Nice looking Include <3 it
Reply
#18

Can You compare results with Y_Ini ?
Reply
#19

Quote:
Originally Posted by SlashPT
Посмотреть сообщение
If your tests were made with a single entry then they are a complete fail...
If you admit that SII is much faster why did you just posted wrong tests?
+1

single write.. can't beat Dini in single writes.
Reply
#20

Quote:
Originally Posted by NeTuddMeg
Посмотреть сообщение
+1

single write.. can't beat Dini in single writes.
Who use single writes? max 1% of SA:MP scripters.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)