Stats not updating..
#1

Hello there,

I made a /stats command which displays amount of cash of a certain player, admin level, kills and deaths. This is my player information enum and array:

pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];
My user path stock:

pawn Код:
stock UserPath(playerid)
{
    new string[128], playername[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), PATH, playername);
    return string;
}
My /stats command:

pawn Код:
if (strcmp("/stats", cmdtext, true, 6) == 0)
    {
        new cash = PlayerInfo[playerid][pCash];
        new admin = PlayerInfo[playerid][pAdmin];
        new kills = PlayerInfo[playerid][pKills];
        new deaths = PlayerInfo[playerid][pDeaths];
       
        new string[128], playerName[MAX_PLAYER_NAME+1];
        GetPlayerName(playerid, playerName, sizeof(playerName));
       
        format(string, sizeof(string), "%s's statistics: \n Amount of cash: %i \n Admin level: %i \n Kills: %i \n Deaths: %i \n", playerName, cash, admin, kills, deaths);
        SendClientMessage(playerid, -1, string);
        return 1;
    }
Whenever a player dies, this is what happens:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    // Increment killer's kills and dead's deaths
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    GivePlayerMoney(killerid, 1000);
    SendClientMessage(killerid, -1, "Nicely done, you have received 1000 dollars for the kill!");

    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File, "data");
    INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
The above code should increment the deaths then update the user file, so when I type /stats, I get the values. The problem is, it's not updating, despite the code above. All I see is 0 deaths even though I /kill'd myself a few times.

Please help me
Reply
#2

Why wouldn't you save the data when player leaves the server? Why would you bother the server, whenever player dies? Imagine, if there are going to be plenty of deaths and kills every 3-5 seconds, your server will have a lot of tasks to do, which is honestly pointless, when you can do the same JUST once.

That should fix the problem, BUT, if it don't, make sure that your "#define PATH "..."" has a proper path to your user files.
Reply
#3

The PATH define is correct nonetheless, it did store my user file.

I already have this, but it still doesn't update even after relogging: (Under OnPlayerDisconnect)

pawn Код:
// Saves information about player who disconnected
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File, "data");
    INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
    INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
    INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
Reply
#4

Does data pop-up in /stats command, when you type it in? Seems like file handler is simply not writing any data to the file. Debug file handler, to make sure that it is writing data to the correct file (I believe, this is YSI).

Also, make sure that data in file is called "Deaths" as you are trying to save it to.
Reply
#5

Yes, data does display in the /stats command. I did some experimenting now, I made myself a /givememoney command to give me cash and see if it's written in my user file. It works now, I have no idea why..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)