[TUT & INC] Nvault Easy

Tutoriale scripting, cod si portiuni de cod.

Moderators: Moderatori ajutatori, Moderatori

Post Reply
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

29 Nov 2016, 16:00

NVE ( Nvault Easy )

Descriere
Salut, tocmai ce m-am apucat de un proiect, un fisier .inc care te ajuta sa salvezi datele mult mai usor, te scuteste de anumite verificari .. e facut 100% pentru incepatori, daca stii cum functioneaza nvault ar trebui sa-l folosesti direct, dar daca te complici cu el ar trebui sa folosesti acest include, daca vrea cineva sa colaboreze si sa-l dezvoltam impreuna , thank!

Sursa codului:
SMA | Afiseaza codul
#if defined _nve_included
  #endinput
#endif
#define _nve_included


#include <amxmodx>
#include <nvault>

new gVault;
new gVaultName[] = "NvaultEasy";



const NVE_VERSION = 1.2;




/**
 * 	Open the NvaultEasy.vault file
 * @noreturn
 */
stock nve_open( )
{
	gVault = nvault_open( gVaultName );

	if( gVault == INVALID_HANDLE )
		set_fail_state( " Problems with Nvault Easy include ... " );
}

/**
 * 	Close the NvaultEasy.vault file.
 * @noreturn
 */
stock nve_close( ) nvault_close( gVault );

/**
 * @return: The vault id wich handle the vault file ( You may want for using normal nvault natives, maybe for the same file ).
 */
stock nve_vault_id( ) return gVault;


/**
 * Save an integer to an index, you need to use a symbol to make it unique.
 *
 * @param	id			The index of the player.
 * @param 	szSymb			The symbol to use for making the save unique for this plugin.
 * @param	Number			The number to save ( the integer ) .
 * @noreturn
 */
stock nve_set_int( id, szSymb[], Number )
{
	new buffer[64];
	new szName[32];
	get_user_name( id, szName, charsmax( szName ) );

	formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

	new szData[11];
	num_to_str( Number, szData, charsmax( szData ) );

	nvault_set( gVault, buffer, szData );
}



/**
 * Get an integer from an index
 *
 * @param	id			The index of the player.
 * @param 	szSymb			The symbol to use for making the save unique for this plugin.
 * @return: The Number
 */
stock nve_get_int( id, szSymb[] )
{
	new buffer[64];
	new szName[32];
	get_user_name( id, szName, charsmax( szName ) );

	formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

	return nvault_get( gVault, buffer );
}

/**
 * Update an integer from an index ( same as nve_get_int() you use this when your user is changing his name to retrieve the actual integer for his actual name. )
 *
 * @param	id			The index of the player.
 * @param 	szSymb			The symbol to use for making the save unique for this plugin.
 * @return: The Number
 */
stock nve_update_int( id, szSymb[] )
{
	new buffer[64];
	new szName[32];
	get_user_info( id, "name", szName, charsmax( szName ) );

	formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

	return nvault_get( gVault, buffer );
}


/**
 * Save an string to an index, you need to use a symbol to make it unique.
 *
 * @param	id			The index of the player.
 * @param 	szSymb			The symbol to use for making the save unique for this plugin.
 * @param	String			The string to save ( "this is a string" )
 * @noreturn
 */
stock nve_set_string( id, szSymb[], String[] )
{
	new buffer[64];
	new szName[32];
	get_user_name( id, szName, charsmax( szName ) );

	formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

	nvault_set( gVault, buffer, String );
}



/**
 * Get an string from an index
 *
 * @param	id			The index of the player.
 * @param 	szSymb			The symbol to use for making the save unique for this plugin.
 * @param	String			The string variable to insert the saved string ( "this is a string" )
 * @param	lengh			The lengh of the String variable ( Note: user charsmax() )
 * @noreturn
 */
stock nve_get_string( id, szSymb[], String[] , lengh=64 )
{
	new buffer[64];
	new szName[32];
	get_user_name( id, szName, charsmax( szName ) );

	formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

	nvault_get( gVault, buffer, String, lengh );
}

/**
 * Update an string from an index ( Same as nve_get_string, you use this when your user is changing his name to retrieve the actual string for his actual name.
 *
 * @param	id			The index of the player.
 * @param 	szSymb			The symbol to use for making the save unique for this plugin.
 * @param	String			The string variable to insert the saved string ( "this is a string" )
 * @param	lengh			The lengh of the String variable ( Note: user charsmax() )
 * @noreturn
 */
stock nve_update_string( id, szSymb[], String[] , lengh=64 )
{
	new buffer[64];
	new szName[32];
	get_user_info( id, "name", szName, charsmax( szName ) );

	formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

	nvault_get( gVault, buffer, String, lengh );
}




/**
 * 	Reset a vault, so it deletes all the entries ( #RO: Sterge toate salvarile, goloseste vault-ul. )
 * @noreturn
 */
stock nve_reset( )
{
	nvault_prune( gVault, 0, get_systime( ) );
}

Explicatii

Cum observati codul nu e prea mare si inca nu prea contine multe native dar asa cum am zis e la inceput.

O sa va explic ce face fiecare in parte, nu uitati e un mod mult mai usor de a salve Numerele ( integers ) pentru incepatori.

Prima data includeti libraria:

Code: Select all

#include <nve>
In plugin init si in plugin_end va trebuie sa aveti mereu asa:

Code: Select all

public plugin_init( )
{
        nve_open();
}

public plugin_end( )
{
        nve_close();
}
Lista Stock-uri/Functii
Lista | Afiseaza codul
nve_open() - deschide Nve Vault.
nve_close() - inchide Nve Vault.

nve_vault_id() - returneaza vault Id.  ( #In caz ca vreti sa folositi si celelalte native ale nvault-ului. )
nve_reset() - Reseteaza NVE ( il goleste ).

nve_set_int( id, szSymb[], Number ) - Salveaza un numar id-ului. 
nve_get_int( id, szSymb[] ) -  Returneaza numarul salvat id-ului.
nve_update_int( id, szSymb[] ) - Returneaza numar salvat al id-ului cu noul nume.

nve_set_string( id, szSymb[], String[] ) - Salveaza un string id-ului.
nve_get_string( id, szSymb[], String[], lengh ) - Insereaza string-ul salvat al id-ului in variabila data.
nve_update_string( id, szSymb[], String[], lengh[] - Insereaza string-ul salvat al id-ului cu noul nume in variabila data.

Exemplu salvare numar:
SMA | Afiseaza codul
#include <amxmodX>
#include <cstrike>
#include <nve>

// Creiem un MACROSS cu "Test" , as prefera ca sa creati o variabila constanta, dar daca asa e mai usor pentru voi ...
#define SYMBOL "Test"

public plugin_init( )
{
	register_plugin( "Nvault Easy Test", "1.0", "Fuffy" );

	register_clcmd( "say /show", "show" );
	register_clcmd( "say /big", "big" );

// Nv Open:
	nve_open( );

}

// De fiecare data cand scrii in chat '/big' iti salva 'banii actuali + inca o suta" 

public big( id )
{

	new iMoney = cs_get_user_money( id );

	nve_set_int( id, SYMBOL, iMoney + 100);
	
}


// De fiecare data cand scrii /show iti va arata cand bani ai salvati.
public show( id )
{
	new ReturneazaMoney = nve_get_int( id, SYMBOL );

	client_print( id, print_chat, "Money: %i", ReturneazaMoney );
}

public plugin_end()
{
	nve_close();
}
Exemplu salvare string:
SMA | Afiseaza codul
#include <amxmodX>
#include <cstrike>
#include <nve>

#define SYMBOL "Test"

public plugin_init( )
{
	register_plugin( "Nvault Easy Test", "1.0", "Fuffy" );

	register_clcmd( "say /test", "big" );
	register_clcmd( "say /show", "show" );

	nve_open( );

}


public big( id )
{

	nve_set_string( id, SYMBOL, " PROPOZITIE " );
	
}


public show( id )
{
	new TheString[64];
	nve_get_string( id, SYMBOL, TheString, charsmax( TheString ) );

	client_print( id, print_chat, "%s", TheString );
}

public plugin_end()
{
	nve_close();
}
Last edited by Fuffy on 13 Dec 2016, 22:49, edited 9 times in total.
AMXX Blue e acum doar pe github.
IG-BOOST.org - Instagram Followers Best, Cheap, Reliable
User avatar
JaiLBreaK
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1692
Joined: 05 Jan 2016, 18:17
Detinator Steam: Nu
Detinator server CS: Da
Reputatie: Membru Club eXtreamCS (2 luni)
Scripter eXtreamCS
Fond eXtream: 0
Has thanked: 1 time
Been thanked: 2 times
Contact:

29 Nov 2016, 18:05

se poate salva in nvault si stringuri
Image
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

29 Nov 2016, 18:32

JaiLBreaK wrote:se poate salva in nvault si stringuri
Mersi, am sa-mi notez in palma sa tin minte.

Si , care e rostul reply-ului asta?
AMXX Blue e acum doar pe github.
User avatar
LondoN eXtream
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 2889
Joined: 10 Oct 2014, 05:21
Detinator Steam: Da
SteamID: /id/london_extreamcs
Reputatie: Scripter eXtreamCS
Moderator ajutator
Membru Club eXtreamCS (6 luni)
Fond eXtream: 0
Location: Roman, Neamț
Has thanked: 2 times
Been thanked: 2 times

29 Nov 2016, 20:27

| Afiseaza codul
#if defined _easy_stock_included
	#endinput
#endif

#define _easy_stock_included

#include <cstrike>
#include <fun>
#include <fakemeta>

stock afla_echipa(id)
{
	if(!is_user_alive(id) || is_user_bot(id) || is_user_hltv(id))
		return -1;
		
	return get_user_team(id);
}

stock afla_bani(id)
{
	if(!is_user_alive(id) || is_user_bot(id) || is_user_hltv(id))
		return -1;
		
	return cs_get_user_money(id);
}

stock afla_resurse(id, szType = 0)
{
	if(!is_user_alive(id) || is_user_bot(id) || is_user_hltv(id) || !szType)
		return -1;
		
	switch(Type)
	{
		case 1:		return get_user_health(id);
		case 2:		return get_user_armor(id);
	}
	
	return -1;
}

stock afla_loc(id)
{
	if(!is_user_alive(id) || is_user_bot(id) || is_user_hltv(id))
		return -1;
		
	new Float:Origin[3], ReturnLocation[3];
	pev(id, pev_origin, Origin);
	FVecIVec(Origin, ReturnLocation);
	
	return ReturnLocation;
}
am gasit si eu astea prin PC poate ajuta pe cineva.
User avatar
JaiLBreaK
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1692
Joined: 05 Jan 2016, 18:17
Detinator Steam: Nu
Detinator server CS: Da
Reputatie: Membru Club eXtreamCS (2 luni)
Scripter eXtreamCS
Fond eXtream: 0
Has thanked: 1 time
Been thanked: 2 times
Contact:

29 Nov 2016, 20:45

stock nve_set_int( id, szSymb[], Number )
{
new buffer[64];
new szName[32];
get_user_name( id, szName, charsmax( szName ) );

formatex( buffer, charsmax( buffer ), "%s%s", szSymb, szName );

new szData[11];
num_to_str( Number, szData, charsmax( szData ) );


nvault_set( gVault, buffer, szData );
}
uite rostu
Image
User avatar
Nubo
Fost moderator
Fost moderator
Posts: 2771
Joined: 11 Jul 2012, 17:45
Detinator Steam: Da
CS Status: [əˈnɒn.ɪ.məs]
Reputatie: Fost scripter eXtreamCS
Fost eXtream Mod
Has thanked: 8 times
Been thanked: 26 times
Contact:

29 Nov 2016, 20:54

JailBreak, mai nou esti orb?
Omul a specifiat:
e un mod mult mai usor de a salve Numerele ( integers )
Exemplu: nve_set_int( id, "L", g_iUserLevel[id] )
Cand nu merge acest forum sunt online aici:
  • * Skype: nubo_cs
    * Y!M ID: nubo_cs
User avatar
JaiLBreaK
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1692
Joined: 05 Jan 2016, 18:17
Detinator Steam: Nu
Detinator server CS: Da
Reputatie: Membru Club eXtreamCS (2 luni)
Scripter eXtreamCS
Fond eXtream: 0
Has thanked: 1 time
Been thanked: 2 times
Contact:

29 Nov 2016, 20:56

Nubo wrote:JailBreak, mai nou esti orb?
Omul a specifiat:
e un mod mult mai usor de a salve Numerele ( integers )
Exemplu: nve_set_int( id, "L", g_iUserLevel[id] )
eh nu am vazut asta dar putea face totusi 2 variante, una pentru numere si una pentru string
Image
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

29 Nov 2016, 23:47

JaiLBreaK wrote: eh nu am vazut asta dar putea face totusi 2 variante, una pentru numere si una pentru string
Ok, adaugat, alte idei sau nevoi?

Code: Select all

nve_get_string( id, symbol, string, len );
nve_set_string( id, symbol, string );
AMXX Blue e acum doar pe github.
User avatar
Fuffy
Membru, skill +1
Membru, skill +1
Posts: 299
Joined: 07 Jan 2016, 08:34
Detinator Steam: Da
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

13 Dec 2016, 22:35

Update:

- Adaugat:

Code: Select all

const NVE_VERSIO
Poate ii trebe cuiva, eu stiu ..

+

2 stock-uri:

nve_update_int / nve_update_string

Le folosit in client_infochanged() cand jucatorul isi schimba noul nume pentru ai updata cu informatia noului nume.
AMXX Blue e acum doar pe github.
User avatar
LondoN eXtream
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 2889
Joined: 10 Oct 2014, 05:21
Detinator Steam: Da
SteamID: /id/london_extreamcs
Reputatie: Scripter eXtreamCS
Moderator ajutator
Membru Club eXtreamCS (6 luni)
Fond eXtream: 0
Location: Roman, Neamț
Has thanked: 2 times
Been thanked: 2 times

09 Feb 2018, 10:43

Nu e complet functional, dupa schimbarea mapei nu imi mai salveaza datele.
Post Reply

Return to “Scripting”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest