Problem With INI (+REP for helper)
#1

Register Dialog:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Red"Registering...",""WHITE"You have entered an "Red"Invalid Password.\n"WHITE"Type your "Red"Password "WHITE"below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                GetPlayerName(playerid,PlayerInfo[playerid][pUsername],MAX_PLAYER_NAME);
                INI_WriteString(File,"Username",PlayerInfo[playerid][pUsername]);
                INI_WriteInt(File,"Password",udb_hash(inputtext));
................................
Login Dialog:
pawn Код:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
i have this on player register & login but the problem is that when ever a player joins into my server and leaves without registering the account is saved on the next time if other player puts the same name instead of register dialog login dialog is appeared please help me fix that
Reply
#2

show the OnPlayerDisconnect or where ever you save the players stats.
Reply
#3

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    SaveStats(playerid);
    return 1;
}

stock SaveStats(playerid)
{
    new string[320];
    format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"AdminLevel",PlayerInfo[playerid][pAdminLevel]);
    INI_WriteInt(File,"Bank",PlayerInfo[playerid][pBank]);
...................................
Reply
#4

just make a var to check if the player has registered/logged in

pawn Код:
new logged[MAX_PLAYERS]; //global var
pawn Код:
case DIALOG_REGISTER:
        {
 if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Red"Registering...",""WHITE"You have entered an "Red"Invalid Password.\n"WHITE"Type your "Red"Password "WHITE"below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                GetPlayerName(playerid,PlayerInfo[playerid][pUsername],MAX_PLAYER_NAME);
                INI_WriteString(File,"Username",PlayerInfo[playerid][pUsername]);
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                logged[playerid] = 1;
pawn Код:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    logged[playerid] = 1;
then check On the savestats
pawn Код:
stock SaveStats(playerid)
{
    if (logged[playerid] ==1)
    {
        new string[320];
        format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    }
i think should work x:
Reply
#5

it will work except this one

pawn Код:
stock SaveStats(playerid)
{
    if (logged[playerid] ==1)
    {
        new string[320];
        format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    }
you forget the brackets (})

this is the correct one

pawn Код:
stock SaveStats(playerid)
{
    if (logged[playerid] ==1)
    {
        new string[320];
        format(string,sizeof string,"/sdzadmin/user/%s.ini",PlayerInfo[playerid][pUsername]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    }
}
Reply
#6

+REP FOR BOTH OF YOU
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)