Raised This Month: $ Target: $400
 0% 

storing multiple values in nvault?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-27-2015 , 18:54   Re: storing multiple values in nvault?
Reply With Quote #7

My original plan was to store the values within 1 cell since there are 4 bytes to work with. This is useful if you are storing multiple booleans or multiple small value numbers. Play time can get high so this approach would not be good because you would probably need 16 bits just for play time alone, leaving only 16 for the remainder of the values. Also, it could be confusing unless you are familiar with bit operations.

Instead here is something easier. For this you will need nVault Utility
PHP Code:

#include <amxmodx>
#include <nvault_util>

new const Version[] = "0.1";

const 
MAXPLAYERS 32;
const 
TASK_DELAY_PRINT 34214;

enum _:PlayerStuff
{
    
Money,
    
Armor,
    
Credits,
    
PlayTime,
    
SteamID32 ]
}
new 
psPlayerDataMAXPLAYERS ][ PlayerStuff ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"nVault Array Example" Version "bugsy" );
    
    if ( ( 
g_Vault nvault_open"TestVault" ) ) == INVALID_HANDLE )
        
set_fail_state"Error opening vault" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    
get_user_authidid psPlayerDataid ][ SteamID ] , charsmaxpsPlayerData[] ) );
    
    
LoadDataid );
}

public 
client_disconnectid )
{
    
SaveDataid );
    
remove_taskid TASK_DELAY_PRINT );
    
    
arraysetpsPlayerDataid ] , sizeofpsPlayerData[] ) );
}

public 
SaveDataid )
{
    
//Test data
    
psPlayerDataid ][ Money ] = 15333;
    
psPlayerDataid ][ Armor ] = 100;
    
psPlayerDataid ][ Credits ] = 23132123;
    
psPlayerDataid ][ PlayTime ] = 664243;
    
    
nvault_set_arrayg_Vault psPlayerDataid ][ SteamID ] , psPlayerDataid ] , sizeofpsPlayerData[] ) );
}

public 
LoadDataid )
{
    new 
iTimeStamp;
    
    if ( 
nvault_get_arrayg_Vault psPlayerDataid ][ SteamID ] , psPlayerDataid ] , sizeofpsPlayerData[] ) , iTimeStamp ) )
    {
        
set_task7.0 "DelayPrint" id TASK_DELAY_PRINT );
    }
}

public 
DelayPrintid )
{
    
id -= TASK_DELAY_PRINT;
    
    
client_printid print_chat "Data loaded: Money=%d Armor=%d Credits=%d PlayTime=%d SteamID=%s" psPlayerDataid ][ Money ] ,
                                                             
psPlayerDataid ][ Armor ] ,
                                                             
psPlayerDataid ][ Credits ] ,
                                                             
psPlayerDataid ][ PlayTime ] ,
                                                             
psPlayerDataid ][ SteamID ] );

__________________

Last edited by Bugsy; 10-27-2015 at 18:56.
Bugsy is offline
 



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 18:13.


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