06.11.2009, 21:30
It's realy works FAST ! Just tested.
"create" example (tested) :
output file format (tested) :
usage example (not tested) :
"create" example (tested) :
Quote:
HLoad( "test", "test_hash_file.txt" ); HAdd( "test", "textValue", "textExample" ); HAddInt( "test", "integerValue", 123456 ); HAddFloat( "test", "floatValue", 1.23456 ); HSave( "test" ); HClose( "test" ); |
Quote:
textValue textExample integerValue 123456 floatValue 1.23456 |
Код:
#include <a_samp> #include <hashloader> #define HASH_FILE_NAME "test" #define HASH_FILE_PATH "test_hash_file.txt" #define HASH_FILE_SAVE_INTERVAL 20000 stock hash_save_timer; forward save_hash_file (); public save_hash_file () { // writing all hash file changes to file HSave( HASH_FILE_NAME ); } public OnGameModeInit () { // opening hash file HLoad( HASH_FILE_NAME, HASH_FILE_PATH ); // save hash file every 20 seconds hash_save_timer = SetTimer( "save_hash_file", HASH_FILE_SAVE_INTERVAL, 1 ); } public OnGameModeExit () { // kill save timer KillTimer( hash_save_timer ); // writing all hash file changes to file HSave( HASH_FILE_NAME ); // closing hash file HClose( HASH_FILE_NAME ); } public OnPlayerCommandText ( playerid, cmdtext[] ) { if ( strcmp( cmdtext, "/hash_writing_test", true ) == 0 ) { new textValue[20], floatValueStr[20]; format( textValue, 20, "newText_%d", random(999999) ); format( floatValueStr, 20, "%d.%d", random(999999), random(999999) ); // writing hash data to server's memory HAdd( HASH_FILE_NAME, "textValue", textValue ); HAddInt( HASH_FILE_NAME, "integerValue", GetTickCount() ); HAddFloat( HASH_FILE_NAME, "floatValue", floatstr( floatValueStr ); SendClientMessage( playerid, 0xAAAAAAAA, " * hash_writing_test: type /hash_reading_test to see new hash values" ); return 1; } if ( strcmp( cmdtext, "/hash_reading_test", true ) == 0 ) { new textValue[20], integerValue, Float:floatValue, message[120]; // reading hash data from server's memory HGet( HASH_FILE_NAME, "textValue", textValue ); HGetInt( HASH_FILE_NAME, "integerValue", integerValue ); HGetFloat( HASH_FILE_NAME, "floatValue", floatValue ); format ( message, 120, " * hash_reading_test: textValue = %s , integerValue = %d , floatValue = %f", textValue, integerValue, floatValue ); SendClientMessage( playerid, 0xAAAAAAAA, message ); return 1; } return 0; }