Raised This Month: $ Target: $400
 0% 

Nvault won't save or load


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 05-19-2012 , 11:35   Nvault won't save or load
Reply With Quote #1

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....
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 05-19-2012 , 11:40   Re: Nvault won't save or load
Reply With Quote #2

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.
__________________
xPaw is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 05-19-2012 , 12:50   Re: Nvault won't save or load
Reply With Quote #3

Quote:
replace_all(szData, 255, "#", " ")
This should be executed before calling parse(),
OK, I did it, but working like before, what next?
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-19-2012 , 14:52   Re: Nvault won't save or load
Reply With Quote #4

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) 
    }
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 05-19-2012 , 16:52   Re: Nvault won't save or load
Reply With Quote #5

nothing..
~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 05-19-2012 , 17:34   Re: Nvault won't save or load
Reply With Quote #6

Your code is totally wrong, I will fix when I get a minute.
__________________

Last edited by Bugsy; 05-19-2012 at 17:37.
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-19-2012 , 18:57   Re: Nvault won't save or load
Reply With Quote #7

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 );
    }

__________________

Last edited by Bugsy; 06-10-2012 at 11:25.
Bugsy is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 05-20-2012 , 05:49   Re: Nvault won't save or load
Reply With Quote #8

PHP Code:
enum MaxRaces
{
    
None,
    
a,
    
b,
    
c,
    
d

>>>>>

PHP Code:
#define MaxRaces 4

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

Possible?
~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 05-20-2012 , 14:21   Re: Nvault won't save or load
Reply With Quote #9

Remove "None" or change MaxRaces to 5 and that will work.
__________________

Last edited by Bugsy; 05-20-2012 at 14:22.
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-20-2012 , 14:46   Re: Nvault won't save or load
Reply With Quote #10

OIC, then just use the define and don't use the enum.
__________________
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 00:21.


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