11.11.2013, 17:47
It seems when I posted the OnPlayerDisconnect before I accidentally removed the line about db_query, sorry.
Change to:
Add default values:
And also check if the inputtext was not NULL.
Add those, remove the database and try again. It should work.
Change to:
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
if(User[playerid][USER_LOGGED_IN] == true)
{
new Query[128];
format(Query, sizeof(Query), "UPDATE users SET admin = %d, money = %d, score = %d WHERE username = '%s'", User[playerid][USER_ADMIN], 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;
}
pawn Code:
db_query(Database, "CREATE TABLE IF NOT EXISTS users (userid INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(24) COLLATE NOCASE, password VARCHAR(129), admin INTEGER DEFAULT 0 NOT NULL, money INTEGER DEFAULT 0 NOT NULL, score INTEGER DEFAULT 0 NOT NULL)");
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 0)
{
if(response)
{
if(!inputtext[0]) return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, ""COL_LIGHTBLUE"CSZM"COL_WHITE" Login pannel", ""chat" Please login to play on "COL_LIGHTBLUE"Counter Strike Zombie Mode\n "COL_WHITE"Enter your "COL_LIGHTBLUE"password"COL_WHITE":", "Login", "Exit");
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, 10); //this
User[playerid][USER_MONEY] = strval(Query);
db_get_field_assoc(Result, "score", Query, 7); //this
User[playerid][USER_SCORE] = strval(Query);
User[playerid][USER_LOGGED_IN] = true;
GivePlayerMoney(playerid, User[playerid][USER_MONEY]);
SetPlayerScore(playerid, User[playerid][USER_SCORE]);
SendClientMessage(playerid, 0x00FF00FF, ""chat" "COL_LIGHTBLUE"You have successfully logged in to your account!");
}
db_free_result(Result);
}
else
{
SendClientMessage(playerid, -1, ""chat" "COL_RED"Incorrect password!");
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, ""COL_LIGHTBLUE"CSZM"COL_WHITE" Login pannel", ""chat" Please login to play on "COL_LIGHTBLUE"Counter Strike Zombie Mode\n "COL_WHITE"Enter your "COL_LIGHTBLUE"password"COL_WHITE":", "Login", "Exit");
}
}
else Kick(playerid);
return 1;
}
// rest..