Saves but doesn't load
#1

This filterscript saves everything but doesn't load anything but the password.

pawn Code:
#include <a_samp>
#include <a_mysql>
#define MYSQL_HOST  "127.0.0.1"
#define MYSQL_USER  "12345"
#define MYSQL_DB    "kcnr"
#define MYSQL_PASS  "12345"

#undef MAX_PLAYERS
#define MAX_PLAYERS 50 // Put this as low as you could
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

#define COLOR_YELLOW 0xE1FF00FF
#define COLOR_RED 0xFF0000FF

enum pEnum
{
    userName[MAX_PLAYER_NAME],
    Password[32],
    Money,
    Score,
    MedFees,
    AdminLVL,
    TicketsR,
    Arrests,
    HitsC,
    MBF,
    PlayersRobbed,
    LottoWins,
    Deaths,
    TimeC,
    Wanted,
    BanBy,
    PlayersTicketed,
    Tarrested,
    BReason,
    Banned,
};
new UserStats[MAX_PLAYERS][pEnum];

new AccountExists[MAX_PLAYERS];
new PlayerLogged[MAX_PLAYERS];

ConnectMySQL()
{
    if(mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS))
        print("[MySQL] Connection to the MySQL Database was successfully!");

    else
        print("[MySQL] Could not connect to the MySQL Database!");
}

CheckMySQL()
{
    if(mysql_ping() == -1)
        mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
}

CheckAccountExists(account[])
{
    new string[128];
        format(string, sizeof(string), "SELECT * FROM Users WHERE userName = '%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[]) // Created by Westie
{
    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;
}

RegisterPlayer(playerid, password[])
{
    if(AccountExists[playerid])
        return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] You're already registered!");

    if(PlayerLogged[playerid])
        return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] You're already logged in!");

    if(strlen(password) < 3 || strlen(password) >= 32)
        return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Your password is too short or too long!");

    CheckMySQL();

    new string[128];
    format(string, sizeof(string), "INSERT INTO Users (userName,Password,Money,Score,Wanted) VALUES ('%s','%s','%d','%d','%d')", UserStats[playerid][userName], password,UserStats[playerid][Money],UserStats[playerid][Score],UserStats[playerid][Wanted]);
    mysql_query(string);

        AccountExists[playerid] = 1;
    SendClientMessage(playerid, COLOR_YELLOW, "[ACCOUNT] Your account has been created, please login now!");

    return 1;
}

LoginPlayer(playerid, password[])
{
    if(!AccountExists[playerid])
        return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] You're not registered!");

    if(PlayerLogged[playerid])
            return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] You're already logged in!");

    if(strlen(password) < 3 || strlen(password) >= 32)
            return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Your password is too short or too long!");

    CheckMySQL();

        new string[128];
    format(string, sizeof(string), "SELECT * FROM Users WHERE userName = '%s' AND Password = '%s'", UserStats[playerid][userName], password);
    mysql_query(string);
    mysql_store_result();

    if(!mysql_num_rows())
        return SendClientMessage(playerid, COLOR_RED, "[ACCOUNT] Incorrect password!");

    new row[128]; // The length of 1 'row' total.
    new field[23][32]; // [4] = Amount of fields, [24] = Max length of the bigest field.

    mysql_fetch_row_format(row, "|");
    explode(row, field, "|");
    mysql_free_result();

    // The field starts here with 1, because the field 'userName' = 0, and we already have the userName in a variable.
    format(UserStats[playerid][Password], 32, "%s", field[1]);
    UserStats[playerid][Money] = strval(field[5]);
    UserStats[playerid][Score] = strval(field[6]);
    UserStats[playerid][MedFees] = strval(field[7]);
    UserStats[playerid][AdminLVL] = strval(field[8]);
    UserStats[playerid][TicketsR] = strval(field[9]);
    UserStats[playerid][PlayersTicketed] = strval(field[10]);
    UserStats[playerid][Arrests] = strval(field[11]);
    UserStats[playerid][Tarrested] = strval(field[12]);
    UserStats[playerid][HitsC] = strval(field[13]);
    UserStats[playerid][MBF] = strval(field[14]);
    UserStats[playerid][PlayersRobbed] = strval(field[15]);
    UserStats[playerid][LottoWins] = strval(field[16]);
    UserStats[playerid][Deaths] = strval(field[17]);
    UserStats[playerid][TimeC] = strval(field[18]);
    UserStats[playerid][Wanted] = strval(field[19]);
    UserStats[playerid][Banned] = strval(field[20]);
    UserStats[playerid][BReason] = strval(field[21]);
    UserStats[playerid][BanBy] = strval(field[22]);

    GivePlayerMoney(playerid, 0 + UserStats[playerid][Money]);
    SetPlayerScore(playerid,  0 + UserStats[playerid][Score]);
    SetPlayerWantedLevel(playerid,  0 + UserStats[playerid][Wanted]);


        format(string, sizeof(string), "[ACCOUNT] Welcome back %s, you are now logged in!", UserStats[playerid][userName]);
        SendClientMessage(playerid, COLOR_YELLOW, string);

        PlayerLogged[playerid] = 1;
        return 1;
}

SavePlayer(playerid)
{
    if(!PlayerLogged[playerid])
        return 0;

        UserStats[playerid][Money] = GetPlayerMoney(playerid);
        UserStats[playerid][Score] = GetPlayerScore(playerid);
        UserStats[playerid][Wanted] = GetPlayerWantedLevel(playerid);


    CheckMySQL();

        new string[256];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Money='%d',Score='%d',Wanted='%d' WHERE userName='%s'", UserStats[playerid][Password], UserStats[playerid][Money], UserStats[playerid][Score], UserStats[playerid][Wanted], UserStats[playerid][userName]);
        mysql_query(string);
        return 1;
}

public OnGameModeInit()
{
    ConnectMySQL();
    return 1;
}

public OnPlayerConnect(playerid)
{
    GetPlayerName(playerid, UserStats[playerid][userName], MAX_PLAYER_NAME);

    if(CheckAccountExists(UserStats[playerid][userName])) AccountExists[playerid] = 1;
    else AccountExists[playerid] = 0;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    SavePlayer(playerid);
    PlayerLogged[playerid] = 0;
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(register, 8, cmdtext);
    dcmd(login, 5, cmdtext);
    return 0;
}

dcmd_register(playerid, params[])
{
    RegisterPlayer(playerid, params);
    return 1;
}

dcmd_login(playerid, params[])
{
    LoginPlayer(playerid, params);
    return 1;
}
Reply
#2

Maybe you missed somthing small & that's stopping it
Reply
#3

Wrong
Reply
#4

We have 2016 and you still using that outdated plugin.

Anyway, your load method is crap too.

That one is probably best for this plugin:

Code:
	new data[128], string[128];

	format(string, sizeof(string), "SELECT * FROM Users WHERE userName = '%s' AND Password = '%s'", UserStats[playerid][userName], password);
	mysql_query(string);
	mysql_store_result();
	while(mysql_fetch_row(data, "|") == 1)
	{
		sscanf(data, "p<|>s[32]dddddddddddddddddd",
		UserStats[playerid][Password],
		UserStats[playerid][Money],
		UserStats[playerid][Score],
		UserStats[playerid][MedFees],
		UserStats[playerid][AdminLVL],
		UserStats[playerid][TicketsR],
		UserStats[playerid][PlayersTicketed],
		UserStats[playerid][Arrests],
		UserStats[playerid][Tarrested],
	 	UserStats[playerid][HitsC],
 		UserStats[playerid][MBF],
		UserStats[playerid][PlayersRobbed],
		UserStats[playerid][LottoWins],
		UserStats[playerid][Deaths],
		UserStats[playerid][TimeC],
		UserStats[playerid][Wanted],
		UserStats[playerid][Banned],
		UserStats[playerid][BReason],
		UserStats[playerid][BanBy]);	
	}
	mysql_free_result();
And i think UserStats[playerid][BReason] should be string, not integer.
Reply
#5

Thanks for the reply, two years late but yeah you are right.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)