AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Nvault won't save or load (https://forums.alliedmods.net/showthread.php?t=185593)

~Ice*shOt 05-19-2012 11:35

Nvault won't save or load
 
This is my nvault code

PHP Code:

public SaveData(id)
{
    new 
szIP[35]
    
get_user_ip(idszIP34)

    new 
szKey[64], szData[256]

    for (new 
RaceID 1RaceID MaxRacesRaceID++)
    {
        
format(szKey63"%s-xWar"szIP)
        
format(szData255"%i#%i#%i#"PlayerLevel[id][RaceID], PlayerXP[id][RaceID], PlayerPoints[id][RaceID])
    }
    
nvault_set(NvaultszKeyszData)
}

public 
LoadData(id)
{
    new 
szIP[35]
    
get_user_ip(idszIP34)

    new 
szKey[64], szData[256]

    
parse(szDataLevel31XP31Points31)

    new 
Level[32], XP[32], Points[32]

    for (new 
RaceID 1RaceID MaxRacesRaceID++)
    {
        
format(szKey63"%s-xWar"szIP)
        
format(szData255"%i#%i#%i#"PlayerLevel[id][RaceID], PlayerXP[id][RaceID], PlayerPoints[id][RaceID])

        
PlayerLevel[id][RaceID] = str_to_num(Level)
        
PlayerXP[id][RaceID] = str_to_num(XP)
        
PlayerPoints[id][RaceID] = str_to_num(Points)
    }
    
nvault_get(NvaultszKeyszData255)

    
replace_all(szData255"#"" ")


Why it don't works? It works when I reconnect in server, but if I change map or restart server nvault won't load my xp, level....

xPaw 05-19-2012 11:40

Re: Nvault won't save or load
 
Because parse() is used to parsed parameter-like strings. "1" "2" "3" and not 1#2#3. You tried to fix this but in wrong place:
replace_all(szData, 255, "#", " ")
This should be executed before calling parse(), or you should save your data in proper format.

~Ice*shOt 05-19-2012 12:50

Re: Nvault won't save or load
 
Quote:

replace_all(szData, 255, "#", " ")
This should be executed before calling parse(),
OK, I did it, but working like before, what next?

Liverwiz 05-19-2012 14:52

Re: Nvault won't save or load
 
try formating your szKey OUTSIDE of the for-loop, and initializing Level[], XP[], and Points[] BEFORE you parse into them.
Code:

new Level[32], XP[32], Points[32]  // placed here
parse(szData, Level, 31, XP, 31, Points, 31)

        // removed line
format(szKey, 63, "%s-xWar", szIP)  // placed here
    for (new RaceID = 1; RaceID < MaxRaces; RaceID++)
    {
            // removed line
        format(szData, 255, "%i#%i#%i#", PlayerLevel[id][RaceID], PlayerXP[id][RaceID], PlayerPoints[id][RaceID])

        PlayerLevel[id][RaceID] = str_to_num(Level)
        PlayerXP[id][RaceID] = str_to_num(XP)
        PlayerPoints[id][RaceID] = str_to_num(Points)
    }


~Ice*shOt 05-19-2012 16:52

Re: Nvault won't save or load
 
nothing.. :(

Bugsy 05-19-2012 17:34

Re: Nvault won't save or load
 
Your code is totally wrong, I will fix when I get a minute.

Bugsy 05-19-2012 18:57

Re: Nvault won't save or load
 
It would be better to provide your constants\vars\enums, since I didn't have these I created dummies.

PHP Code:

#include <amxmodx>
#include <nvault>

enum MaxRaces
{
    
None,
    
a,
    
b,
    
c,
    
d
}

new 
PlayerLevel33 ][ MaxRaces ];
new 
PlayerXP33 ][ MaxRaces ];
new 
PlayerPoints33 ][ MaxRaces ];
new 
Nvault;

const 
MaxNumberLen 5;

public 
plugin_init() 
{
    
register_plugin"Test" "0.1" "bugsy" );
    
    
Nvault nvault_open"blah" );
    
    
register_clcmd"say test" "TestData" );
    
register_clcmd"say save" "SaveData" );
    
register_clcmd"say load" "LoadData" );
    
register_clcmd"say show" "ShowData" );
}

public 
plugin_end()
{
    
nvault_closeNvault );
}

public 
TestDataid )
{
    for ( new 
MaxRaces:MaxRaces:MaxRaces i++ )
    {
        
PlayerLevelid ][ ] = random_num1000 );
        
PlayerXPid ][ ] = random_num1001 2000 );
        
PlayerPointsid ][ ] = random_num2001 3000 );
    }
}

public 
ShowDataid )
{
    
client_printid print_chat "%d %d %d / %d %d %d / %d %d %d / %d %d %d" 
        
PlayerLevelid ][ ],
        
PlayerXPid ][ ],
        
PlayerPointsid ][ ],
        
        
PlayerLevelid ][ ],
        
PlayerXPid ][ ],
        
PlayerPointsid ][ ],
        
        
PlayerLevelid ][ ],
        
PlayerXPid ][ ],
        
PlayerPointsid ][ ],

        
PlayerLevelid ][ ],
        
PlayerXPid ][ ],
        
PlayerPointsid ][ ] );
}
        
public 
SaveDataid )
{
    new 
szKey32 ] , szData[ ( ( MaxNumberLen ) * _:MaxRaces ) + ] , iLen iPos;
    
    
iLen get_user_ipid szKeycharsmaxszKey ) );
    
copyszKeyiLen ] , charsmaxszKey ) - iLen "-xWar" );
    
    for ( new 
MaxRaces:RaceID MaxRaces:RaceID MaxRaces RaceID++)
    {
        
iPos += formatexszDataiPos ] , charsmaxszData ) - iPos "%05d %05d %05d "PlayerLevel[id][RaceID], PlayerXP[id][RaceID], PlayerPoints[id][RaceID])
        
server_printszData );
    }
    
    
nvault_setNvault szKey szData );
}

public 
LoadData(id)
{
    new 
szKey32 ] , szData[ ( ( MaxNumberLen ) * _:MaxRaces ) + ] , iLen;
    new 
LevelMaxNumberLen ] , XPMaxNumberLen ] , PointsMaxNumberLen ];
    
    
iLen get_user_ipid szKeycharsmaxszKey ) );
    
copyszKeyiLen ] , charsmaxszKey ) - iLen "-xWar" );
    
    
nvault_getNvault szKey szData charsmaxszData ) );

    for ( new 
MaxRaces:RaceID MaxRaces:RaceID MaxRaces RaceID++ )
    {
        
parseszData[ ( _:RaceID ) * ( * ( MaxNumberLen ) ) ] , Level charsmaxLevel ) , XP charsmaxXP ), Points charsmaxPoints ) ); 
        
        
PlayerLevel[id][RaceID] = str_to_numLevel );
        
PlayerXP[id][RaceID] = str_to_numXP );
        
PlayerPoints[id][RaceID] = str_to_numPoints );
    }



~Ice*shOt 05-20-2012 05:49

Re: Nvault won't save or load
 
PHP Code:

enum MaxRaces
{
    
None,
    
a,
    
b,
    
c,
    
d


>>>>>

PHP Code:

#define MaxRaces 4

new const Races[MaxRaces][] =
{
    
"None",
    
"a",
    
"b",
    
"c",
    
"d"


Possible?

Liverwiz 05-20-2012 10:26

Re: Nvault won't save or load
 
Quote:

Originally Posted by ~Ice*shOt (Post 1712764)
PHP Code:

#define MaxRaces 4

new const Races[MaxRaces][] =
{
    
"None",
    
"a",
    
"b",
    
"c",
    
"d"


Possible?

no. you have 5 strings going into a 4-cell array.

Bugsy 05-20-2012 14:21

Re: Nvault won't save or load
 
Remove "None" or change MaxRaces to 5 and that will work.


All times are GMT -4. The time now is 00:20.

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