Raised This Month: $51 Target: $400
 12% 

Solved Parsing vaultdata properly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 10-12-2017 , 03:15   Parsing vaultdata properly
Reply With Quote #1

Greetings,

I can't seem to get my vaultdata to parse properly for a Pokemod Auction House plugin.

Vault Information
Vaultkey is stored as (AUCTIONS-%d), ex. (AUCTIONS-1).
Vaultdata is stored as 191 1 ; 1507788754 ; 0 0 ; iMiNDFREAK ; STEAM_0:0:12345678 ; 25000
(191 1 means a pokemon #191 level 1, 1507788754 is the timestamp, 0 0 is just a double zero added for a formatting reason, iMiNDFREAK is the player name, STEAM ID is steam ID, the 25000 at the end is the price).

CODE :
PHP Code:
public LoadAuctions()
{
    if( 
g_iEmpty != )
        
g_iEmpty = -1
    
new vaultkey[64],vaultdata[256], timestamp;
    new 
parsedsteamid[35],parsedname[32],parsedzero[8],parsedtimestamp[12],parsedpoke[8],parsedlevel[8], parsedprice[9]
    
    for( new 
1MAX_AUCTIONSi++ )
    {
        
format(vaultkey,63,"AUCTIONS-%d"i);
        if( 
nvault_lookup(recordvaultkeyvaultdata255timestamp) )
        {
            
nvault_get(record,vaultkey,vaultdata,255);
            if( 
equalivaultdata"" ) )
            {
                if( 
g_iEmpty == || g_iEmpty == -)
                    
g_iEmpty i
            
}
            else
            {
                
replace_all(vaultdata255";"" ")
                
parse

(vaultdata,parsedpoke,7,parsedlevel,7,parsedtimestamp,11,parsedzero,7,parsedname,31,parsedsteamid,34,parsedprice8)
                
g_iPoke] = str_to_numparsedpoke )
                
g_iPrice] = str_to_numparsedprice )
                
g_iLevel] = str_to_numparsedlevel )
                
g_iTimestamp] = str_to_num parsedtimestamp )

                
formatexg_iDoubleZero], 8"%s",parsedzero )
                
formatexg_szSteamid], 35"%s",parsedsteamid )
                
formatexg_szPlayername], 32"%s",parsedname )
            }
        }
        else if( 
g_iEmpty == || g_iEmpty == -)
            
g_iEmpty i
    
}

Thank you for your help everyone!

EDIT: Solved - See Last Post!
__________________
BeastGaming Community - Map Maker & Coder.

Last edited by imindfreak; 10-14-2017 at 02:39.
imindfreak is offline
GrimmReaper
Junior Member
Join Date: Oct 2017
Location: Name's the Clue
Old 10-12-2017 , 08:35   Re: [HELP] Dynamically populate a menu from nvault
Reply With Quote #2

Use enums it's easier.
Exolentnjr's tutorial here
__________________
Add Me On Steam
GrimmReaper is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-12-2017 , 11:24   Re: [HELP] Dynamically populate a menu from nvault
Reply With Quote #3

The code you posted doesn't even compile. Can't test it.
Black Rose is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 10-12-2017 , 15:40   Re: [HELP] Dynamically populate a menu from nvault
Reply With Quote #4

Quote:
Originally Posted by imindfreak View Post
1. In ShowAuctions menu, all Pokemon in the menu listing have a price of 0. This value is stored in g_iPrice but for some reason always shows 0.
Looking at the code, I think I found your fault for this problem. This is your vault data string:
Code:
191 1 ; 1507788754 ; 0 0 ; iMiNDFREAK ; STEAM_0:0:12345678 ; 25000
When you replace ; with space you get this:
Code:
191 1   1507788754   0 0   iMiNDFREAK   STEAM_0:0:12345678   25000
and parsedzero string will be only the first zero, parsedname will be 2nd zero and so on...

I decided to make a little test. Here is the test code:
Code:
new vaultdata[256] = "191 1 ; 1507788754 ; 0 0 ; iMiNDFREAK ; STEAM_0:0:12345678 ; 25000"; replace_all(vaultdata, 255, ";", " "); server_print("Replaced string: { %s }", vaultdata);     new arg1[8],arg2[8],arg3[12],arg4[8],arg5[32],arg6[35],arg7[9]; parse(vaultdata,arg1,7,arg2,7,arg3,11,arg4,7,arg5,31,arg6,34,arg7, 8);     server_print("#: %s", arg1); server_print("Level: %s", arg2); server_print("Timestamp: %s", arg3); server_print("Zeros: %s", arg4); server_print("Player Name: %s", arg5); server_print("Player SteamID: %s", arg6); server_print("Price: %s", arg7);
and the result:
Code:
Replaced string: { 191 1   1507788754   0 0   iMiNDFREAK   STEAM_0:0:12345678   25000 }
#: 191
Level: 1
Timestamp: 1507788754
Zeros: 0
Player Name: 0
Player SteamID: iMiNDFREAK
Price: STEAM_0:
To fix this actually you need to add quotes to zeros and SteamID:
Code:
"191 1 ; 1507788754 ; ^"0 0^" ; iMiNDFREAK ; ^"STEAM_0:0:12345678^" ; 25000"
and the result:
Code:
Replaced string: { 191 1   1507788754   "0 0"   iMiNDFREAK   "STEAM_0:0:12345678"   25000 }
#: 191
Level: 1
Timestamp: 1507788754
Zeros: 0 0
Player Name: iMiNDFREAK
Player SteamID: STEAM_0:0:12345678
Price: 25000
It seems this is the problem for zero prices.

Last edited by KiLLeR.; 10-12-2017 at 15:54.
KiLLeR. is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 10-12-2017 , 23:25   Re: [HELP] Dynamically populate a menu from nvault
Reply With Quote #5

I just applied the changes but it still does the same thing and I'm really not sure why...
I looked into the vaultdata and it was formatted just like the proposed new version but still failed.
I even removed the double zero as a part of vaultdata being stored for each user and it still does the same thing.
It's definitely a parsing issue or the formatting of vault data.
__________________
BeastGaming Community - Map Maker & Coder.

Last edited by imindfreak; 10-14-2017 at 02:40.
imindfreak is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 10-13-2017 , 04:35   Re: [HELP] Dynamically populate a menu from nvault
Reply With Quote #6

You should start debugging a.k.a testing. For example:
Code:
g_iPoke[ i ] = str_to_num( parsedpoke ) g_iPrice[ i ] = str_to_num( parsedprice ) g_iLevel[ i ] = str_to_num( parsedlevel ) g_iTimestamp[ i ] = str_to_num ( parsedtimestamp ) formatex( g_iDoubleZero[ i ], 8, "%s",parsedzero ) // for those use copy(g_iDoubleZero[ i ], charsmax(g_iDoubleZero[ i ]), parsedzero) formatex( g_szSteamid[ i ], 35, "%s",parsedsteamid ) formatex( g_szPlayername[ i ], 32, "%s",parsedname ) server_print("iPoke: %d | g_iLevel: %d | ....", g_iPoke(i), .... ) // here check if everything is loaded correctly into the global vars.
After that test if your g_iPrice holds proper values, then you have to debug everything that where g_iPrice is used and print message in console to check if everything is OK!
Searching and debugging are key skills for programmers!?!

Last edited by KiLLeR.; 10-13-2017 at 04:43.
KiLLeR. is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 10-14-2017 , 02:44   Re: Parsing vaultdata properly
Reply With Quote #7

Quote:
Originally Posted by KiLLeR. View Post
Looking at the code, I think I found your fault for this problem. This is your vault data string:
Code:
191 1 ; 1507788754 ; 0 0 ; iMiNDFREAK ; STEAM_0:0:12345678 ; 25000
When you replace ; with space you get this:
Code:
191 1   1507788754   0 0   iMiNDFREAK   STEAM_0:0:12345678   25000
and parsedzero string will be only the first zero, parsedname will be 2nd zero and so on...

I decided to make a little test. Here is the test code:
Code:
new vaultdata[256] = "191 1 ; 1507788754 ; 0 0 ; iMiNDFREAK ; STEAM_0:0:12345678 ; 25000"; replace_all(vaultdata, 255, ";", " "); server_print("Replaced string: { %s }", vaultdata);     new arg1[8],arg2[8],arg3[12],arg4[8],arg5[32],arg6[35],arg7[9]; parse(vaultdata,arg1,7,arg2,7,arg3,11,arg4,7,arg5,31,arg6,34,arg7, 8);     server_print("#: %s", arg1); server_print("Level: %s", arg2); server_print("Timestamp: %s", arg3); server_print("Zeros: %s", arg4); server_print("Player Name: %s", arg5); server_print("Player SteamID: %s", arg6); server_print("Price: %s", arg7);
and the result:
Code:
Replaced string: { 191 1   1507788754   0 0   iMiNDFREAK   STEAM_0:0:12345678   25000 }
#: 191
Level: 1
Timestamp: 1507788754
Zeros: 0
Player Name: 0
Player SteamID: iMiNDFREAK
Price: STEAM_0:
To fix this actually you need to add quotes to zeros and SteamID:
Code:
"191 1 ; 1507788754 ; ^"0 0^" ; iMiNDFREAK ; ^"STEAM_0:0:12345678^" ; 25000"
and the result:
Code:
Replaced string: { 191 1   1507788754   "0 0"   iMiNDFREAK   "STEAM_0:0:12345678"   25000 }
#: 191
Level: 1
Timestamp: 1507788754
Zeros: 0 0
Player Name: iMiNDFREAK
Player SteamID: STEAM_0:0:12345678
Price: 25000
It seems this is the problem for zero prices.
Quote:
Originally Posted by KiLLeR. View Post
You should start debugging a.k.a testing. For example:
Code:
g_iPoke[ i ] = str_to_num( parsedpoke ) g_iPrice[ i ] = str_to_num( parsedprice ) g_iLevel[ i ] = str_to_num( parsedlevel ) g_iTimestamp[ i ] = str_to_num ( parsedtimestamp ) formatex( g_iDoubleZero[ i ], 8, "%s",parsedzero ) // for those use copy(g_iDoubleZero[ i ], charsmax(g_iDoubleZero[ i ]), parsedzero) formatex( g_szSteamid[ i ], 35, "%s",parsedsteamid ) formatex( g_szPlayername[ i ], 32, "%s",parsedname ) server_print("iPoke: %d | g_iLevel: %d | ....", g_iPoke(i), .... ) // here check if everything is loaded correctly into the global vars.
After that test if your g_iPrice holds proper values, then you have to debug everything that where g_iPrice is used and print message in console to check if everything is OK!
Searching and debugging are key skills for programmers!?!
After thorough debugging, the solution proposed by KiLLeR worked.

For knowledge purposes for anyone else with a parsing issue -

The problem was the spacing between the parsing which resulting in Player Name being 0 and so on.
If you wish to parse text that has space between it, you need to add the escape quotes ^"Text Here^" for it to be parsed.
The solution to the problem was adding escape quotes to the g_iDoubleZero and g_szPlayername.
I didn't seem to need to add g_szSteamid in quotes as there is no space between a SteamID.
__________________
BeastGaming Community - Map Maker & Coder.

Last edited by imindfreak; 10-14-2017 at 16:22. Reason: test
imindfreak is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 10-14-2017 , 16:30   Re: Parsing vaultdata properly
Reply With Quote #8

Quote:
Originally Posted by imindfreak View Post
I didn't seem to need to add g_szSteamid in quotes as there is no space between a SteamID.
Check again my tests (code/result) and if you wish even test it (just put it in plugin_init and look at server start in console). SteamID without quotes isn't parsed correctly due to colons :

Last edited by KiLLeR.; 10-14-2017 at 16:32.
KiLLeR. 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 20:21.


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