Storing data into the variables...?
#1

Guys... I have this function, but the problem is that the data doesn't get stored into the variables and so nothing works correctly...

pawn Код:
stock LoadAccountVariables(playerid)
{
    new EscapedName[MAX_PLAYER_NAME];
    if(IsPlayerConnectedEx(playerid))
    {
        mysql_real_escape_string(GetName(playerid), EscapedName);
        format(Query, sizeof(Query), "SELECT * FROM `Accounts` WHERE `Username` = '%s'", EscapedName);
        mysql_query(Query);
        mysql_store_result();
       
        mysql_fetch_row_format(Query, "|");
        sscanf(Query, "e<p<|>s[24]s[146]ddddfffff>", PlayerStats[playerid]);

        SetPlayerHealth(playerid, PlayerStats[playerid][pHealth]);
        SetPlayerArmour(playerid, PlayerStats[playerid][pArmour]);
    }
    else print("[MySQL ERROR] LoadAccountVariables() was called, but to a non-connected ID.");
    mysql_free_result();
}
How do I store what sscanf extracts so I can use it throughout the script?
Reply
#2

Can you show us the enumeration?
Reply
#3

Sure thing!

pawn Код:
enum PlayerData
{
    pUserName[23],
    pPassword[146],
    pAdminLevel,
    pMoney,
    pScore,
    pSkin,
    Float: pHealth,
    Float: pArmour,
    Float: pPositionX,
    Float: pPositionY,
    Float: pPositionZ
};
Reply
#4

I would:

Debug:
pawn Код:
new
    result = sscanf(Query, "e<p<|>s[24]s[146]ddddfffff>", PlayerStats[playerid]);

printf("%d", result); // 0 = everything is okay.
And make the enumerations bigger than the specifier's size:
pawn Код:
enum PlayerData
{
    pUserName[25], // this
    pPassword[147], // and this
    pAdminLevel,
    pMoney,
    pScore,
    pSkin,
    Float: pHealth,
    Float: pArmour,
    Float: pPositionX,
    Float: pPositionY,
    Float: pPositionZ
}
I don't know what the problem is, though.
Reply
#5

I solved the problem. It was something which I thought I had removed from the MySQL database, but apparently not. This is the "LoadAccountVariables();" function I'm using now.

pawn Код:
stock LoadAccountVariables(playerid)
{
    new EscapedName[MAX_PLAYER_NAME];
    if(IsPlayerConnectedEx(playerid))
    {
        mysql_real_escape_string(GetName(playerid), EscapedName);
        format(Query, sizeof(Query), "SELECT * FROM `Accounts` WHERE `Username` = '%s'", EscapedName);
        mysql_query(Query);
        mysql_store_result();
       
        mysql_fetch_row_format(Query, "|");
        sscanf(Query, "e<p<|>s[25]s[147]ddddfffff>",
        PlayerStats[playerid][pUserName],
        PlayerStats[playerid][pPassword],
        PlayerStats[playerid][pAdminLevel],
        PlayerStats[playerid][pMoney],
        PlayerStats[playerid][pScore],
        PlayerStats[playerid][pSkin],
        PlayerStats[playerid][pHealth],
        PlayerStats[playerid][pArmour],
        PlayerStats[playerid][pPositionX],
        PlayerStats[playerid][pPositionY],
        PlayerStats[playerid][pPositionZ]);
    }
    else print("[MySQL ERROR] LoadAccountVariables() was called, but to a non-connected ID.");
    mysql_free_result();
}
Sscanf won't shut the fuck up though with the format specifier, blah..., I'll fix that though. Anyways... Thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)