AlliedModders

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

MeliMeli 02-27-2023 17:18

nVault Help
 
People, can someone give me an example of how I can save something in nVault through a given value? I see a lot of using "i++" to save automatically but I would like to save it manually through certain values (if this is possible) example:

PHP Code:

if (g_M4A1_Black[id] & g_HasBlack[id])
    {
        
formatex(amenu,charsmax(amenu),"\yM4A1 Black \r[Selected]"
        
menu_additem(menuz,amenu,"1")

       }
       
       if (
g_M4A1_Rose[id] & g_HasRose[id])
    {
        
formatex(amenu,charsmax(amenu),"\yM4A1 Rose \r[Selected]"
        
menu_additem(menuz,amenu,"2")

       } 

Where (g_bM4A1_Black[id]) & if (g_M4A1_Rose[id] is a number different value that will be saved in nvault, I'm doing it manually

I'm doing this because of a cost definition of each weapon. If the player buys a weapon, it is saved in the nvault and you do not have to buy it again if you have it.

bigdaddy424 02-27-2023 18:06

Re: nVault Help
 
you can combine it with bits if you ever heard of it. it also depends how many weapons you got.

MeliMeli 02-27-2023 18:43

Re: nVault Help
 
I would like an example please, I intend for 6 weapons.

Bugsy 02-27-2023 19:06

Re: nVault Help
 
Why do you need 2 variables, M4A1_Black and HasBlack?

Why not just use 1 variable and set the variable to true if the player has black m4a1?

MeliMeli 02-27-2023 19:12

Re: nVault Help
 
Because 1 is to save in nVault and the other is to identify if the player has it selected as the current model. If you have a better way to define this, please explain to me, have you even seen the code I sent you? I really need your help for an in-depth understanding in nvault (it's my first time using)

Bugsy 02-27-2023 19:40

Re: nVault Help
 
Take a look at this and see if you can apply this in your plugin. This supports up to 32 weapons - add others to the WeaponBits and Weapons enumerators as needed.
PHP Code:


#include <amxmodx>
#include <nvault_array>

enum WeaponBits (<<=1)
{
    
wtBlack 1,
    
wtRose
}
enum Weapons
{
    
WeaponBlack 1,
    
WeaponRose
}
enum PlayerData
{
    
WeaponBits:PlayerWeapons,
    
Weapons:CurrentWeapon
}

new 
g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Vault;

#define AddWeapon(%1,%2)    g_pdData[%1][PlayerWeapons]|=%2    
#define RemoveWeapon(%1,%2)    g_pdData[%1][PlayerWeapons]&=~%2
    
public plugin_init() 
{
    
g_Vault nvault_open"testVault" );
    
    
register_clcmd"say /buyblack" "BuyBlack" );
    
register_clcmd"say /buyrose" "BuyRose" );
    
    
register_clcmd"say /setblack" "SetBlack" );
    
register_clcmd"say /setrose" "SetRose" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
BuyBlackid )
{
    if ( 
g_pdDataid ][ PlayerWeapons ] & wtBlack )
    {
        
client_printid print_chat "You already have Black" );
    }
    else
    {
        
AddWeaponid wtBlack );
        
client_printid print_chat "Black has been given" );
    }
}

public 
BuyRoseid )
{
    if ( 
g_pdDataid ][ PlayerWeapons ] & wtRose )
    {
        
client_printid print_chat "You already have Rose" );
    }
    else
    {
        
AddWeaponid wtRose );
        
client_printid print_chat "Rose has been given" );
    }
}

public 
SetBlackid )
{
    if ( 
g_pdDataid ][ PlayerWeapons ] & wtBlack )
    {
        if ( 
g_pdDataid ][ CurrentWeapon ] == WeaponBlack )
        {
            
client_printid print_chat "Black already set" );
        }
        else
        {
            
client_printid print_chat "Set to Black" );
            
g_pdDataid ][ CurrentWeapon ] = WeaponBlack;
        }
    }
    else
    {
        
client_printid print_chat "You do not have Black" );
    }
}

public 
SetRoseid )
{
    if ( 
g_pdDataid ][ PlayerWeapons ] & wtRose )
    {
        if ( 
g_pdDataid ][ CurrentWeapon ] == WeaponRose )
        {
            
client_printid print_chat "Rose already set" );
        }
        else
        {
            
client_printid print_chat "Set to Rose" );
            
g_pdDataid ][ CurrentWeapon ] = WeaponRose;
        }
    }
    else
    {
        
client_printid print_chat "You do not have Rose" );
    }
}

public 
client_authorizedid )
{
    new 
iTS;
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
nvault_get_arrayg_Vault g_szAuthIDid ] , g_pdDataid ][ PlayerData:] , sizeofg_pdData[] ) , iTS );
}

public 
client_disconnectedid )
{
    
nvault_set_arrayg_Vault g_szAuthIDid ] , g_pdDataid ][ PlayerData:] , sizeofg_pdData[] ) );



MeliMeli 02-27-2023 22:57

Re: nVault Help
 
So if I were to add new models I would have to edit:

PHP Code:

enum WeaponBits (<<=2)
{
    
wtBlack 1,
    
wtRose 2,
    
wtDefault
}

enum Weapons
{
    
WeaponBlack 1,
    
WeaponRose 2,
    
WeaponDefault
}

// What about this from here?
#define AddWeapon(%1,%2)    g_pdData[%1][PlayerWeapons]|=%2           // ?
#define RemoveWeapon(%1,%2)    g_pdData[%1][PlayerWeapons]&=~%2  // ? 

If I'm wrong, can you kindly tell me the right way?

Bugsy 02-28-2023 10:12

Re: nVault Help
 
I personally would do this, if you need a none/default option.
PHP Code:

enum WeaponBits (<<=1//don't ever change this regardless of # of types
{
    
wtDefault,
    
wtBlack,
    
wtRose
}

enum Weapons
{
    
WeaponDefault,
    
WeaponBlack,
    
WeaponRose


Add/Remove macros are how you set a player as having or not having a given weapon..

MeliMeli 03-01-2023 15:05

Re: nVault Help
 
Works perfectly, I managed to implement in my plugin, I have only a few questions, is it possible to implement for other weapons in the same plugin? could this cause some error?

Bugsy 03-01-2023 18:36

Re: nVault Help
 
You can do up to 31 weapons without messing anything up, just don't randomly change things and expect it to work, like you did above, for example: enum WeaponBits (<<=2)

To add more, this is all you need to do:
PHP Code:

enum WeaponBits (<<=1//don't ever change this regardless of # of types
{
    
wtDefault,
    
wtBlack,
    
wtRose,
    
wt4,
    
wt5,
    
wt6,
    
wt7,
    
wt8,
    
wt9,
    
wt10
}

enum Weapons
{
    
WeaponDefault,
    
WeaponBlack,
    
WeaponRose,
    
Weapon4,
    
Weapon5,
    
Weapon6,
    
Weapon7,
    
Weapon8,
    
Weapon9,
    
Weapon10


You can also do another array if you want to use printable names for each
PHP Code:

new const WeaponNamesWeapons ][] = 
{
    
"Default",
    
"Black",
    
"Rose",
    
"1",
    
"2",
    
"3",
    
"4",
    
"5",
    
"6",
    
"7",
    
"8",
    
"9",
    
"10"
}; 



All times are GMT -4. The time now is 10:23.

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