Raised This Month: $ Target: $400
 0% 

nVault


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-28-2014 , 16:10   nVault
Reply With Quote #1

I have this vault and I need to add one more saving, it's bool variable: g_bTrue[][]. Here is what I have

PHP Code:
new const g_szSomething[][] =
{
      
"First",
      
"Second",
      
"Third"
      
// etc.
};

new 
boolg_bTrue[33][sizeof g_szSomething]; // NEED TO ADD THIS IN SAVE AND LOAD FUNCTIONS
 
new g_iVar1[33];
new 
g_iVar2[33];
 
public 
SaveData(id)
{
    new 
szData[16];
    new 
szKey[40];
 
    
formatex(szKeycharsmax(szKey), "%s-AuthID"g_szAuthID[id]);
    
formatex(szDatacharsmax(szData), "%i#%i#"g_iVar1[id], g_iVar2[id]);
 
    
nvault_set(g_VaultszKeyszData);
}
 
public 
LoadData(id)
{
    new 
szData[16];
    new 
szKey[40];
 
    
formatex(szKeycharsmax(szKey), "%s-AuthID"g_szAuthID[id]);
    
formatex(szDatacharsmax(szData), "%i#%i#"g_iVar1[id], g_iVar2[id]);
 
    
nvault_get(g_VaultszKeyszDatacharsmax(szData));
 
    
replace_all(szData255"#"" ")
 
    new 
szVar1[32], szVar2[32];
    
parse(szDataszVar1charsmax(szVar1), szVar2charsmax(szVar2));
 
    
g_iVar1[id] = str_to_num(szVar1);
    
g_iVar2[id] = str_to_num(szVar2);

I am asking for a help because my knowledge of nvault is very low.

Last edited by ~Ice*shOt; 11-28-2014 at 16:11.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-28-2014 , 16:32   Re: nVault
Reply With Quote #2

Simply format it into your data string by converting it to a string like so:

Code:
bBooleanVariable ? "1" : "0"
or

Code:
bBooleanVariable ? "true" : "false"
then something like this:
Code:
format(szData, charsmax(szData), "%s %s %s", szString, szString, bBooleanVariable ? "1" : "0")
__________________

Last edited by fysiks; 11-28-2014 at 16:32.
fysiks is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-28-2014 , 17:00   Re: nVault
Reply With Quote #3

Yes, I understand. But what about formating data, should I create new formatex line? and new string near

PHP Code:
new szData[16]; 
Sth like

PHP Code:
new szData[16], szData2[32]; 
Because I'll need a loop through g_bTrue[id][i], that place which I didn't understand at all.

Last edited by ~Ice*shOt; 11-28-2014 at 17:01.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-29-2014 , 03:50   Re: nVault
Reply With Quote #4

Why do you you need to loop through it? What does this array contain?
__________________
fysiks is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-29-2014 , 11:25   Re: nVault
Reply With Quote #5

It contains g_szSomething

PHP Code:
new const g_szSomething[][] =
{
      
"First",
      
"Second",
      
"Third"
      
// etc.
};

new 
boolg_bTrue[33][sizeof g_szSomething]; 
For example it can be like

Quote:
First = true
Second = false
Third = true
That's why.

Last edited by ~Ice*shOt; 11-29-2014 at 11:26.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-29-2014 , 13:34   Re: nVault
Reply With Quote #6

You can make a loop to append a 1 or a 0 for each one.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-29-2014 , 15:28   Re: nVault
Reply With Quote #7

Are you just trying to save a list of boolean settings? If so, you can accomplish this with a single bit-field. With this, the saved data will appear as a random integer "234343" in nvault and not plain english "setting1:0#setting2:4".

If this isn't what you have in mind, explain what you're trying to do in english instead of code.
__________________

Last edited by Bugsy; 11-29-2014 at 15:28.
Bugsy is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-29-2014 , 16:54   Re: nVault
Reply With Quote #8

Yes I'm trying to save a list of bools, some of them can be true and other will be false, so I need to save and load them correctly and in the best way Added this in to my first post's code would be great When I make some bools (from the g_szSomething) true and reconnect I want to see them true.

Last edited by ~Ice*shOt; 11-29-2014 at 16:57.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-29-2014 , 17:17   Re: nVault
Reply With Quote #9

From this tut: https://forums.alliedmods.net/showthread.php?t=139916

PHP Code:
#define MAX_PLAYERS    32

//Create a list of options that are supported by the plugin
enum ( <<=_Options
{
    
Speed=1// 1 << 0 or 1 
    
AutoAim,  // 1 << 1 or 1 << 1 (as value is calculated by enum)        
    
HighJump// 1 << 2 or 2 << 1
    
ExtraHP,   // 1 << 3 or 4 << 1
    
ExtraArmor // 1 << 4 or 8 << 1
}

//Define an array that will keep track of each option a player currently has
new g_OptionsMAX_PLAYERS+];

//Examples of how to apply option for player
g_Optionsid ] |= Speed;
g_Optionsid ] |= HighJump;
g_Optionsid ] |= ExtraArmor;

//Examples of how to remove option for player
g_Optionsid ] &= ~Speed;
g_Optionsid ] &= ~HighJump;
g_Optionsid ] &= ~ExtraArmor;

//Example how to check if a player has an option
if ( g_Optionsid ] & Speed )
    
//player has speed 
To load and save player booleans (untested):
PHP Code:
//To save:
new szData15 ];
num_to_strg_Optionsid ] , szData charsmaxszData ) );
nvault_setg_VaultID szKey szData );

//To load:
g_Optionsid ] = nvault_getg_VaultID szKey ); 
__________________

Last edited by Bugsy; 11-29-2014 at 17:18.
Bugsy is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 11-29-2014 , 17:26   Re: nVault
Reply With Quote #10

Sorry, but if I have more than 20 choices (so 20 bools in g_bTrue) it is a little bit a lot of writing with your way, isn't it?

Last edited by ~Ice*shOt; 11-29-2014 at 17:26.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
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 17:41.


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