Register System
#1

Well I am containing problem with my register system
I am using dini atm. It works well, the score even saves to the file, but when player disconnects, score resets, and doesn't save.

OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
    gPlayerLogged[playerid] = 0;
    new name[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Continental Wars", "Welcome to continental wars. Please register in order to proceed.", "Register", "Quit");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Continental Wars", "Welcome back to Continental Wars. Please log in in order to proceed.", "Login", "Quit");
    }
    return 1;
}
OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", GetPlayerScore(playerid));
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
        dini_IntSet(file, "VIP", PlayerInfo[playerid][pVip]);
        dini_IntSet(file, "Admin Level", PlayerInfo[playerid][pAdmin]);
        dini_IntSet(file, "Banned", PlayerInfo[playerid][pBanned]);
        dini_IntSet(file, "IP", PlayerInfo[playerid][pIP]);
        dini_IntSet(file, "Rank", PlayerInfo[playerid][pRank]);
    }
    gPlayerLogged[playerid] = 0;
    return 1;
}
OnDialogResponse:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], file[128], string[128];
        new ip[24];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response)
        {
            SendClientMessage(playerid, COLOR_WHITE, "[SYSTEM]: You have chosen to quit.");
            Kick(playerid);
        }
        if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Continental Wars", "Welcome to continental wars. Please register in order to proceed.", "Register", "Quit");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "Admin Level", PlayerInfo[playerid][pAdmin] = 0);
        dini_IntSet(file, "VIP", PlayerInfo[playerid][pVip] = 0);
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore] = 0);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash] = 1000);
        dini_IntSet(file, "IP", PlayerInfo[playerid][pIP] = GetPlayerIp(playerid, ip, sizeof(ip)));
        dini_IntSet(file, "Banned", PlayerInfo[playerid][pCash] = 0);
        dini_IntSet(file, "Rank", PlayerInfo[playerid][pRank] = 1);
        format(string, sizeof(string), "[SYSTEM]: Successfully registered account %s with password %s. You have been automatically logged in.", name, inputtext);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        gPlayerLogged[playerid] = 1;
    }
    if(dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[128], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response)
        {
            SendClientMessage(playerid, COLOR_WHITE, "[SYSTEM]: You have chosen to quit.");
            Kick(playerid);
        }
        new tmp;
        tmp = dini_Int(file, "Password");
        if(udb_hash(inputtext) != tmp)
        {
            SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: Password incorrect. [1/3]");
            passwordcount ++;
            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Continental Wars", "Welcome back to Continental Wars. Please log in in order to proceed.", "Login", "Quit");
            if(passwordcount == 3)
            {
                SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: Password incorrect. [3/3] You have been kicked as result.");
                Kick(playerid);
            }
        }
        else
        {
            gPlayerLogged[playerid] = 1;
            PlayerInfo[playerid][pAdmin] = dini_Int(file, "Admin Level");
            SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
            GivePlayerMoney(playerid, dini_Int(file, "Money"));
            PlayerInfo[playerid][pVip] = dini_Int(file, "VIP");
            PlayerInfo[playerid][pIP] = dini_Int(file, "IP");
            PlayerInfo[playerid][pRank] = dini_Int(file, "Rank");
            format(string, sizeof(string), "[SYSTEM]: Successfully logged in to account %s", name);
            SendClientMessage(playerid, COLOR_GREEN, string);
        }
    }
    return 1;
}
I see nothing wrong with it, whats wrong ?
Reply
#2

Maybe instead of getting the player his score, store into your variable whenever that player gets a score and then when this specific player logs out, you'll IntSet with the variable.
Reply
#3

pawn Код:
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
Change it to

pawn Код:
SetPlayerScore(playerid, dini_Int(file, "Score"));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)