Dini OnPlayerDisconnect save stats help
#1

Hey guys... I made this reister/login system for a fucture admin system but i keep can't save stats...
It create a file on the scriptfiles direction with the stuff i want to save, but when disconect, it don't save the stats...
What could i put under OnPlayerDisconnect to save stats?

Code:
pawn Код:
#include <a_samp>
#include <dini>
#include <dudb>
#include <zcmd>
#include <sscanf>

#pragma unused ret_memcpy

new IsLogged[MAX_PLAYERS];
new gLogged[MAX_PLAYERS];
new gRegistred[MAX_PLAYERS];
new file[256];

enum pInfo
{
    AdminLevel,
    Cash,
    Score,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

COMMAND:register(playerid, params[])
{
    new tmp[256];
    new name[MAX_PLAYER_NAME];
    new id;
    GetPlayerName(playerid, name, sizeof(name));
    if(!sscanf(params, "u", id))
    {
            format(file,sizeof(file),"/RicAdmin/users/%s.ini",name);
            if(!fexist(file))
            {
                dini_Create(file);
                dini_IntSet(file,"Password", udb_hash(tmp));
                dini_IntSet(file,"AdminLevel", 0);
                dini_IntSet(file,"Cash", 0);
                dini_IntSet(file,"Score", 0);
                SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Created!");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                GetPlayerName(playerid, name, sizeof(name));
                printf("%s has registered a account!", name);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFFFFFFFF, " Account Already Found In Database");
                PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
                return 1;
            }
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /register [password]");
}

COMMAND:login(playerid, params[])
{
    new tmp[256], tmp2[256];
    new id;
    new PlayerName[24];
    if(!sscanf(params, "u", id))
    {
        new name[MAX_PLAYER_NAME];
        if(IsLogged[playerid] == 1)
        {
           
                GetPlayerName(playerid, name, sizeof(name));
                format(file,sizeof(file),"%s.ini",name);
                if(fexist(file))
                {
                    tmp2 = dini_Get(file, "Password");
                    if(udb_hash(tmp) != strval(tmp2))
                    {
                        SendClientMessage(playerid, 0xFFFFFFFF, "Login Failed!");
                        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
                        printf("%s has failed to login", name);
                        IsLogged[playerid] = 1;
                        SetPlayerMoney(playerid, dini_Int(file, "Cash"));
                        PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
                        SendClientMessage(playerid, 0xFFFFFFFF, "[System]: Account Logged into!");
                       
                    }
                }
           
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "You already are logged in!");
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /login [password]");
    return 1;
}
public OnPlayerDisconnect(playerid)
{
    IsLogged[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(gLogged[playerid] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "SERVER:Use /login [password] to save your stats!");
        return 1;
    }
    return 1;
}
public OnPlayerConnect(playerid)
{
    if(gRegistred[playerid] == 1)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Use /login to login into your account!");
        return 1;
    }
    if(gRegistred[playerid] == 0)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Use /register to register your account!");
        return 1;
    }
    return 1;
}
THANKS VERY MUCH!
Reply
#2

You need to instruct dini to write new values into the files when the player disconnects, for example:

pawn Код:
public OnPlayerDisconnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name)); // I recommend only doing this OnPlayerConnect and storing it in a multi-dimensional array for later referencing, but that is up to you
    format(file,sizeof(file),"/RicAdmin/users/%s.ini",name);
    if(IsLogged[playerid] == 1)
    {
        dini_IntSet(file,"AdminLevel", PlayerInfo[playerid][AdminLevel]);
        dini_IntSet(file,"Cash", GetPlayerMoney(playerid));
        dini_IntSet(file,"Score", GetPlayerScore(playerid));
    }
    IsLogged[playerid] = 0;
    return 1;
}
You have to remember that computers are very stupid, they cannot figure out what you want them to do on their own, you have to be very specific when programming, every instruction is given by you. So if you don't tell dini to set the values when the player disconnects, the values won't be set. I hope that helps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)