AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Saving data problem (https://forums.alliedmods.net/showthread.php?t=118047)

xbatista 02-07-2010 07:45

Saving data problem
 
It must print in end of the file '0 0#' but it prints '#0 0 0 0 0#0'
I tested this with Nvault Editor.
PHP Code:

iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d#",  g_iPlayerPotions[id][hero_id][iPotions], g_iPlayerPotionsInv[id][hero_id][iPotions] ) 


PHP Code:

Save_Data(id)
{
    new 
szKey[66];
    
Save_GetKeyidszKeycharsmaxszKey ) );

    new 
iLen 0;
    static 
szData[30000];
    
    
iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d#"g_PlayerChars[id], g_CurrentMana[id] );

    for(new 
hero_id 0hero_id MAX_CHARS hero_id++)
    {
        
iLen += formatex szDataiLen ], charsmax(szData) - iLen"%d %d %d %d %d %d %d %d %d %d %d %d#"g_PlayerLevel[id][hero_id], g_PlayerXp[id][hero_id], g_PlayerSkPoints[id][hero_id], g_PlayerStPoints[id][hero_id], g_Strength[id][hero_id], g_Dexterity[id][hero_id], g_Vitality[id][hero_id], g_Energy[id][hero_id], 
        
g_Coins[id][hero_id], g_CoinsInv[id][hero_id], g_PlayerHero[id][hero_id], g_PlayerCharActive[id][hero_id] )
    }    
    for( new 
iSkill 0iSkill <= g_skillcounteriSkill++ ) 
    {
        for(new 
hero_id 0hero_id MAX_CHARS hero_id++)
        {
            
iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d#"g_iSkills[id][hero_id][iSkill] );
        }    
    }
    for( new 
iItems 0iItems <= g_charcounter iItems++ )
    {
        for(new 
hero_id 0hero_id MAX_CHARS hero_id++)
        {
            
iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d %d %d %d#",  g_iPlayerItem[id][hero_id][iItems], g_iPlayerItemInv[id][hero_id][iItems], g_iPlayerItemBolts[id][hero_id][iItems], 
            
g_iPlayerItemWorn[id][hero_id][iItems], g_iPlayerItemRepair[id][hero_id][iItems] )
        }
    }
    for( new 
iPotions 0iPotions MAX_POTIONS iPotions++ )
    {
        for(new 
hero_id 0hero_id MAX_CHARS hero_id++)
        {
            
iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d#",  g_iPlayerPotions[id][hero_id][iPotions], g_iPlayerPotionsInv[id][hero_id][iPotions] )
        }    
    }
    
    
nvault_setg_NvaultszKeyszData );



Bugsy 02-07-2010 09:34

Re: Saving data problem
 
Quote:

Originally Posted by xbatista (Post 1081427)
It must print in end of the file '0 0#' but it prints '#0 0 0 0 0#0'

I'm a bit confused, are you saying you are only supposed to be saving "0 0#" but "#0 0 0 0 0#0" is getting saved? Or are you just referring to the end portion "0#" vs "0#0"?

See if the below works or you can just trim off the trailing zero if you can confirm it isn't storing any data.

PHP Code:

iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d%s",  g_iPlayerPotions[id][hero_id][iPotions], g_iPlayerPotionsInv[id][hero_id][iPotions] , "#" 


xbatista 02-07-2010 09:38

Re: Saving data problem
 
I mean at the end of the vault file is '#0 0 0 0 0#0' , why not '0 0#' ?
In my code is '%d %d#' at the end of iLen

Bugsy 02-07-2010 09:41

Re: Saving data problem
 
Before saving, make sure a number is stored in the very last-written g_iPlayerPotionsInv[id][hero_id][iPotions] and see if that ends up in your vault entry.

xbatista 02-07-2010 09:45

Re: Saving data problem
 
1 Attachment(s)
Yes it's stored

EDIT : End of entry

Bugsy 02-07-2010 10:07

Re: Saving data problem
 
Try using a delimiter other then # and see if you get the same result.

Sylwester 02-07-2010 10:08

Re: Saving data problem
 
Try this and see if the end is still incorrect. Maybe there is some length limit and it's cutting off some part of the string.
PHP Code:

Save_Data(id)
{
    new 
szKey[66];
    
Save_GetKeyidszKeycharsmaxszKey ) );

    new 
iLen 0;
    static 
szData[30000];
    
/*
    iLen += formatex( szData[ iLen ], charsmax(szData) - iLen, "%d %d#", g_PlayerChars[id], g_CurrentMana[id] );
     
    for(new hero_id = 0; hero_id < MAX_CHARS + 1 ; hero_id++)
    {
        iLen += formatex ( szData[ iLen ], charsmax(szData) - iLen, "%d %d %d %d %d %d %d %d %d %d %d %d#", g_PlayerLevel[id][hero_id], g_PlayerXp[id][hero_id], g_PlayerSkPoints[id][hero_id], g_PlayerStPoints[id][hero_id], g_Strength[id][hero_id], g_Dexterity[id][hero_id], g_Vitality[id][hero_id], g_Energy[id][hero_id], 
        g_Coins[id][hero_id], g_CoinsInv[id][hero_id], g_PlayerHero[id][hero_id], g_PlayerCharActive[id][hero_id] )
    }    
    for( new iSkill = 0; iSkill <= g_skillcounter; iSkill++ ) 
    {
        for(new hero_id = 0; hero_id < MAX_CHARS + 1 ; hero_id++)
        {
            iLen += formatex( szData[ iLen ], charsmax(szData) - iLen, "%d#", g_iSkills[id][hero_id][iSkill] );
        }    
    }
    for( new iItems = 0; iItems <= g_charcounter ; iItems++ )
    {
        for(new hero_id = 0; hero_id < MAX_CHARS + 1 ; hero_id++)
        {
            iLen += formatex( szData[ iLen ], charsmax(szData) - iLen, "%d %d %d %d %d#",  g_iPlayerItem[id][hero_id][iItems], g_iPlayerItemInv[id][hero_id][iItems], g_iPlayerItemBolts[id][hero_id][iItems], 
            g_iPlayerItemWorn[id][hero_id][iItems], g_iPlayerItemRepair[id][hero_id][iItems] )
        }
    }*/
    
for( new iPotions 0iPotions MAX_POTIONS iPotions++ )
    {
        for(new 
hero_id 0hero_id MAX_CHARS hero_id++)
        {
            
iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d#",  g_iPlayerPotions[id][hero_id][iPotions], g_iPlayerPotionsInv[id][hero_id][iPotions] )
        }    
    }
    
    
nvault_setg_NvaultszKeyszData );



xbatista 02-07-2010 10:14

Re: Saving data problem
 
1 Attachment(s)
Quote:

Originally Posted by Sylwester (Post 1081583)
Try this and see if the end is still incorrect. Maybe there is some length limit and it's cutting off some part of the string.
PHP Code:

Save_Data(id)
{
    new 
szKey[66];
    
Save_GetKeyidszKeycharsmaxszKey ) );

    new 
iLen 0;
    static 
szData[30000];
    
/*
    iLen += formatex( szData[ iLen ], charsmax(szData) - iLen, "%d %d#", g_PlayerChars[id], g_CurrentMana[id] );
     
    for(new hero_id = 0; hero_id < MAX_CHARS + 1 ; hero_id++)
    {
        iLen += formatex ( szData[ iLen ], charsmax(szData) - iLen, "%d %d %d %d %d %d %d %d %d %d %d %d#", g_PlayerLevel[id][hero_id], g_PlayerXp[id][hero_id], g_PlayerSkPoints[id][hero_id], g_PlayerStPoints[id][hero_id], g_Strength[id][hero_id], g_Dexterity[id][hero_id], g_Vitality[id][hero_id], g_Energy[id][hero_id], 
        g_Coins[id][hero_id], g_CoinsInv[id][hero_id], g_PlayerHero[id][hero_id], g_PlayerCharActive[id][hero_id] )
    }    
    for( new iSkill = 0; iSkill <= g_skillcounter; iSkill++ ) 
    {
        for(new hero_id = 0; hero_id < MAX_CHARS + 1 ; hero_id++)
        {
            iLen += formatex( szData[ iLen ], charsmax(szData) - iLen, "%d#", g_iSkills[id][hero_id][iSkill] );
        }    
    }
    for( new iItems = 0; iItems <= g_charcounter ; iItems++ )
    {
        for(new hero_id = 0; hero_id < MAX_CHARS + 1 ; hero_id++)
        {
            iLen += formatex( szData[ iLen ], charsmax(szData) - iLen, "%d %d %d %d %d#",  g_iPlayerItem[id][hero_id][iItems], g_iPlayerItemInv[id][hero_id][iItems], g_iPlayerItemBolts[id][hero_id][iItems], 
            g_iPlayerItemWorn[id][hero_id][iItems], g_iPlayerItemRepair[id][hero_id][iItems] )
        }
    }*/
    
for( new iPotions 0iPotions MAX_POTIONS iPotions++ )
    {
        for(new 
hero_id 0hero_id MAX_CHARS hero_id++)
        {
            
iLen += formatexszDataiLen ], charsmax(szData) - iLen"%d %d#",  g_iPlayerPotions[id][hero_id][iPotions], g_iPlayerPotionsInv[id][hero_id][iPotions] )
        }    
    }
    
    
nvault_setg_NvaultszKeyszData );



So what I must do now? ^^

xPaw 02-07-2010 10:14

Re: Saving data problem
 
static szData[30000];
wtf ? O_o"

xbatista 02-07-2010 10:19

Re: Saving data problem
 
Quote:

Originally Posted by xPaw (Post 1081587)
static szData[30000];
wtf ? O_o"

What? ^^
You said that if I'll use 'new' it will print error in log, btw I use this to save large data


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

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