mysql user row to enum
#1

Hello.

I have problem trying to save the user row from mysql to an enum. For the sake of simplicity i will only use 3 columns.

the sql structure is similar to this -> username | email | money.

My enum looks like this:
pawn Код:
enum uAccount
{
     pUsername,
     pEmail,
     pMoney
};
new PlayerData[MAX_PLAYERS][uAccount];
After clicking login on "login dialog", i have a function that checks the user in database. If ok, proceeds to the data loading.

here is the function for loading..
pawn Код:
stock UserLoggedIn(playerid)
{
     format(sqlQuery, sizeof(sqlQuery), "SELECT * FROM accounts WHERE username = '%s'", PlayerName(playerid)); // PlayerName returns the name
     mysql_query(sqlQuery);
     mysql_store_result();

     if(mysql_fetch_row(sqlQuery))
     {
          sscanf(sqlQuery, "p<|>e<s[24]s[255]i>", PlayerData[playerid]);
     }
     mysql_free_result();
    return 1;
}
For testing purposes i have print the PlayerData[playerid][pUsername] and PlayerData[playerid][pMoney] and I get Username: * and Money: 0

Any help is aprreciated.
Reply
#2

so if i define enum like this
pawn Код:
enum uAccount
{
     pUsername[24],
     pEmail[255],
     pMoney
};
new PlayerData[MAX_PLAYERS][uAccount];
that should do it? I cannot test the code atm..

tnx
Reply
#3

Quote:
Originally Posted by [Diablo]
Посмотреть сообщение
so if i define enum like this
pawn Код:
enum uAccount
{
     pUsername[24],
     pEmail[255],
     pMoney
};
new PlayerData[MAX_PLAYERS][uAccount];
that should do it? I cannot test the code atm..

tnx
pawn Код:
enum uAccount
{
     pUsername[24],
     pEmail[30],
     pMoney
};
new PlayerData[MAX_PLAYERS][uAccount];
Reply
#4

I noticed there is also no closing angle bracket in the sscanf line (for the enum).
Reply
#5

couldn't wait for this, so i did a remote to home computer and tried.
@firecat & ******: thanks for the solution, i didn't know that enums and sscanf must match learning something new everyday^^

@iggy1: thanks, this was a mistype when writing a post, fixed now.

best regards, problem solved.
Reply
#6

for the purpose of not spamming threads, i will ask here.
if i create a separate filterscript, how can i access this same enum (PlayerData) ? Is that even possible?

br
Reply
#7

Quote:
Originally Posted by [Diablo]
Посмотреть сообщение
for the purpose of not spamming threads, i will ask here.
if i create a separate filterscript, how can i access this same enum (PlayerData) ? Is that even possible?

br
Not directly. You can use CallRemoteFunction.

https://sampwiki.blast.hk/wiki/CallRemoteFunction
Reply
#8

thank you, will check it out asap.
although the resolution given by firecat and ****** works, i do get a warning in samp-serve console:
sscanf warning: Format specifier does not match parameter count.

code written:
pawn Код:
stock UserLoggedIn(playerid)
{
    format(sqlQuery, sizeof(sqlQuery), "SELECT username, email, ip, adminlevel, money FROM accounts WHERE username = '%s'", PlayerName(playerid));
    mysql_query(sqlQuery);
    mysql_store_result();

    if(mysql_fetch_row(sqlQuery))
    {
        sscanf(sqlQuery, "p<|>e<s[24]s[255]s[15]dd>",
        PlayerData[playerid][pUsername], PlayerData[playerid][pEmail], PlayerData[playerid][pIP], PlayerData[playerid][pAdminLevel], PlayerData[playerid][pMoney]);
    }
    mysql_free_result();
    return 1;
}
as far as i know, there are 5 parameters and 5 store values, so i'm out of ideas..

br
Reply
#9

pawn Код:
sscanf(sqlQuery, "p<|>e<s[24]s[255]s[15]dd>", PlayerData[playerid]);
Reply
#10

damn i feel bad now worked as a charm, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)