My Money doesn't save, only money from Spawn
#1

Hello Everybody. The problem is: when I enter the server I have $3.000 , then I spend $10-15 and exit the server. When I enter it again I have $3.000. So the saving system doesn't work. What can I do with it? Can you help me, please?

That's my OnPlayerDisconnect,OnPlayerSpawn and OnPlayerLogin : Check them.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
        Delete3DTextLabel(PlayerLabel);
        SaveAccounts();
        OnPlayerDataSave(playerid);
        SetPVarInt(playerid, "laser", 0);
        RemovePlayerAttachedObject(playerid, 0);
        KillTimer(Checkveh[playerid]);

    new pname[MAX_PLAYER_NAME], string[560 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    switch(reason)
    {
pawn Код:
public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid, Text[playerid]), TextDrawShowForPlayer(playerid, Text1[playerid]), TextDrawShowForPlayer(playerid, Health[playerid]);
    TextDrawShowForPlayer(playerid,Txt), TextDrawShowForPlayer(playerid, Clock), TextDrawShowForPlayer(playerid, Date);
    PlayerPlaySound(playerid, 1069, 0.0, 0.0, 0.0);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid, 0);
    SetPlayerScore(playerid, PlayerInfo[playerid][pKills]);
    SetPlayerSkillLevel(playerid,0,999);
    SetPlayerSkillLevel(playerid,1,999);
    SetPlayerSkillLevel(playerid,2,999);
    SetPlayerSkillLevel(playerid,3,999);
    SetPlayerSkillLevel(playerid,4,999);
    SetPlayerSkillLevel(playerid,5,999);
    SetPlayerSkillLevel(playerid,6,999);
    SetPlayerSkillLevel(playerid,7,999);
    SetPlayerSkillLevel(playerid,8,999);
    SetPlayerSkillLevel(playerid,9,999);
    SetPlayerSkillLevel(playerid,10,999);
    SetPlayerToTeamColor(playerid);
    SetPlayerSpawn(playerid);
    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
pawn Код:
public OnPlayerLogin_(playerid, password[])
{//15060
    new string2[256], keystring[256];
    format(string2, sizeof(string2), "%s.ini", PlayerName(playerid));
    keystring = dini_Get(string2, "Key");
    if(strcmp(keystring, password, true) == 0) // I assume that's the password check string1 is equal to string2
       {
        PlayerInfo[playerid][pAdmin] = dini_Int(string2,"AdminLevel");
        PlayerInfo[playerid][aDuty] = dini_Int(string2,"aDuty");
        PlayerInfo[playerid][aTog] = dini_Int(string2,"aTog");
        PlayerInfo[playerid][pMember] = dini_Int(string2,"pMember");
        PlayerInfo[playerid][pRank] = dini_Int(string2,"pRank");
        PlayerInfo[playerid][pBanned] = dini_Int(string2,"Banned");
        PlayerInfo[playerid][pDonateRank] = dini_Int(string2,"DonateRank");
        PlayerInfo[playerid][pWarns] = dini_Int(string2,"Warnings");
        PlayerInfo[playerid][pReg] = dini_Int(string2,"Registered");
        PlayerInfo[playerid][pCash] = dini_Int(string2,"Cash");
        PlayerInfo[playerid][pKills] = dini_Int(string2,"Kills");
        PlayerInfo[playerid][pDeaths] = dini_Int(string2,"Deaths");
        PlayerInfo[playerid][pMuted] = dini_Int(string2,"Muted");
        PlayerInfo[playerid][prMuted] = dini_Int(string2,"ReportMuted");
        PlayerInfo[playerid][ptrMuted] = dini_Int(string2,"ReportTimeMuted");
        PlayerInfo[playerid][ptMuted] = dini_Int(string2,"TimeMuted");
        PlayerInfo[playerid][pvMuted] = dini_Int(string2,"VipMuted");
        PlayerInfo[playerid][pvtMuted] = dini_Int(string2,"VipTimeMuted");
        PlayerInfo[playerid][pfMuted] = dini_Int(string2,"FactionMuted");
        PlayerInfo[playerid][pftMuted] = dini_Int(string2,"FactionTimeMuted");
        PlayerInfo[playerid][pSpree] = dini_Int(string2,"KillSpree");
        PlayerInfo[playerid][pCWons] = dini_Int(string2,"CWons");
        PlayerInfo[playerid][pHide] = dini_Int(string2,"Hide");
        PlayerInfo[playerid][pIgnorePM] = dini_Int(string2,"pIgnorePM");
        PlayerInfo[playerid][pJailed] = dini_Int(string2,"pJailed");
        PlayerInfo[playerid][pArrested] = dini_Int(string2,"pArrested");
        PlayerInfo[playerid][pCrimes] = dini_Int(string2,"pCrimes");
        PlayerInfo[playerid][pJail] = dini_Int(string2,"pJail");
        PlayerInfo[playerid][pJailTime] = dini_Int(string2,"pJailTime");
        PlayerInfo[playerid][Level] = dini_Int(string2,"Level");
        PlayerInfo[playerid][Exp] = dini_Int(string2,"Exp");
        PlayerInfo[playerid][pWantedDeaths] = dini_Int(string2,"pWantedDeaths");
    }
    else
    {
Thanks guys
Reply
#2

Hand over the SaveAccounts(); function.


Also explain please how are you spending the money in game, cause it only saves PlayerInfo[playerid][pCash], and if that's not decreased then you never really 'bought' anything.


Suggestion: Attempt to debug it.
Quote:

printf("%s has left the server with %d cash", PUT_NAME_DETECTOR_HERE, PlayerInfo[playerid][pCash]);

* Replace "PUT_NAME_DETECTOR_HERE" with characters name or whatever you want to.
* Place it on OnPlayerDisconnect and check if the money updates when you spend & exit.
Reply
#3

1. We need to see the code where you save the accounts.

2. Why are you using dini? There are many different alternatives that are much more efficient and just as easy to use.
Reply
#4

pawn Код:
public SaveAccounts()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            OnPlayerDataSave(i);
        }
    }
}
Example how i get money with my Job :
pawn Код:
SendClientMessage(playerid,COLOR_YELLOW,"You get $350.");
                    GivePlayerMoney(playerid, 350);
                    SetPlayerColor(playerid, TeamInfo[PlayerInfo[playerid][pMember]][TeamColor]);
                    RemovePlayerFromVehicle(playerid);
                    DisablePlayerCheckpoint(playerid);
                    SetTimerEx("SweeperJobAgain", 3600000,false, "d", playerid);
                    CoalMineJobAllow[playerid] = 1;
                    coalmine[playerid] = 0;
                }//done and LAST
Reply
#5

pawn Код:
dini_Create(string);
        dini_IntSet(string, "cash",[playerid]);
Reply
#6

Doesnt works semaj, PLEASE HELP ME GUYS
Reply
#7

Show the OnPlayerDataSave() function.
Reply
#8

pawn Код:
public OnPlayerDataSave(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        if(gPlayerLogged[playerid] && gPlayerSpawned[playerid])
        {
            new string[256], playersip[64];
            format(string, sizeof(string), "%s.ini", PlayerName(playerid));
            GetPlayerIp(playerid, playersip, sizeof(playersip));
            if(dini_Exists(string))
            {
                dini_Set(string, "Key", PlayerInfo[playerid][pKey]);
                dini_Set(string, "IP", PlayerInfo[playerid][pIP]);
                dini_IntSet(string, "AdminLevel", PlayerInfo[playerid][pAdmin]);
                dini_IntSet(string, "aDuty", PlayerInfo[playerid][aDuty]);
                dini_IntSet(string, "aTog", PlayerInfo[playerid][aTog]);
                dini_IntSet(string, "pMember", PlayerInfo[playerid][pMember]);
                dini_IntSet(string, "pRank", PlayerInfo[playerid][pRank]);
                dini_IntSet(string, "Banned", PlayerInfo[playerid][pBanned]);
                dini_IntSet(string, "DonateRank", PlayerInfo[playerid][pDonateRank]);
                dini_IntSet(string, "Registered", PlayerInfo[playerid][pReg]);
                dini_IntSet(string, "Warnings", PlayerInfo[playerid][pWarns]);
                dini_IntSet(string, "Cash", PlayerInfo[playerid][pCash]);
                dini_IntSet(string, "Kills", PlayerInfo[playerid][pKills]);
                dini_IntSet(string, "Deaths", PlayerInfo[playerid][pDeaths]);
                dini_IntSet(string, "Muted", PlayerInfo[playerid][pMuted]);
                dini_IntSet(string, "ReportMuted", PlayerInfo[playerid][prMuted]);
                dini_IntSet(string, "ReportTimeMuted", PlayerInfo[playerid][ptrMuted]);
                dini_IntSet(string, "TimeMuted", PlayerInfo[playerid][ptMuted]);
                dini_IntSet(string, "VipMuted", PlayerInfo[playerid][pvMuted]);
                dini_IntSet(string, "VipTimeMuted", PlayerInfo[playerid][pvtMuted]);
                dini_IntSet(string, "FactionMuted", PlayerInfo[playerid][pfMuted]);
                dini_IntSet(string, "FactionTimeMuted", PlayerInfo[playerid][pftMuted]);
                dini_IntSet(string, "KillSpree", PlayerInfo[playerid][pSpree]);
                dini_IntSet(string, "CWons", PlayerInfo[playerid][pCWons]);
                dini_IntSet(string, "Hide", PlayerInfo[playerid][pHide]);
                dini_IntSet(string, "pIgnorePM", PlayerInfo[playerid][pIgnorePM]);
                dini_IntSet(string, "pJailed", PlayerInfo[playerid][pJailed]);
                dini_IntSet(string, "pArrested", PlayerInfo[playerid][pArrested]);
                dini_IntSet(string, "pCrimes", PlayerInfo[playerid][pCrimes]);
                dini_IntSet(string, "pJail", PlayerInfo[playerid][pJail]);
                dini_IntSet(string, "pJailTime", PlayerInfo[playerid][pJailTime]);
                dini_IntSet(string, "Level", PlayerInfo[playerid][Level]);
                dini_IntSet(string, "Exp", PlayerInfo[playerid][Exp]);
                dini_IntSet(string, "pWantedDeaths", PlayerInfo[playerid][pWantedDeaths]);
            }
        }
    }
    return 1;
}
And OnPlayerLogin
pawn Код:
}
    if(PlayerInfo[playerid][pReg] == 0)
    {
        PlayerInfo[playerid][pReg] = 1;
        GivePlayerMoney(playerid, 500);
    }
    gPlayerLogged[playerid] = 1;
    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
    SendClientMessage(playerid, 0x40FF40FF,"SERVER: Успешно влезе в акаунта си.");
    format(string2, sizeof(string2), "Добре дошъл {00B700}%s", PlayerName(playerid));
    SendClientMessage(playerid, COLOR_WHITE,string2);
    GetPlayerIp(playerid, PlayerInfo[playerid][pIP], 21);
    strmid(PlayerInfo[playerid][pKey], password, 0, strlen(password), 255);
    {
        new string[256];
        new nxtlevel = PlayerInfo[playerid][Level]+1;
        new expamount = nxtlevel*levelexp;
        format(string, sizeof(string), "Админ Левел: %d | ВИП Левел: %d | Ниво: %d | XP: %d/%d | Организация: %s", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], expamount, TeamInfo[PlayerInfo[playerid][pMember]][TeamName]);
        SendClientMessage(playerid, COLOR_YELLOW,string);
    }
    return 1;
}
Reply
#9

The problem is most likely that you are not updated the pCash variable when you are adding/deducting money from the player's total; you only use GetPlayerMoney/GivePlayerMoney().

However, you don't need that variable anyway. You can just use the two functions above during loading/saving. The rest of the time the amount of money they have is held by the server itself.
Reply
#10

Quote:
Originally Posted by Bakr
Посмотреть сообщение
You can just use the two functions above during loading/saving.
4char
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)