SA-MP Forums Archive
Y_ini INI_WriteInt won't work with timestamps - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Y_ini INI_WriteInt won't work with timestamps (/showthread.php?tid=540603)



Y_ini INI_WriteInt won't work with timestamps - dominik523 - 05.10.2014

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.


Re: Y_ini INI_WriteInt won't work with timestamps - Chenko - 06.10.2014

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.


Re: Y_ini INI_WriteInt won't work with timestamps - dominik523 - 06.10.2014

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); <---
...