Y_ini INI_WriteInt won't work with timestamps
#1

Hey all! I found little problem when creating register/login system with Y_ini.
Under OnPlayerDisconnect I'm saving current time with gettime() function but I can't save into file current seconds in timestamps. Here is my code:
pawn Code:
// enum with player's stats
...
       pLastVisit
}
// OnPlayerDisconnect:
PlayerInfo[playerid][pLastVisit] = gettime();
SavePlayer(playerid);

// SavePlayer function
INI_WriteInt(file, "LastVisit", PlayerInfo[playerid][pLastVisit]);
Does anyone know how to fix this? I've seen somewhere that saving unix timestamps as strings works but I think it would be easier with integers.
Reply
#2

I remember having this issue and the easiest fix was to edit the y_ini include.

Open up the y_ini.inc file that you use to compile and search for:

Code:
stock INI_WriteInt
Then replace this line:

Code:
valstr(str, data);
With this:

Code:
format(str, sizeof(str), "%d", data);
For whatever reason valstr can't handle numbers over 1.4 billion or so. Also, if you don't wish to edit the y_ini include then you can use the fixes include.
Reply
#3

Quote:
Originally Posted by Chenko
View Post
I remember having this issue and the easiest fix was to edit the y_ini include.

Open up the y_ini.inc file that you use to compile and search for:

Code:
stock INI_WriteInt
Then replace this line:

Code:
valstr(str, data);
With this:

Code:
format(str, sizeof(str), "%d", data);
For whatever reason valstr can't handle numbers over 1.4 billion or so. Also, if you don't wish to edit the y_ini include then you can use the fixes include.
Thank you very much for your answer.

EDIT: Okay, it wasn't working when I changed that line from valstr to format, but I also changed one more thing and it works now without fixes.inc.
pawn Code:
stock INI_WriteInt(INI:file, name[], data)
{
    P:3("INI_WriteInt called: %i, \"%s\", %i", _:file, name, data);
    new
        str[12];
    format(str, sizeof(str), "%d", data);
    INI_AddToBuffer(file, name, str);
}

stock INI_WriteArray(INI:file, const name[], data[], len)
{
    // Write 6 bits at a time, in 3 cell chunks.  It takes 16 bytes to record
    // three cells with 6 bits per byte.
    P:4("INI_WriteArray called");
    new
        dname[MAX_INI_ENTRY_NAME],
        write[Y_INI_WRITE_ARRAY_SIZE + 1],
        idx,
        wi,
        iter;
    // Write the length first just so the data exists.
    //INI_WriteInt(file, name, len);
    //valstr(write, len);  <---
    format(write, sizeof(write), "%d", len); <---
...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)