Raised This Month: $51 Target: $400
 12% 

How to save easier in nvault?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gasior
Member
Join Date: Mar 2012
Old 02-09-2017 , 05:32   How to save easier in nvault?
Reply With Quote #1

Hi guys,

Is there any easier way to save the below?

Code:
public SaveData(id) 
{  
    new szKey[ 40 ] , szData[ 3 ];
    new sBurner[ 40 ] , zBurner[ 3 ];
    new sCarbon[ 40 ], zCarbon[ 3 ];
    new sCrimson[ 40 ], zCrimson[ 3 ];
    new sGradient[ 40 ], zGradient[ 3 ];
    new sKrolewski[ 40 ], zKrolewski[ 3 ];
    new sKrwawy[ 40 ], zKrwawy[ 3 ];
     
    formatex( szKey , charsmax( szKey ) , "%s_glock" , g_szAuthID[ id ] ); 
    num_to_str( _:glock_model[ id ] , szData , charsmax( szData ) ); 
    
    formatex( sBurner , charsmax( sBurner ) , "%s_Burner" , g_szAuthID[ id ] ); 
    num_to_str( _:Burner1[ id ] , zBurner , charsmax( zBurner ) );
    
    formatex( sCarbon , charsmax( sCarbon ) , "%s_Carbon" , g_szAuthID[ id ] ); 
    num_to_str( _:Carbon1[ id ] , zCarbon , charsmax( zCarbon ) );
    
    formatex( sCrimson , charsmax( sCrimson ) , "%s_Crimson" , g_szAuthID[ id ] ); 
    num_to_str( _:Crimson1[ id ] , zCrimson , charsmax( zCrimson ) );
    
    formatex( sGradient , charsmax( sGradient ) , "%s_Gradient" , g_szAuthID[ id ] ); 
    num_to_str( _:Gradient1[ id ] , zGradient , charsmax( zGradient ) );
    
    formatex( sKrolewski , charsmax( sKrolewski ) , "%s_Krolewski" , g_szAuthID[ id ] ); 
    num_to_str( _:Krolewski1[ id ] , zKrolewski , charsmax( zKrolewski ) );
    
    formatex( sKrwawy , charsmax( sKrwawy ) , "%s_Krwawy" , g_szAuthID[ id ] ); 
    num_to_str( _:Krwawy1[ id ] , zKrwawy , charsmax( zKrwawy ) );

    nvault_set( zapis_vault , szKey , szData );
    nvault_set( zapis_vault , sBurner , zBurner ); 
    nvault_set( zapis_vault , sCarbon , zCarbon ); 
    nvault_set( zapis_vault , sCrimson , zCrimson ); 
    nvault_set( zapis_vault , sGradient , zGradient ); 
    nvault_set( zapis_vault , sKrolewski , zKrolewski );
    nvault_set( zapis_vault , sKrwawy , zKrwawy );
} 

public LoadData(id)  
{  
    new szKey[ 40 ] , szData[ 3 ] , iTS;
    new sBurner[ 40 ] , zBurner[ 3 ], kTS;
    new sCarbon[ 40 ], zCarbon[ 3 ], oTS;
    new sCrimson[ 40 ], zCrimson[ 3 ], tTS;
    new sKrolewski[ 40 ], zKrolewski[ 3 ], bTS;
    new sGradient[ 40 ], zGradient[ 3 ], nTS;
    new sKrwawy[ 40 ], zKrwawy[ 3 ], qTS;
     
    formatex( szKey , charsmax( szKey ) , "%s_glock" , g_szAuthID[ id ] );
    formatex( sGradient , charsmax( sGradient ) , "%s_Gradient" , g_szAuthID[ id ] );
    formatex( sKrolewski , charsmax( sKrolewski ) , "%s_Krolewski" , g_szAuthID[ id ] );
    formatex( sCrimson , charsmax( sCrimson ) , "%s_Crimson" , g_szAuthID[ id ] );
    formatex( sCarbon , charsmax( sCarbon ) , "%s_Carbon" , g_szAuthID[ id ] );
    formatex( sBurner , charsmax( sBurner ) , "%s_Burner" , g_szAuthID[ id ] );
    formatex( sKrwawy , charsmax( sKrwawy ) , "%s_Krwawy" , g_szAuthID[ id ] );
     
    if ( nvault_lookup( zapis_vault , szKey , szData , charsmax( szData ) , iTS ) )   
    { 
        glock_model[ id ] = Glocks:str_to_num( szData ); 
    }
    if ( nvault_lookup( zapis_vault , sBurner , zBurner , charsmax( zBurner ) , kTS ) )   
    { 
        Burner1[ id ] = str_to_num( zBurner ); 
    } 
    if ( nvault_lookup( zapis_vault , sCarbon , zCarbon , charsmax( zCarbon ) , oTS ) )   
    { 
        Carbon1[ id ] = str_to_num( zCarbon ); 
    } 
    if ( nvault_lookup( zapis_vault , sCrimson , zCrimson , charsmax( zCrimson ) , tTS ) )   
    { 
        Crimson1[ id ] = str_to_num( zCrimson ); 
    } 
    if ( nvault_lookup( zapis_vault , sGradient , zGradient , charsmax( zGradient ) , nTS ) )   
    { 
        Gradient1[ id ] = str_to_num( zGradient ); 
    } 
    if ( nvault_lookup( zapis_vault , sKrolewski , zKrolewski , charsmax( zKrolewski ) , bTS ) )   
    {
        Krolewski1[ id ] = str_to_num( zKrolewski ); 
    }
    if ( nvault_lookup( zapis_vault , sKrwawy , zKrwawy , charsmax( zKrwawy ) , qTS ) )   
    {
        Krwawy1[ id ] = str_to_num( zKrwawy ); 
    }
}
Gasior is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-09-2017 , 05:37   Re: How to save easier in nvault?
Reply With Quote #2

Yeah, you can make the code shorter.
__________________
HamletEagle is offline
Gasior
Member
Join Date: Mar 2012
Old 02-09-2017 , 06:07   Re: How to save easier in nvault?
Reply With Quote #3

How can I do that? I know it can be shortened but could you show me how to do it?
Gasior is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-09-2017 , 06:51   Re: How to save easier in nvault?
Reply With Quote #4

use Nvault array.

I believe you already open some threads about this subject, you understand nothing from them?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-09-2017 , 09:36   Re: How to save easier in nvault?
Reply With Quote #5

Assign values for each player like this:

g_pdData[ id ][ Crimson ] = 343;
g_pdData[ id ][ Burner ] = 123;

PHP Code:

#include <amxmodx>
#include <nvault_array>

#define MAX_PLAYERS 32

enum PlayerData
{
    
Glock,
    
Burner,
    
Carbon,
    
Crimson,
    
Gradient,
    
Krolewski,
    
Krwawy
}

new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
bool:g_bIgnorePlayerMAX_PLAYERS ];
new 
zapis_vault;

public 
plugin_init() 
{
    
zapis_vault nvault_open"zapis_vault" );
}

public 
plugin_end()
{
    
nvault_closezapis_vault );
}

public 
client_authorizedid )
{
    if ( !( 
g_bIgnorePlayerid ] = ( is_user_botid ) || is_user_hltvid ) ) ) ) 
    {
        
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
        
LoadDataid );
    }
}

public 
client_disconnectid )
{
    if ( !
g_bIgnorePlayerid ] )
    {
        
SaveDataid );
    }

    
arraysetg_pdDataid ][ PlayerData:] , sizeofg_pdData[] ) );
}

public 
SaveDataid 
{  
    
nvault_set_arrayzapis_vault g_szAuthIDid ] , g_pdDataid ][ PlayerData:] , sizeofg_pdData[] ) );


public 
LoadDataid )  
{  
    
nvault_get_arrayzapis_vault g_szAuthIDid ] , g_pdDataid ][ PlayerData:] , sizeofg_pdData[] ) );

__________________

Last edited by Bugsy; 02-09-2017 at 10:20.
Bugsy is offline
Gasior
Member
Join Date: Mar 2012
Old 02-09-2017 , 16:31   Re: How to save easier in nvault?
Reply With Quote #6

Thanks Bugsy, that's making my life so much easier.
Gasior is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode