AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   nVault Tutorial (https://forums.alliedmods.net/showthread.php?t=91503)

Nextra 05-02-2009 15:36

Re: nVault
 
Quote:

Originally Posted by Bugsy (Post 819582)
Even if querying isn't a problem for you it could still be overkill depending on what you are storing. If you are only storing a single item and only need to retrieve it based on a single key then it is a waste of CPU to use SQL. Whatever floats your boat though. :grrr:

Of course. As I said: If it's uncomplex or temporary data I wouldn't bother doing a SQL-implementation.

Bugsy 05-02-2009 16:20

Re: nVault
 
Thanks Exolent for catching the typo. +k

Bugsy 05-25-2009 11:33

Re: nVault
 
Made corrections to example plugin. There were a few minor typo's and added required modules to make it compile via copy and paste.

Dygear 01-14-2010 00:03

Re: nVault
 
If you could add a function to return just the timestamp for a vault key that would be great.

Code:
nvault_timestamp(vault, key[]); // Finds when the item was last touched.

Also, it would be awesome it we could write as to the save to the vault in the same data type that it was intended to be in.

Exolent[jNr] 01-14-2010 00:39

Re: nVault
 
Code:
stock nvault_timestamp(const vault, const key[]) {     static data[2], timestamp;     return nvault_lookup(vault, key, data, charsmax(data), timestamp) ? timestamp : 0; }

r4ndomz 02-21-2010 09:56

Re: nVault
 
Thanks for the tut!

tm. 04-22-2010 02:26

Re: nVault
 
Thanks for the tutorial, it has been useful for me.
Quote:

Originally Posted by fysiks (Post 819100)
Would there be file access issues if you tried to access a single nVault from two plugins? Just curious really.

Same question.
And how many entries is to much for nvault?

Seta00 04-22-2010 16:08

Re: nVault
 
Quote:

Originally Posted by fysiks (Post 819100)
Would there be file access issues if you tried to access a single nVault from two plugins?

File access protection is based on the process, and there's only one process accessing all the vaults: hl.exe, so no problems.

Of course there's the problem two or more threads can't write to one file at the same time, but this isn't an issue, since AMXx runs on a single thread.

fysiks 04-22-2010 16:35

Re: nVault
 
Yeah, I figured that was the case.

NiHiLaNTh 08-18-2010 13:32

Re: nVault
 
Can anyone help me with storing multiple data.
Code:

#include < amxmodx >
#include < nvault >

new g_iVaultID
new g_szSteamID[ 33 ][ 34 ]
new g_iData[ 33 ]
new g_iData2[ 33 ]
new g_iData3[ 33 ]
new g_iData4[ 33 ]
new g_iData5[ 33 ]
new g_iData6[ 33 ]

public plugin_init( )
{
    register_plugin( "Shit", "Crap", "Lol" )
   
    register_clcmd( "say /show", "fn_Show" )
    register_clcmd( "say /save", "fn_Save" )
}

public plugin_end( )
{
    nvault_close( g_iVaultID )
}

public plugin_cfg( )
{
    g_iVaultID = nvault_open( "test_vault" )
   
    if( g_iVaultID == INVALID_HANDLE )
    {
        set_fail_state( "Error opening Test Nvault" )
    }
}

public client_putinserver( Player )
{
    get_user_authid( Player, g_szSteamID[ Player ], charsmax( g_szSteamID[ ] ) )
   
    Load_Stuff( Player )
}

public fn_Show( Player )
{
    client_print( Player, print_chat, "Data1: %d; Data2: %d; Data3: %d; Data4: %d; Data5:%d; Data6: %d", g_iData[ Player ], g_iData2[ Player ], g_iData3[ Player ], g_iData4[ Player ], g_iData5[ Player ], g_iData6[ Player ] )
}

public fn_Save( Player )
{
    new szSteamID[ 34 ]
    formatex( szSteamID, charsmax( szSteamID ), "%sTEST", g_szSteamID[ Player ] )
   
    g_iData[ Player ] = random_num( 0, 200 )
    g_iData2[ Player ] = random_num( 201, 400 )
    g_iData3[ Player ] = random_num( 401, 600 )
    g_iData4[ Player ] = random_num( 601, 800 )
    g_iData5[ Player ] = random_num( 801, 999 )
    g_iData6[ Player ] = random_num( 1000, 1099 )
   
    new szData[ 50 ]
    formatex( szData, charsmax( szData ), "%d %d %d %d %d %d", g_iData[ Player ], g_iData2[ Player ], g_iData3[ Player ], g_iData4[ Player ], g_iData5[ Player ], g_iData6[ Player ] )
   
    nvault_set( g_iVaultID, szSteamID, szData )
   
    client_print( Player, print_chat, "Data1: %d; Data2: %d; Data3: %d; Data4: %d; Data5:%d; Data6: %d", g_iData[ Player ], g_iData2[ Player ], g_iData3[ Player ], g_iData4[ Player ], g_iData5[ Player ], g_iData6[ Player ]  )
}

Load_Stuff( Player )
{
    new szData[ 50 ], szSteamID[ 34 ]
    formatex( szSteamID, charsmax( szSteamID ), "%sTEST", g_szSteamID[ Player ] )
   
    if( nvault_get( g_iVaultID, szSteamID, szData, 49 ) )
    {
        new iSpacePos = contain( szData, " " )
       
        if( iSpacePos > -1 )
        {
            new szData1[ 4 ], szData2[ 4 ], szData3[ 4 ], szData4[ 4 ], szData5[ 4 ], szData6[ 5 ]
            formatex( szData1, iSpacePos, "%s", szData )
            formatex( szData2, 3, "%s", szData[ iSpacePos + 1 ] )
            formatex( szData3, 3, "%s", szData2[ iSpacePos + 1 ] )
            formatex( szData4, 3, "%s", szData3[ iSpacePos + 1 ] )
            formatex( szData5, 3, "%s", szData4[ iSpacePos + 1 ] )
            formatex( szData6, 4, "%s", szData5[ iSpacePos + 1 ] )
           
           
            g_iData[ Player ] = str_to_num( szData1 )
            g_iData2[ Player ] = str_to_num( szData2 )
            g_iData3[ Player ] = str_to_num( szData3 )
            g_iData4[ Player ] = str_to_num( szData4 )
            g_iData5[ Player ] = str_to_num( szData5 )
            g_iData6[ Player ] = str_to_num( szData6 )
        }
    }
}

I dont why, but g_iData[ ] values all the time are 0. :(


All times are GMT -4. The time now is 20:52.

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