SA-MP Forums Archive
[Plugin] [REL] Hash File Loader - 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: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] [REL] Hash File Loader (/showthread.php?tid=100903)

Pages: 1 2


[REL] Hash File Loader - VRocker - 07.10.2009

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


Re: [REL] Hash File Loader - gijsmin - 07.10.2009

I don't really get what this plugin does?


Re: [REL] Hash File Loader - Westie - 07.10.2009

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.


Re: [REL] Hash File Loader - Correlli - 07.10.2009

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


Re: [REL] Hash File Loader - Jay_ - 07.10.2009

Nice one!


Re: [REL] Hash File Loader - MenaceX^ - 07.10.2009

Good job! That is very useful!


Re: [REL] Hash File Loader - Dresden - 07.10.2009

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


Re: [REL] Hash File Loader - joemomma53 - 08.10.2009

I'll check this out, nice job!


Re: [REL] Hash File Loader - Jay_ - 16.10.2009

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


Re: [REL] Hash File Loader - Jamesy - 17.10.2009

Nice work.


Re: [REL] Hash File Loader - Creed - 31.10.2009

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

- Creed


Re: [REL] Hash File Loader - MX_Master - 06.11.2009

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;
}



REL Hash File Loader - D.duabe - 09.11.2009

Pierre

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

What method are you using to copy the file?


Re: [REL] Hash File Loader - cyber_punk - 09.11.2009

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?


Re: [REL] Hash File Loader - DaftWerk - 10.11.2009

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!


Re: [REL] Hash File Loader - Angelhj - 18.11.2009

HGetInt not working for me


Re: [REL] Hash File Loader - Aleron - 18.11.2009

nice job!


Re: [REL] Hash File Loader - Raphinity - 02.12.2009

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...



Re: [REL] Hash File Loader - VRocker - 03.12.2009

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

Uploaded both binaries and source now.


Re: [REL] Hash File Loader - Raphinity - 04.12.2009

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