SA-MP Forums Archive
Save / Load prob - 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: Save / Load prob (/showthread.php?tid=494339)



Save / Load prob - JacobSanchez - 12.02.2014

Ok so I think it's saving right... but wont really know till the loading part works right, so I'm not sure what is wrong, if its not saving or if it not loading. please take a look at my code and help me please. if you don't understand what im asking, ask me please i really need this fixed before my server opens in the next few days!

pawn Код:
stock LoadServerStats()
{
    #define SERVER_STATS "serverstats.cfg"

    if(!fexist(SERVER_STATS)) return 1;

    new File:i_FileHandle = fopen(SERVER_STATS, io_read), sz_FileStr[256];
    fread(i_FileHandle, sz_FileStr);
    //sscanf(sz_FileStr, "iiiiiiiiiiii", TotalLogin, TotalConnect, TotalAutoBan, TotalRegister, MaxPlayersConnected, MPDay, MPMonth, MPYear, MPHour, MPMinute, TotalUptime);
    //sz_FileStr = TotalLogin;
    return fclose(i_FileHandle);
}

stock SaveServerStats()
{
    #define SERVER_STATS "serverstats.cfg"
    new sz_FileStr[256];
    new File:i_FileHandle = fopen(SERVER_STATS, io_write);
    //format(sz_FileStr, sizeof(sz_FileStr), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", TotalLogin, TotalConnect, TotalAutoBan, TotalRegister,MaxPlayersConnected,MPDay,MPMonth,MPYear,MPHour,MPMinute,TotalUptime);
    format(sz_FileStr, 256, "%d", TotalLogin);
    fwrite(i_FileHandle, sz_FileStr);
    return fclose(i_FileHandle);
}



Re: Save / Load prob - Private200 - 12.02.2014

Why do you define twice? You shall define it on top of your script.

pawn Код:
// top (after a_samp)

#define SERVER_STATS "serverstats.cfg"

stock LoadServerStats()
{
    if(!fexist(SERVER_STATS)) return 1;

    new File:i_FileHandle = fopen(SERVER_STATS, io_read), sz_FileStr[256];
    fread(i_FileHandle, sz_FileStr);
    //sscanf(sz_FileStr, "iiiiiiiiiiii", TotalLogin, TotalConnect, TotalAutoBan, TotalRegister, MaxPlayersConnected, MPDay, MPMonth, MPYear, MPHour, MPMinute, TotalUptime);
    //sz_FileStr = TotalLogin;
    return fclose(i_FileHandle);
}

stock SaveServerStats()
{
    new sz_FileStr[256];
    new File:i_FileHandle = fopen(SERVER_STATS, io_write);
    //format(sz_FileStr, sizeof(sz_FileStr), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", TotalLogin, TotalConnect, TotalAutoBan, TotalRegister,MaxPlayersConnected,MPDay,MPMonth,MPYear,MPHour,MPMinute,TotalUptime);
    format(sz_FileStr, 256, "%d", TotalLogin);
    fwrite(i_FileHandle, sz_FileStr);
    return fclose(i_FileHandle);
}
That's the code.


Re: Save / Load prob - JacobSanchez - 12.02.2014

ok but still does not work


Re: Save / Load prob - JacobSanchez - 14.02.2014

bump


Re: Save / Load prob - CuervO - 15.02.2014

This might sound a bit obvious, but it doesn't work because it's commented? Or is it commented to point out something?

If you use commas, you need to use the p<,> delimitator on sscanf to let it know to separate by the commas and not by the spaces.


Re: Save / Load prob - JacobSanchez - 15.02.2014

Well that would be needed if i had more than one thing, but i'm only using one thing atm... and plus it is a saving / loading prob i think