AlliedModders

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

~Ice*shOt 11-28-2014 16:10

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

fysiks 11-28-2014 16:32

Re: nVault
 
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")

~Ice*shOt 11-28-2014 17:00

Re: nVault
 
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.

fysiks 11-29-2014 03:50

Re: nVault
 
Why do you you need to loop through it? What does this array contain?

~Ice*shOt 11-29-2014 11:25

Re: nVault
 
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.

fysiks 11-29-2014 13:34

Re: nVault
 
You can make a loop to append a 1 or a 0 for each one.

~Ice*shOt 11-29-2014 13:45

Re: nVault
 
This is my attempt, is it okay? Will it save and load data correctly and is it the best way?

PHP Code:

public SaveData(id)
{
    new 
szData[16], szData2[32];
    new 
szKey[40];
 
    
formatex(szKeycharsmax(szKey), "%s-AuthID"g_szAuthID[id]);
    
formatex(szDatacharsmax(szData), "%i#%i#"g_iVar1[id], g_iVar2[id]);

    for (new 
0sizeof g_szSomethingi++)
        
formatex(szData2charsmax(szData2), "%i#"g_bTrue[id][i] ? 0);

    
nvault_set(g_VaultszKeyszData);
    
nvault_set(g_VaultszKeyszData2);
}

public 
LoadData(id)
{
    new 
szData[16], szData2[32];
    new 
szKey[40];
 
    
formatex(szKeycharsmax(szKey), "%s-AuthID"g_szAuthID[id]);
    
formatex(szDatacharsmax(szData), "%i#%i#"g_iVar1[id], g_iVar2[id]);

    for (new 
0sizeof g_szSomethingi++)
        
formatex(szData2charsmax(szData2), "%i#"g_bTrue[id][i] ? 0);

    
nvault_get(g_VaultszKeyszDatacharsmax(szData));
    
nvault_get(g_VaultszKeyszData2charsmax(szData2));

    
replace_all(szData255"#"" ")
    
replace_all(szData2255"#"" ")

    new 
szVar1[32], szVar2[32];
    
parse(szDataszVar1charsmax(szVar1), szVar2charsmax(szVar2));
 
    
g_iVar1[id] = str_to_num(szVar1);
    
g_iVar2[id] = str_to_num(szVar2);

    for (new 
0sizeof g_szSomethingi++)
    {
        new 
szTrue[32]
        
parse(szData2szTruecharsmax(szTrue));
 
        
g_bTrue[id][i] = str_to_num(szTrue);
    }



Bugsy 11-29-2014 15:28

Re: nVault
 
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.

~Ice*shOt 11-29-2014 16:54

Re: nVault
 
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.

Bugsy 11-29-2014 17:17

Re: nVault
 
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 ); 



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

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