11.11.2013, 15:06
Hello guys,
So i am messing around with sqlite again with konstatinos tutorial and i already had a problem before saving the money and score. now my question is: how do i load it after i logged in? i tried it like this:
but konstatinos said this is not neccesary or something.
i'm lost, i have this on OnPlayerConnect:
So i am messing around with sqlite again with konstatinos tutorial and i already had a problem before saving the money and score. now my question is: how do i load it after i logged in? i tried it like this:
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 0)
{
if(response)
{
new buf[129];
WP_Hash(buf, 129, inputtext);
if(!strcmp(buf, User[playerid][USER_PASSWORD], false))
{
new Query[75], DBResult: Result;
format(Query, sizeof(Query), "SELECT * FROM users WHERE username = '%s' LIMIT 0, 1", DB_Escape(User[playerid][USER_NAME]));
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
db_get_field_assoc(Result, "userid", Query, 7);
User[playerid][USER_ID] = strval(Query);
db_get_field_assoc(Result, "admin", Query, 3);
User[playerid][USER_ADMIN] = strval(Query);
db_get_field_assoc(Result, "money", Query, 3); //this
User[playerid][USER_MONEY] = strval(Query);
db_get_field_assoc(Result, "score", Query, 3); //this
User[playerid][USER_SCORE] = strval(Query);
User[playerid][USER_LOGGED_IN] = true;
SendClientMessage(playerid, 0x00FF00FF, ""chat" "COL_LIGHTBLUE"You have successfully logged in to your account!");
}
db_free_result( Result );
i'm lost, i have this on OnPlayerConnect:
pawn Code:
if(User[playerid][USER_LOGGED_IN] == true)
{
new Query[72];
format(Query, sizeof(Query), "UPDATE users SET admin = %d, money = %d, score = %d WHERE username = '%s'", User[playerid][USER_ADMIN], DB_Escape(User[playerid][USER_NAME]));
format(Query, sizeof(Query), "UPDATE users SET money = %d, score = %d WHERE username = '%s'", GetPlayerMoney(playerid), GetPlayerScore(playerid), DB_Escape(User[playerid][USER_NAME]));
db_query(Database, Query);
}
for(new i; i < _: USER_DATA; ++i) User[playerid][USER_DATA: i] = 0;
return 1;
}