Raised This Month: $51 Target: $400
 12% 

nVault Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MeliMeli
Senior Member
Join Date: Apr 2022
Location: Brazil
Old 02-27-2023 , 17:18   nVault Help
Reply With Quote #1

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.
MeliMeli is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 02-27-2023 , 18:06   Re: nVault Help
Reply With Quote #2

you can combine it with bits if you ever heard of it. it also depends how many weapons you got.
__________________
bigdaddy424 is offline
MeliMeli
Senior Member
Join Date: Apr 2022
Location: Brazil
Old 02-27-2023 , 18:43   Re: nVault Help
Reply With Quote #3

I would like an example please, I intend for 6 weapons.
MeliMeli is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-27-2023 , 19:06   Re: nVault Help
Reply With Quote #4

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?
__________________
Bugsy is offline
MeliMeli
Senior Member
Join Date: Apr 2022
Location: Brazil
Old 02-27-2023 , 19:12   Re: nVault Help
Reply With Quote #5

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)

Last edited by MeliMeli; 02-27-2023 at 19:12.
MeliMeli is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-27-2023 , 19:40   Re: nVault Help
Reply With Quote #6

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[] ) );

__________________
Bugsy is offline
MeliMeli
Senior Member
Join Date: Apr 2022
Location: Brazil
Old 02-27-2023 , 22:57   Re: nVault Help
Reply With Quote #7

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?
MeliMeli is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-28-2023 , 10:12   Re: nVault Help
Reply With Quote #8

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

Last edited by Bugsy; 02-28-2023 at 10:14.
Bugsy is offline
MeliMeli
Senior Member
Join Date: Apr 2022
Location: Brazil
Old 03-01-2023 , 15:05   Re: nVault Help
Reply With Quote #9

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?
MeliMeli is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-01-2023 , 18:36   Re: nVault Help
Reply With Quote #10

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"
}; 
__________________
Bugsy 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 05:41.


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