[Plugin] [REL] Hash File Loader
#1

Hash File Loader

This is my first plugin for samp as it was requested by a friend. I noticed SA-MP doesn't have many decent file storage options. Yes theres dini and sql variants but imo they aren't fast enough.

So i created this has file loader. It works in a similar way to mIRC hash files (Hashes are stored in a text file and loaded into memory, and resides there until saved)
In testing, its a LOT faster than ini and sqlite so its great for anyone who needs/wants the best performance from their script.

The plugin code is a bit messy since it was originally designed for another project of mine, so i just took the files and rammed them into the hello world example.

Heres the files: http://liberty-unleashed.co.uk/samp/hashloader.zip (Contains dll, so and inc)

And heres the source: http://liberty-unleashed.co.uk/samp/hash-src.zip

The usage is pretty self explanatory so check the inc file.

Enjoy
Reply
#2

I don't really get what this plugin does?
Reply
#3

Quote:

So i created this has file loader. It works in a similar way to mIRC hash files (Hashes are stored in a text file and loaded into memory, and resides there until saved)

Well I get it. It's a way of decreasing the read/write time to 'files', where 'files' are actually chunks of memory.
Reply
#4

Good work VRocker, didn't saw you on these forums for a long time. I guess you're too busy with your project?
Reply
#5

Nice one!
Reply
#6

Good job! That is very useful!
Reply
#7

Would be nice to get a more in-depth readme but I guess I can try figuring it out.
Reply
#8

I'll check this out, nice job!
Reply
#9

Quote:
Originally Posted by Seif_
Yea maybe some examples would be good. This looks good.
Working on it
Reply
#10

Nice work.
Reply
#11

Quote:
Originally Posted by Don Correlli
Good work VRocker
Jup. Really nice work, VRocker!

- Creed
Reply
#12

It's realy works FAST ! Just 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" );

output file format (tested) :

Quote:
textValue
textExample
integerValue
123456
floatValue
1.23456
usage example (not tested) :

Код:
#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;
}
Reply
#13

Pierre

There might be a way to do it. I dont know.

What method are you using to copy the file?
Reply
#14

Looks promising but the lock of proper documentation or examples on its uses kinda makes it like bleh
Can we get some read me's or and example for every function. I am kinda curious about HInc and HDec, like what is the proper usage on the amount parameter?
Reply
#15

Hey all,
This hash script was built for my server and we've tested the literal **** out of it, if you want to do dynamic player positions and car spawning this is probably thee best way to do it/store it!

If you need any support or code snippits I'll be more than happy to help - just drop me a PM

Cheers,

oz

P.S. If you want to see it in action: samp.stirredfork.net:7777, all of the non server owned cars will respawn where you leave them and you respawn where you leave, easy stuff to do but gives a more RPG feel!
Reply
#16

HGetInt not working for me
Reply
#17

nice job!
Reply
#18

Nice, it seems really interesting !

Quote:
Originally Posted by Angelhj
HGetInt not working for me
Same for me, I can get a string with HGet, but HGetInt always return 0 as value, even if it's not 0 in the file...
Reply
#19

Sorry about the HGetInt problems. I fixed this a while ago but forgot to upload.

Uploaded both binaries and source now.
Reply
#20

After having downloaded the last HashLoader.dll, I still notice the same problem with HGetInt.
Can somebody else confirm ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)