SA-MP Forums Archive
mysql user row to enum - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: mysql user row to enum (/showthread.php?tid=282699)



mysql user row to enum - [Diablo] - 12.09.2011

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.


Re: mysql user row to enum - [Diablo] - 12.09.2011

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


Re: mysql user row to enum - FireCat - 12.09.2011

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];



Re: mysql user row to enum - iggy1 - 12.09.2011

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


Re: mysql user row to enum - [Diablo] - 12.09.2011

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.


Re: mysql user row to enum - [Diablo] - 12.09.2011

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


Re: mysql user row to enum - MadeMan - 12.09.2011

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


Re: mysql user row to enum - [Diablo] - 12.09.2011

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


Re: mysql user row to enum - MadeMan - 12.09.2011

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



Re: mysql user row to enum - [Diablo] - 12.09.2011

damn i feel bad now worked as a charm, thanks