Score/money doesn't save
#1

Hello, im working on a reg system with dini (for test), it works but i have a problem. Score and money aren't saved when a player disconnects or server restart. This is the OnPlayerLogin i use:

pawn Код:
public OnPlayerLogin(playerid,password[])
{
    new string2[64];
    new playername3[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername3, sizeof(playername3));

    format(string2, sizeof(string2), "/Users/%s.ini", playername3);

    if (dini_Exists(string2))
    {
        new password2 = num_hash(password);
        if(dini_Int(string2,"Password") == password2)
        {
            pInfo[playerid][Pass] = dini_Int(string2,"Password");
            pInfo[playerid][Admin] = dini_Int(string2,"Admin");
            pInfo[playerid][Cash] = dini_Int(string2,"Cash");
            pInfo[playerid][Vip] = dini_Int(string2,"Vip");
            pInfo[playerid][Scores] = dini_Int(string2,"Scores");
            pInfo[playerid][Deaths] = dini_Int(string2,"Deaths");
            pInfo[playerid][Nopm] = dini_Int(string2,"Nopm");
            pInfo[playerid][Muted] = dini_Int(string2,"Muted");
            pInfo[playerid][Vip] = dini_Int(string2,"Vip");
            pInfo[playerid][Banned] = dini_Int(string2,"Banned");
            pInfo[playerid][Cookies] = dini_Int(string2,"Cookies");
            pInfo[playerid][Warn] = dini_Int(string2,"Warn");
            pInfo[playerid][Jailed] = dini_Int(string2,"Jailed");
            pInfo[playerid][Logged] = dini_Int(string2,"Logged");
            pInfo[playerid][AdminActions] = dini_Int(string2,"AdminActions");
            pInfo[playerid][Rank] = dini_Int(string2,"Rank");
            pInfo[playerid][TempBan] = dini_Int(string2,"TempBan");
            GivePlayerMoney(playerid, pInfo[playerid][Cash]);
            SetPlayerScore(playerid, pInfo[playerid][Scores]);
            pInfo[playerid][Logged] = 1;
            SetTimerEx("CheckBan", 1500, false, "i", playerid);
            SetTimerEx("CheckTempBan", 1500, false, "i", playerid);
            new string[150];
            format(string,sizeof(string),"System: Logged in as {F70505}%s {FFFFFF}- Level: {F70505}%d",AdminLevelToName(playerid),pInfo[playerid][Admin]);
            SCM(playerid,-1,string);
        }
        else
        {
            new Year, Month, Day, Hour, Minute, Second;
            getdate(Year, Month, Day);
            gettime(Hour, Minute, Second);
            new echo[270];
            new kname[24];
            GetPlayerName(playerid, kname, 24);
            new IP[16];
            GetPlayerIp(playerid, IP, 16);
            format(echo,sizeof(echo),"0,3%s (%d) (IP: %s) failed to login in his account - %02d:%02d:%02d - %02d:%02d:%02d",kname,playerid,IP,Day,Month,Year,Hour,Minute,Second);
            FailedLogins(echo);
            gPlayerLogTries[playerid] += 1;
            ShowPlayerDialog(playerid, 1245, DIALOG_STYLE_INPUT,"Login","Incorrect password.","Login","Quit");
            if(gPlayerLogTries[playerid] == 3) { Kick(playerid); }
            return 1;
        }
    }
    return 1;
}
And this is OnPlayerDisconnect:

pawn Код:
if(pInfo[playerid][Logged] == 1)
    {
        new file[64];
        new playername3[MAX_PLAYER_NAME];
        GetPlayerName(playerid, playername3, sizeof(playername3));
        format(file, sizeof(file), "/Users/%s.ini", playername3);
        dini_IntSet(file, "Admin",pInfo[playerid][Admin]);
        dini_IntSet(file, "Cash",pInfo[playerid][Cash]);
        dini_IntSet(file, "Vip",pInfo[playerid][Vip]);
        dini_IntSet(file, "Scores",pInfo[playerid][Scores]);
        dini_IntSet(file, "Deaths",pInfo[playerid][Deaths]);
        dini_IntSet(file, "Nopm",pInfo[playerid][Nopm]);
        dini_IntSet(file, "Muted",pInfo[playerid][Muted]);
        dini_IntSet(file, "Vip",pInfo[playerid][Vip]);
        dini_IntSet(file, "Banned",pInfo[playerid][Banned]);
        dini_IntSet(file, "Cookies",pInfo[playerid][Cookies]);
        dini_IntSet(file, "Warn",pInfo[playerid][Warn]);
        dini_IntSet(file, "Jailed",pInfo[playerid][Jailed]);
        dini_IntSet(file, "Logged",pInfo[playerid][Logged]);
        dini_IntSet(file, "AdminActions",pInfo[playerid][AdminActions]);
        dini_IntSet(file, "Rank",pInfo[playerid][Rank]);
        dini_IntSet(file, "TempBan",pInfo[playerid][TempBan]);
        return 1;
    }
Reply
#2

Are you Parsing the file for the player under OnPlayerConnect?

Example:

pawn Код:
public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
    }
    return 1;
}
Reply
#3

No, i just do:
pawn Код:
new string[128];
    new plname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, plname, sizeof(plname));
    format(string, sizeof(string), "/Users/%s.ini", plname);
   
    if (dini_Exists(string))
    {
    ShowPlayerDialog(playerid, 1245, DIALOG_STYLE_INPUT,"Login","This account is registered, please input your password to login.","Login","Quit");
    }
    else
    {
    ShowPlayerDialog(playerid, 1246, DIALOG_STYLE_INPUT,"Register","Please insert your password to create a new account.","Register","Quit");
    }
Reply
#4

Bump.
Reply
#5

Try this saving code:

pawn Код:
if(pInfo[playerid][Logged] == 1)
    {
        new file[64];
        new playername3[MAX_PLAYER_NAME];
        GetPlayerName(playerid, playername3, sizeof(playername3));
        format(file, sizeof(file), "/Users/%s.ini", playername3);
        dini_IntSet(file, "Admin",pInfo[playerid][Admin]);
        dini_IntSet(file, "Cash",GetPlayerMoney(playerid));
        dini_IntSet(file, "Vip",pInfo[playerid][Vip]);
        dini_IntSet(file, "Scores",GetPlayerScore(playerid));
        dini_IntSet(file, "Deaths",pInfo[playerid][Deaths]);
        dini_IntSet(file, "Nopm",pInfo[playerid][Nopm]);
        dini_IntSet(file, "Muted",pInfo[playerid][Muted]);
        dini_IntSet(file, "Vip",pInfo[playerid][Vip]);
        dini_IntSet(file, "Banned",pInfo[playerid][Banned]);
        dini_IntSet(file, "Cookies",pInfo[playerid][Cookies]);
        dini_IntSet(file, "Warn",pInfo[playerid][Warn]);
        dini_IntSet(file, "Jailed",pInfo[playerid][Jailed]);
        dini_IntSet(file, "Logged",pInfo[playerid][Logged]);
        dini_IntSet(file, "AdminActions",pInfo[playerid][AdminActions]);
        dini_IntSet(file, "Rank",pInfo[playerid][Rank]);
        dini_IntSet(file, "TempBan",pInfo[playerid][TempBan]);
        return 1;
    }
Reply
#6

use GetPlayerMoney(playerid) to get the money of the player, and GetPlayerScore(playerid) for the score, for the rest the code seems fine.
Reply
#7

Quote:
Originally Posted by Apenmeeuw
Посмотреть сообщение
use GetPlayerMoney(playerid) to get the money of the player, and GetPlayerScore(playerid) for the score, for the rest the code seems fine.
I do already.

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Try this saving code:
Works, thanks! What do you changed?
Reply
#8

He changed

pawn Код:
dini_IntSet(file, "Cash",pInfo[playerid][Cash]);
dini_IntSet(file, "Scores",pInfo[playerid][Scores]);
into

pawn Код:
dini_IntSet(file, "Cash",GetPlayerMoney(playerid));
dini_IntSet(file, "Scores",GetPlayerScore(playerid));
But, for the love of god, please do not use this method.

My guess is your problem was not incrementing the pInfo[playerid][Cash] and pInfo[playerid][Scores] values whenever they needed to.

Using
pawn Код:
dini_IntSet(file, "Cash",GetPlayerMoney(playerid));
Is a really bad idea, this allows players to use money hacks. You should have a server-side money system. Instead of completely using the function "GivePlayerMoney", you should have your own function to handle money, for example:

pawn Код:
forward playerGiveMoney(playerid, amount);
public playerGiveMoney(playerid, amount)
{
    pInfo[playerid][Cash] += amount;
    GivePlayerMoney(playerid, amount);
}
Then when saving the player statistics, you should use

pawn Код:
dini_IntSet(file, "Cash", pInfo[playerid][Cash]);
Reply
#9

Oh, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)