AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   nVault plugin not working (https://forums.alliedmods.net/showthread.php?t=325272)

supertrio17 06-14-2020 20:37

nVault plugin not working
 
Hey, so I wanted to try and make a plugin with nVault, I followed this tutorial made by Bugsy, but I can't get it to work.

PHP Code:

#include <amxmodx> 
#include <amxmisc> 
#include <chatmanager>
#include <nvault>

#define FORMAT_SAY "format_admin"
#define FORMAT_TSAY "format_admin_team"

new g_iPrefix[33];
new 
g_Vault;
new 
g_szAuthID[33][35]; 

public 
plugin_init()
{
    
register_plugin("Proba Prefix""3.2""Mr. Boopsy");
    
register_clcmd("say /prefix",    "prefix_menu")
}

public 
plugin_cfg()
{
    
g_Vault nvault_open"yourvault" );

    if ( 
g_Vault == INVALID_HANDLE )
        
set_fail_state"Error opening nVault" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_putinserver(id)
{
    
LoadPrefix(id)
}

public 
prefix_menu(id)
{
    new 
menu menu_create("\r[\wChoose your Prefix\r]\r""menu_prefix")
    
    
menu_additem(menu"\wPLAYER""1"0)
    
menu_additem(menu"\wADMIN""2"0)
    
menu_additem(menu"\wOWNER""3"0)

    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
    
menu_display(idmenu0)
}

public 
menu_prefix(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    new 
data[6], iName[64]
    new 
accescallback
    menu_item_getinfo
(menuitemaccesdata,5iName63callback)
    
    new 
key str_to_num(data)
    
    
get_user_authid(idg_szAuthID[id], charsmax(g_szAuthID[]));

    switch(
key)
    { 
       case 
1
       {
            new 
szPrefix[30];
            new 
szKey[40];
            
cm_set_user_say_format(idFORMAT_SAYFORMAT_TSAY);
            
cm_set_user_prefix(id"[PLAYER]");
            
g_iPrefix[id] = 1;

            
formatex(szKeycharsmaxszKey ), "%sPREFIX"g_szAuthID[id]);
            
formatex(szPrefixcharsmaxszPrefix ), "%d"g_iPrefix[id]);
            
nvault_set(g_VaultszKeyszPrefix);
       }
       case 
2
       {
            new 
szPrefix[30];
            new 
szKey[40];
            
cm_set_user_say_format(idFORMAT_SAYFORMAT_TSAY);
            
cm_set_user_prefix(id"[ADMIN]");
            
g_iPrefix[id] = 2;

            
formatex(szKeycharsmaxszKey ), "%sPREFIX"g_szAuthID[id]);
            
formatex(szPrefixcharsmaxszPrefix ), "%d"g_iPrefix[id]);
            
nvault_set(g_VaultszKeyszPrefix);
       }
       case 
3:
       {
            new 
szPrefix[30];
            new 
szKey[40];
            
cm_set_user_say_format(idFORMAT_SAYFORMAT_TSAY);
            
cm_set_user_prefix(id"[OWNER]");
            
g_iPrefix[id] = 3;

            
formatex(szKeycharsmaxszKey ), "%sPREFIX"g_szAuthID[id]);
            
formatex(szPrefixcharsmaxszPrefix ), "%d"g_iPrefix[id]);
            
nvault_set(g_VaultszKeyszPrefix);
       }
    }
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED
}  

LoadPrefix(id)
{
    new 
szKey[40];
    
formatex(szKeycharsmaxszKey ), "%sPREFIX"g_szAuthID[id]);
    new 
iPrefix nvault_get(g_VaultszKey);

    switch(
iPrefix)
    { 
       case 
1
       {
            
cm_set_user_say_format(idFORMAT_SAYFORMAT_TSAY);
            
cm_set_user_prefix(id"[PLAYER]");
       }
       case 
2
       {
            
cm_set_user_say_format(idFORMAT_SAYFORMAT_TSAY);
            
cm_set_user_prefix(id"[ADMIN]");
       }
       case 
3:
       {
            
cm_set_user_say_format(idFORMAT_SAYFORMAT_TSAY);
            
cm_set_user_prefix(id"[OWNER]");
       }
    }   



Bugsy 06-14-2020 20:47

Re: nVault plugin not working
 
When the player first connects, LoadPrefix() is called which uses g_szAuthID[] to make the key to read from the vault. At that time, g_szAuthID[] is empty since you are not populating it until menu_prefix() is called.

supertrio17 06-14-2020 20:51

Re: nVault plugin not working
 
I tried it like this, I called the menu, choose the prefix I wanted, logout, logged back in, no prefix.

supertrio17 06-14-2020 21:05

Re: nVault plugin not working
 
Quote:

Originally Posted by Bugsy (Post 2705729)
When the player first connects, LoadPrefix() is called which uses g_szAuthID[] to make the key to read from the vault. At that time, g_szAuthID[] is empty since you are not populating it until menu_prefix() is called.

Oh okay, I just got what you said, so how do I fix that?

Bugsy 06-14-2020 21:08

Re: nVault plugin not working
 
Make sure g_szAuthID[] holds a valid value before you try to use it.

supertrio17 06-14-2020 21:13

Re: nVault plugin not working
 
How do I do that, sorry, I'm pretty newbie.

Bugsy 06-14-2020 21:18

Re: nVault plugin not working
 
Change
PHP Code:

public client_putinserver(id)
{
    
LoadPrefix(id)


to

PHP Code:

public client_authorizedid )
{
    
get_user_authid(idg_szAuthID[id], charsmax(g_szAuthID[]));
    
LoadPrefix(id)


And remove get_user_authid() in menu_prefix().

supertrio17 06-14-2020 21:23

Re: nVault plugin not working
 
Quote:

Originally Posted by Bugsy (Post 2705739)
Change
PHP Code:

public client_putinserver(id)
{
    
LoadPrefix(id)


to

PHP Code:

public client_authorizedid )
{
    
get_user_authid(idg_szAuthID[id], charsmax(g_szAuthID[]));
    
LoadPrefix(id)


And remove get_user_authid() in menu_prefix().

I did, and it still doesn't work. Any other ideas?

Bugsy 06-14-2020 21:36

Re: nVault plugin not working
 
What is not working specifically

supertrio17 06-14-2020 21:41

Re: nVault plugin not working
 
Quote:

Originally Posted by Bugsy (Post 2705742)
What is not working specifically

Well, I type /prefix in chat, it gives me my menu, I choose, and I get my prefix, but when I disconnect and join again, there is no prefix. I want to save my choice so when I get back I will have the prefix that I selected before.


All times are GMT -4. The time now is 17:14.

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