CheckAccountExists(account[]) { new string[128]; format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s'", account); mysql_query(string); mysql_store_result(); new value; value = mysql_num_rows(); mysql_free_result(); return value; } explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) //this isn't mine! { new iNode, iPointer, iPrevious = -1, iDelimiter = strlen(sDelimiter); while(iNode < iVertices) { iPointer = strfind(sSource, sDelimiter, false, iPointer); if(iPointer == -1) { strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength); break; } else { strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength); } iPrevious = (iPointer += iDelimiter); ++iNode; } return iPrevious; } public OnPlayerRegister(playerid, password[]) { if(!AccountExists[playerid]) { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Type Down Your Password To Continue(log-in)", "Register","Quit"); } if(strlen(password) < 3) return GameTextForPlayer(playerid, "~r~Your Password Must be Atleast 3", 3000, 3); if(strlen(password) >= 32) return GameTextForPlayer(playerid, "~g~Your Password Is Too Long", 3000, 3); CheckMySQL(); new string[128]; format(string, sizeof(string), "INSERT INTO Users (Name,Password) VALUES ('%s','%s')", UserStats[playerid][Name], UserStats[playerid][Password]); mysql_query(string); AccountExists[playerid] = 1; SendClientMessage(playerid, GREEN, "Your account has been created, please login now!"); OnPlayerLogin(playerid, password); return 1; } public OnPlayerLogin(playerid, password[]) { if(AccountExists[playerid]) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Type Down Your Password To Continue(log-in)", "Log-in","Quit"); CheckMySQL(); new string[128]; format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s' AND Password = '%s'", UserStats[playerid][Name], UserStats[playerid][Password]); mysql_query(string); mysql_store_result(); if(!mysql_num_rows()) return GameTextForPlayer(playerid, "~n~~n~~r~Incorrect password!", 3000, 3); new row[128]; new field[4][32]; mysql_fetch_row_format(row, "|"); explode(row, field, "|"); mysql_free_result(); UserStats[playerid][Name] = strval(field[0]); format(UserStats[playerid][Password], 32, "%s", field[1]); UserStats[playerid][Admin] = strval(field[2]); UserStats[playerid][Money] = strval(field[3]); GivePlayerMoney(playerid, UserStats[playerid][Money]); format(string, sizeof(string), "Welcome back %s, you are now logged in!", UserStats[playerid][Name]); SendClientMessage(playerid, GREEN, string); PlayerLogged[playerid] = 1; TogglePlayerControllable(playerid, false); return 1; } SavePlayer(playerid) { if(!PlayerLogged[playerid]) return 0; UserStats[playerid][Money] = GetPlayerMoney(playerid); UserStats[playerid][Admin] = UserStats[playerid][Admin]; CheckMySQL(); new string[256]; format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d' WHERE Name='%s'", UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Name]); mysql_query(string); return 1; }
public OnQueryError(errorid, error[], resultid, extraid, callback[], query[], connectionHandle)
{
printf("MySQL Error: %d %s %d %d %s %s %d", errorid, error, resultid, extraid, callback, query, connectionHandle);
return 1;
}
lol, I said to you to paste the code in to your script and paste the errors here.
|
public OnPlayerConnect(playerid) { //after some codes if(CheckAccountExists(UserStats[playerid][Name])) AccountExists[playerid] = 1; else AccountExists[playerid] = 0; AccountExists[playerid] = 0; return 1; }