SA-MP Forums Archive
Y_Ini - Reading string (i tried..) - 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 - Reading string (i tried..) (/showthread.php?tid=280121)



Y_Ini - Reading string (i tried..) - Riddick94 - 30.08.2011

So.. it's saving:

pawn Код:
format(OnlineTime, sizeof(OnlineTime), "%02d:%02d:%02d", PlayerInfo[playerid][pOnlineHours], PlayerInfo[playerid][pOnlineMinutes], PlayerInfo[playerid][pOnlineSeconds]);

INI_WriteString(Account,        "Online_Time",      OnlineTime);
And now to load.. i tried with format, strval(value), strlen(value) and other options..

pawn Код:
if(!strcmp(name, "Online_Time"))
{
        PlayerInfo[playerid][pOnlineHours]      = strval(value);
        PlayerInfo[playerid][pOnlineMinutes]    = strval(value);
        PlayerInfo[playerid][pOnlineSeconds]    = strval(value);
}
But i dunno what to do to read it.. oh.. and i tried with INI_String.. no results.


Re: Y_Ini - Reading string (i tried..) - [MWR]Blood - 30.08.2011

Quote:
pawn Код:
if(!strcmp(name, "Online_Time"))
{
        PlayerInfo[playerid][pOnlineHours]      = strval(value);
        PlayerInfo[playerid][pOnlineMinutes]    = strval(value);
        PlayerInfo[playerid][pOnlineSeconds]    = strval(value);
}
But i dunno what to do to read it.. oh.. and i tried with INI_String.. no results.

Your current code ain't gonna do it...
Show your attempts of INI_String.


Re: Y_Ini - Reading string (i tried..) - Jeffry - 30.08.2011

Hi, try this:

(I guess 'value' is the string name)
pawn Код:
if(!strcmp(name, "Online_Time"))
{
    new tmpx[20], which;
    for(new i=0; i<strlen(value); i++)
    {
        if(value[i] == ':')
        {
            if(which == 0) PlayerInfo[playerid][pOnlineHours] = strval(tmpx);
            if(which == 1) PlayerInfo[playerid][pOnlineMinutes] = strval(tmpx);
            format(tmpx, sizeof(tmpx), "");
            which++;
        }
        else format(tmpx, sizeof(tmpx), "%s%c", tmpx, value[i]);
    }
    PlayerInfo[playerid][pOnlineSeconds] = strval(tmpx);
}
I hope this works, let me know if there are any problems.

Jeffry


Re: Y_Ini - Reading string (i tried..) - Riddick94 - 30.08.2011

Works. To lock.


Re: Y_Ini - Reading string (i tried..) - AndreT - 30.08.2011

There's no need to write such a complex loader for something like this alone. There's a much much more complex unformatting function for that... sscanf 2.0.

This would be very simple:
pawn Код:
sscanf(value, "p<:>ddd", PlayerInfo[playerid][pOnlineHours], PlayerInfo[playerid][pOnlineMinutes], PlayerInfo[playerid][pOnlineSeconds]);
Edit
To save some memory, you could make pOnlineMinutes and pOnlineSeconds char arrays. This reduces the size by half and would be usable since minutes and seconds never go near 255.
pawn Код:
new pOnlineHours[MAX_PLAYERS], pOnlineMinutes[MAX_PLAYERS char], pOnlineSeconds[MAX_PLAYERS char];
// In your 1-second loop...
pOnlineSeconds{playerid} ++;
if(pOnlineSeconds{playerid} == 60)
{
    pOnlineSeconds{playerid} = 0, pOnlineMinutes{playerid} ++;
    if(pOnlineMinutes{playerid} == 60)
    {
        pOnlineMinutes{playerid} = 0, pOnlineHours[playerid] ++;
    }
}