AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] nvault lookup (https://forums.alliedmods.net/showthread.php?t=278604)

indraraj striker 02-04-2016 07:39

[Solved] nvault lookup
 
1 Attachment(s)
About plugin
plugin is working well while saving and retrying at load and save but nvault lookup is not working it is not able to check the data is already exist or not
someone please help me

PHP Code:

#include <amxmodx>
#include <nvault>

#define PLUGIN "Test_lookup"
#define VERSION "1.0"
#define AUTHOR "26-{indra}"

new g_Vault;
new 
szName[33],szKey[10],Text[10];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("Enter_string","get_strings");
    
register_clcmd("say /test","testmenu");
}

public 
plugin_cfg()
{
    
g_Vault nvault_open"Test_lookup" );
}

public 
client_putinserver(id)
{
    
load_string(id);
}

public 
client_disconnect(id)
{
    
save_string(id);
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
testmenu(id)
{
    new 
menu menu_create("Enter a string""mh_testMenu");
    
menu_additem(menu"Enter a string"""0); 
    
menu_additem(menu"Submit """0);
    
menu_display(idmenu0);
}

public 
mh_testMenu(idmenuitem)
{
    switch(
item)
    {
        case 
0:
        {
            new 
szVal[10];
            new 
iExists,iTimestamp;
            
            
get_user_nameid ,  szName charsmaxszName ) );
            
iExists nvault_lookupg_Vault "szName" szVal charsmaxszVal ) , iTimestamp );  
            if(
iExists)
            {
                
client_print(id,print_chat,"This user already entered string")
            }
            else
            {
            
client_cmd(id"messagemode Enter_string");
            
testmenu(id)
            }
        }
        case 
1:
        {
            
client_print(idprint_chat,"Your string is saved");
            
save_string(id);
        }
    }
    
menu_destroy(menu);
}

public 
get_strings(id)
{
    
read_args(Textcharsmax(Text));
    
remove_quotes(Text);
    if(
equal(Text""))
      return 
PLUGIN_HANDLED;
    
client_print(id,print_chat,"the enter string is %s",Text);
    return 
PLUGIN_CONTINUE;
}


public 
load_string(id)
{
    
get_user_nameid ,  szName charsmaxszName ) );
    
formatexszKey charsmaxszKey ) , "%s-string",  szName );
    
nvault_getg_Vault szKey Text);
    
server_print("the data is retry %s",Text);
    return 
PLUGIN_CONTINUE;
}

public 
save_string(id)
{
    
get_user_nameid ,  szName charsmaxszName ) );
    
formatexszKey charsmaxszKey ) , "%s-string",  szName );
    
nvault_setg_Vault szKey Text );
    
server_print("the data is saved %s",Text);
    return 
PLUGIN_CONTINUE;



Bugsy 02-04-2016 07:57

Re: [help] nvault lookup
 
You're not using lookup on the same key that you are saving with.

Lookup=szName
Save=%s-string

indraraj striker 02-04-2016 08:05

Re: [help] nvault lookup
 
still having same problem
i changed save string to %s only

Bugsy 02-04-2016 08:24

Re: [help] nvault lookup
 
Reread my post.

Use szString in all places. They must match exactly.

I also did not check your menu functionality so there could be a problem there if this issue persists after fixing the mismatched keys.

Bugsy 02-04-2016 20:47

Re: [help] nvault lookup
 
I didn't review your entire code, only the nvault stuff.
Code:
public mh_testMenu(id, menu, item) {     switch(item)     {         case 0:         {             new szVal[10];             new iExists,iTimestamp;                         get_user_name( id ,  szName , charsmax( szName ) );                     //You forgot to do this:             formatex( szKey , charsmax( szKey ) , "%s-string",  szName )             iExists = nvault_lookup( g_Vault , szKey , szVal , charsmax( szVal ) , iTimestamp );               if(iExists)             {                 client_print(id,print_chat,"This user already entered string")             }             else             {             client_cmd(id, "messagemode Enter_string");             testmenu(id)             }         }         case 1:         {             client_print(id, print_chat,"Your string is saved");             save_string(id);         }     }     menu_destroy(menu); }

Make sure you have the same when you use nvault_get() and nvault_set() or else it will not work. These keys must be identical if you expect to be able to retrieve the data.
PHP Code:

public load_string(id)
{
    
get_user_nameid ,  szName charsmaxszName ) );
    
formatexszKey charsmaxszKey ) , "%s-string",  szName );
    
nvault_getg_Vault szKey Text);
    
server_print("the data is retry %s",Text);
    return 
PLUGIN_CONTINUE;
}

public 
save_string(id)
{
    
get_user_nameid ,  szName charsmaxszName ) );
    
formatexszKey charsmaxszKey ) , "%s-string",  szName );
    
nvault_setg_Vault szKey Text );
    
server_print("the data is saved %s",Text);
    return 
PLUGIN_CONTINUE;



indraraj striker 02-04-2016 23:31

Re: [help] nvault lookup
 
Finally, Today i learnt nvault_lookup
Thank you Bugsy sir


All times are GMT -4. The time now is 09:24.

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