AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save and Load Problems (nVault) (https://forums.alliedmods.net/showthread.php?t=143820)

GXLZPGX 11-25-2010 10:15

Save and Load Problems (nVault)
 
Alright, so here's the basic problem:

When there's no vault file, I can change the map, and it will work perfectly fine, but if someone kills someone, and it saves something to the vault, and I change the map, it crashes. What could possibly be the problem?

PHP Code:

public Save_Data(id)  
{  
    new 
AuthID[35
    
get_user_authid(id,AuthID,34
    
    new 
vaultkey[64], vaultdata[256
    
    if(
pub_Class[id] == WARRIOR)
    {
        
formatex(vaultkey,63,"%s-xp-%i-class",AuthIDWARRIOR)
    }
    else
    {
        
formatex(vaultkey,63,"%s-xp-%i-class",AuthIDASSASSIN);
    }
    
    
formatex(vaultdata254"%i#%i#%i#%i#%i#%i"pub_Stats[id][EXP], 
        
pub_Stats[id][LVL], pub_Stats[id][AGILITY], pub_Stats[id][TRANSPARENCY],
        
pub_Stats[id][STRENGTH], pub_Stats[id][HEALTH]
    );
    
    
nvault_set(g_Vaultvaultkeyvaultdata);
    
    
formatex(vaultkeycharsmax(vaultkey), "%s-stats"AuthID);
    
nvault_set(g_Vaultvaultkeypub_Stats[id][STATSCOUNT]);
}

public 
Load_Data(id

    new 
AuthID[35
    
get_user_authid(id,AuthID,34
    
    new 
vaultkey[64];
    
formatex(vaultkey,63,"%s-xp-%i-class",AuthIDpub_Class[id]) 
    
    new 
Data[256]
    
nvault_get(g_VaultvaultkeyDatacharsmax(Data));
    
replace_all(Datacharsmax(Data), "#"" ");
    
    new 
exp[10], lvl[10], agi[10], trans[10], str[10], health[10];
    
parse(Dataexpcharsmax(exp), lvlcharsmax(lvl), agicharsmax(agi),
        
transcharsmax(trans), strcharsmax(str), healthcharsmax(health)
    );
    
    
pub_Stats[id][EXP] = str_to_num(exp);
    
pub_Stats[id][LVL] = str_to_num(lvl);
    
pub_Stats[id][AGILITY] = str_to_num(agi);
    
pub_Stats[id][TRANSPARENCY] = str_to_num(trans);
    
pub_Stats[id][STRENGTH] = str_to_num(str);
    
pub_Stats[id][HEALTH] = str_to_num(health);
    
    
formatex(vaultkeycharsmax(vaultkey), "%s-stats"AuthID);
    
pub_Stats[id][STATSCOUNT] = nvault_get(g_Vaultvaultkey);


Some possibly useful information:
-The nVault is closed at plugin_end()
-The nVault only loads data when the person joins a team

Bugsy 11-25-2010 10:18

Re: Save and Load Problems (nVault)
 
nvault_set(g_Vault, vaultkey, pub_Stats[id][STATSCOUNT]);

Looks like here you are attempting to write an integer value? If so you must first convert to string.

GXLZPGX 11-25-2010 10:20

Re: Save and Load Problems (nVault)
 
Quote:

Originally Posted by Bugsy (Post 1356360)
nvault_set(g_Vault, vaultkey, pub_Stats[id][STATSCOUNT]);

Looks like here you are attempting to write an integer value? If so you must first convert to string.

Yes, it's an integer, thank you very much, I'll compile and try it.

PHP Code:

new Stats[63];
num_to_str(pub_Stats[id][STATSCOUNT], Statscharsmax(Stats) )
nvault_set(g_VaultvaultkeyStats); 

Correct?

Bugsy 11-25-2010 10:24

Re: Save and Load Problems (nVault)
 
Yes, but the number cannot possibly be that big (62 digits), reduce the string size to a realistic number. If you still get errors then maybe your vault file is corrupt, try shutting down your server, delete vault file, and restart.

GXLZPGX 11-25-2010 10:52

Re: Save and Load Problems (nVault)
 
Quote:

Originally Posted by Bugsy (Post 1356368)
Yes, but the number cannot possibly be that big (62 digits), reduce the string size to a realistic number. If you still get errors then maybe your vault file is corrupt, try shutting down your server, delete vault file, and restart.

Thats true. I was just keeping possibilities up, so if for any reason it got to a huge number like that, I wouldn't have problems.

Bugsy 11-25-2010 12:21

Re: Save and Load Problems (nVault)
 
You are limited to a 32-bit signed integer in Pawn (without considering any memory trickery) so the max number of digits you will encounter is 10, plus 1 to make room for the sign if negative plus one for null char so you can safely size the number string at 12.

Values storable in a 32-bit signed int are -2,147,483,647 to 2,147,483,647 which should be plenty.

GXLZPGX 11-25-2010 22:26

Re: Save and Load Problems (nVault)
 
Quote:

Originally Posted by Bugsy (Post 1356449)
You are limited to a 32-bit signed integer in Pawn (without considering any memory trickery) so the max number of digits you will encounter is 10, plus 1 to make room for the sign if negative plus one for null char so you can safely size the number string at 12.

Values storable in a 32-bit signed int are -2,147,483,647 to 2,147,483,647 which should be plenty.

More than plenty. Thank you!


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

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