Save / Load prob
#1

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);
}
Reply
#2

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.
Reply
#3

ok but still does not work
Reply
#4

bump
Reply
#5

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.
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)