Problem with Y_Ini
#1

Hello.

I am using Y_Ini to save some of players' data.

The RulesRead variable is to show the rules dialog in OnPlayerRequestSpawn callback if they haven't accepted the rules yet and if its set to 1, it shouldn't show the dialog again but its showing even if the value is set to 1 in the player data file. Same script was working fine in my backup server which had Y_ini for all the player data. I moved to mysql and since these 4 variables aren't necessary to save in mysql db, i thought of making a separate file using Y_ini and found the problem with RulesRead variable. I have inventory file system with the same method and its working fine. I guess something is wrong on the dialog?

pawn Код:
#define DATA_DIRECTORY              "/Player Data/%s.ini"

forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
    new HouseIndex, BusIndex;
    INI_Int("MoneyBoost",       pInfo[playerid][MoneyBoost]);
    INI_Int("BoostTime",        pInfo[playerid][BoostTime]);
    INI_Int("Jailed",           pInfo[playerid][Jailed]);
    INI_Int("RulesRead",        pInfo[playerid][RulesRead]);
    INI_Int("Houses",           pInfo[playerid][Houses][HouseIndex]);  HouseIndex++;
    INI_Int("Business",         pInfo[playerid][Business][BusIndex]);  BusIndex++;
    return 1;
}

stock pData_Create(playerid)
{
    new INI:File = INI_Open(DataPath(playerid));
    INI_SetTag(File,"DATA");
    INI_WriteInt(File, "MoneyBoost", 0);
    INI_WriteInt(File, "BoostTime", 0);
    INI_WriteInt(File, "Jailed", 0);
    INI_WriteInt(File, "RulesRead", 0);
    INI_Close(File);
}

stock pData_Save(playerid)
{
    new INI:File = INI_Open(DataPath(playerid));
    INI_SetTag(File,"DATA");
    INI_WriteInt(File, "MoneyBoost", pInfo[playerid][MoneyBoost]);
    INI_WriteInt(File, "BoostTime", pInfo[playerid][BoostTime]);
    INI_WriteInt(File, "Jailed", pInfo[playerid][Jailed]);
    INI_WriteInt(File, "RulesRead", pInfo[playerid][RulesRead]);
    for (new i; i < MAX_HOUSESPERPLAYER; i++)
        if (pInfo[playerid][Houses][i] != 0)
            INI_WriteInt(File, "Houses", pInfo[playerid][Houses][i]);
    for (new i; i < MAX_BUSINESSPERPLAYER; i++)
        if (pInfo[playerid][Business][i] != 0)
            INI_WriteInt(File, "Businesses", pInfo[playerid][Business][i]);
    INI_Close(File);
    for (new i; i < MAX_HOUSESPERPLAYER; i++)
        if (pInfo[playerid][Houses][i] != 0)
            HouseFile_Save(pInfo[playerid][Houses][i]);
    for (new i; i < MAX_BUSINESSPERPLAYER; i++)
        if (pInfo[playerid][Business][i] != 0)
            BusinessFile_Save(pInfo[playerid][Business][i]);
    return 1;
}

stock DataPath(playerid)
{
    new str[128], Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name,sizeof(Name));
    format(str,sizeof(str), DATA_DIRECTORY, Name);
    return str;
}

public OnPlayerDisconnect(playerid, reason)
{
    pData_Save(playerid);
    //some other codes are here
    return 1;
}

public OnPlayerConnect(playerid)
{
    //some other codes are here
    if(fexist(DataPath(playerid)))
        INI_ParseFile(DataPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
    return 1;
}

Dialog_Rules(playerid, response)
{
    if(!response)
    {
        Timer_Disconnect[playerid] = SetTimerEx("DisconnectPlayer", 100, false, "d", playerid);
        SendClientMessage(playerid, DARK_RED, "We do not allow any players who don't follow our server rules!");
    }
    if(response)
    {
        if (pInfo[playerid][RulesRead] == 0)
        {
            RewardPlayer(playerid, 10000, 5);
            pInfo[playerid][RulesRead] = 1;
            SendClientMessage(playerid, YELLOW, "You got $10000 and 5 score for accepting our server's rules.");
            pData_Save(playerid);
        }
    }
    return 1;
}

//In register dialog
pData_Create(playerid);

//In login dialog
INI_ParseFile(DataPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
Reply
#2

You forgot to show the code where you show the rules read dialog.
Reply
#3

I have added it. Dialog_Rules(playerid, response) Shows in OnPlayerRequestClass
Reply
#4

Yeah you showed the stock, but not the code that shows it. We need to see your OnPlayerRequestClass bit.
Reply
#5

Oh i just noticed i didn't include it. Sorry.

pawn Код:
public OnPlayerRequestSpawn(playerid)
{
    //Other codes are up here
    if(pInfo[playerid][RulesRead] == 0)
        RulesList_Create(playerid);
    return 1;
}
Reply
#6

It's probably because you're calling it under OnPlayerRequestSpawn, and when the player first connects it gets called before the players data is loaded, there fore it doesn't know what the value of RulesRead is. Try doing it on OnPlayerSpawn, something like this:

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(gIsPlayerLoggedIn)
    {
        // spawn codes
    }
    else
    {
        if(pInfo[playerid][RulesRead] == 0)
        {
            // show rules
        }
        else
        {
            // show login/register..
        }
    }
    return 1;
}
Reply
#7

I believe 'SetTag(File, "DATA");' should be 'SetTag(File, "data");'.
Reply
#8

Quote:
Originally Posted by Threshold
Посмотреть сообщение
I believe 'SetTag(File, "DATA");' should be 'SetTag(File, "data");'.
It doesn't matter if a tag is upper case or lower case.
Reply
#9

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
It doesn't matter if a tag is upper case or lower case.
Wrong.
Reply
#10

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Wrong.
https://sampforum.blast.hk/showthread.php?tid=175565

Quote:
Originally Posted by ******
new
INI:ini = INI_Open("myini.ini");
INI_SetTag(ini, "LVDM");
INI_WriteString(ini, "NAME", "******");
INI_WriteInt(ini, "SCORE", gScore);
INI_Close(ini);
Reply


Forum Jump:


Users browsing this thread: