Y_Ini writing issue
#1

Hello again, Can anyone tell me how can i write the Business IDs in 2 separate lines? I mean there should be something like this in the file

Код:
Jailed = 1
Muted = false
RulesRead = true
Business = 45
Business = 68
I tried this code
pawn Код:
pData_Save(playerid)
{
    new
        INI:File = INI_Open(User_Directory(playerid));

    INI_SetTag(File, "db");
    INI_WriteInt(File, "MoneyBoost", pInfo[playerid][MoneyBoost]);
    INI_WriteInt(File, "BoostTime", pInfo[playerid][BoostTime]);
    INI_WriteInt(File, "Jailed", pInfo[playerid][Jailed]);
    INI_WriteBool(File, "Muted", pInfo[playerid][Muted]);
    INI_WriteBool(File, "RulesRead", pInfo[playerid][RulesRead]);

    for(new i; i < MAX_BUSINESSPERPLAYER; i++)
    {
        if(pInfo[playerid][Business][i] != 0)
        {
            INI_WriteInt(File, "Business",  pInfo[playerid][Business][i]);
        }
    }
    INI_Close(File);
    return 1;
}
But with this, it will store the player's first business id and if they buy another, its replacing the first business id with the second one, not creating a new line for the second business id. The same code worked fine with the default file saving system but with y_ini, its not working. I searched around the whole forums + ******, but couldn't find anything related to this.
Reply
#2

I think you can't do that.
You can either just have two similar names; Business, Business2, etc.
Reply
#3

Separate the "Business" as "Business1" and "Business2".
Reply
#4

But how can i do that? Currently i have to loop through MAX_BUSINESSESPERPLAYER and check if the slot is free or not to get the player's business id, and i don't know how to create 2 different names (Business 1/Business2) and store the ids there.

Can you guys give me a little example?
Reply
#5

I tried something like this
pawn Код:
pData_Save(playerid)
{
    new
        INI:File = INI_Open(User_Directory(playerid)),
        string[24],
        Index
    ;

    INI_SetTag(File, "db");
    INI_WriteInt(File, "MoneyBoost", pInfo[playerid][MoneyBoost]);
    INI_WriteInt(File, "BoostTime", pInfo[playerid][BoostTime]);
    INI_WriteInt(File, "Jailed", pInfo[playerid][Jailed]);
    INI_WriteBool(File, "Muted", pInfo[playerid][Muted]);
    INI_WriteBool(File, "RulesRead", pInfo[playerid][RulesRead]);
    INI_WriteInt(File, "House-ID", pInfo[playerid][pHouse_ID]);
    for(new i; i < MAX_BUSINESSPERPLAYER; i++)
    {
        if(pInfo[playerid][Business][i] != 0)
        {
            format(string, sizeof(string), "\nBusiness", pInfo[playerid][Business][Index]);
            INI_WriteInt(File, string, pInfo[playerid][Business][i]);
        }
    }
    INI_Close(File);
    return 1;
}
The result i got is this

Код:
[db]
MoneyBoost = 0
BoostTime = 0
Jailed = 0
Muted = false
RulesRead = true
House-ID = 0

Business = 5

Business = 4
It kinda worked but there are spaces, i guess its because of \n? And if i don't use \n, the result is same as before, its replacing the business id without \n. I could only try that so far, please correct if its done wrong.
Reply
#6

/Bump

I have been trying and trying but nothing. :/
Reply
#7

You could make it work by:
  • Counting the amount of businesses that player has
  • Adding a number after Business (Ex: Business2) using format
  • Saving them
Reply
#8

PHP код:
pData_Save(playerid)
{
    new
        
INI:File INI_Open(User_Directory(playerid)),
        
string[24],
        
Index
    
;

    
INI_SetTag(File"db");
    
INI_WriteInt(File"MoneyBoost"pInfo[playerid][MoneyBoost]);
    
INI_WriteInt(File"BoostTime"pInfo[playerid][BoostTime]);
    
INI_WriteInt(File"Jailed"pInfo[playerid][Jailed]);
    
INI_WriteBool(File"Muted"pInfo[playerid][Muted]);
    
INI_WriteBool(File"RulesRead"pInfo[playerid][RulesRead]);
    
INI_WriteInt(File"House-ID"pInfo[playerid][pHouse_ID]);
    for(new 
iMAX_BUSINESSPERPLAYERi++)
    {
        if(
pInfo[playerid][Business][i] != 0)
        {
            
format(stringsizeof(string), "Business%d"i);
            
INI_WriteInt(FilestringpInfo[playerid][Business][i]);
        }
    }
    
INI_Close(File);
    return 
1;

Reply
#9

Fixed, thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)