Raised This Month: $ Target: $400
 0% 

[Solved] nvault lookup


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 02-04-2016 , 07:39   [Solved] nvault lookup
Reply With Quote #1

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;

Attached Files
File Type: sma Get Plugin or Get Source (test_lookup.sma - 602 views - 2.1 KB)
__________________
Thanks everyone. #miss_you_all

Last edited by indraraj striker; 02-04-2016 at 23:31.
indraraj striker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2016 , 07:57   Re: [help] nvault lookup
Reply With Quote #2

You're not using lookup on the same key that you are saving with.

Lookup=szName
Save=%s-string
__________________
Bugsy is offline
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 02-04-2016 , 08:05   Re: [help] nvault lookup
Reply With Quote #3

still having same problem
i changed save string to %s only
__________________
Thanks everyone. #miss_you_all
indraraj striker is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2016 , 08:24   Re: [help] nvault lookup
Reply With Quote #4

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.
__________________

Last edited by Bugsy; 02-04-2016 at 11:15.
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2016 , 20:47   Re: [help] nvault lookup
Reply With Quote #5

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;

__________________

Last edited by Bugsy; 02-04-2016 at 20:48.
Bugsy is offline
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 02-04-2016 , 23:31   Re: [help] nvault lookup
Reply With Quote #6

Finally, Today i learnt nvault_lookup
Thank you Bugsy sir
__________________
Thanks everyone. #miss_you_all
indraraj striker 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 09:24.


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