Set PVarint or something like that to make this save?
#1

pawn Код:
forward OnPlayerSave(playerid);
public OnPlayerSave(playerid)
{
        if(IsPlayerConnected(playerid))
        {
                new string3[32];
                new playername3[MAX_PLAYER_NAME];
                GetPlayerName(playerid, playername3, sizeof(playername3));
                format(string3, sizeof(string3), "SS_%s.ini", playername3);
                new File: hFile = fopen(string3, io_write);
                if(hFile)
                {
                        new var[128];
                        format(var, 32, "SS=%d\n",pInfo[playerid][pSS]);fwrite(hFile, var);
                        fclose(hFile);
                }
        }
        return 1;
}
forward OnPlayerLogin(playerid);
public OnPlayerLogin(playerid)
{
    new string2[128];
    new playername[64];
    new val[ 256 ];
    new Data[ 256 ];
    new key[ 256 ];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string2, sizeof(string2), "SS%s.ini", PlayerName(playerid));
    new File: UserFile = fopen(string2, io_read);
    if ( UserFile )
    {
        key = ini_GetKey( Data );
        if( strcmp( key , "SS" , true ) == 0 )
        {
            val = ini_GetValue( Data );
            pInfo[playerid][pSS] = strvalEx( val );
        }
    }
    fclose(UserFile);
}
stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
stock ini_GetValue( line[] )
{
        new valRes[256];
        valRes[0]=0;
        if( strfind( line , "=" , true ) == -1 ) return valRes;
        strmid( valRes , line , strfind( line , "=" , true )+1 , strlen( line ) , sizeof( valRes ) );
        return valRes;
}
stock strvalEx( str[ ] )
{
    if( strlen( str ) >= 50 ) return -1;
    return strval( str );
}
stock ini_GetKey( line[] )
{
    new keyRes[256];
    keyRes[0] = 0;
    if( strfind( line , "=" , true ) == -1 ) return keyRes;
    strmid( keyRes , line , 0 , strfind( line , "=" , true ) , sizeof( keyRes) );
    return keyRes;
}
The public:

pawn Код:
public OnPlayerSave(playerid)
{
        if(IsPlayerConnected(playerid))
        {
                new string3[32];
                new playername3[MAX_PLAYER_NAME];
                GetPlayerName(playerid, playername3, sizeof(playername3));
                format(string3, sizeof(string3), "SS_%s.ini", playername3);
                new File: hFile = fopen(string3, io_write);
                if(hFile)
                {
                        new var[128];
                        format(var, 32, "SS=%d\n",pInfo[playerid][pSS]);fwrite(hFile, var);
                        fclose(hFile);
                }
        }
        return 1;
}

A guy told me to use SetPVar int or something like that to make this save, because what's below makes it save, and it saves when a player logs in and out, but not on fs reload. Can anyone fix this so that it saves on fs reload, or give me a example to save
pawn Код:
pInfo[playerid][pSS]
with Y_ini or dini or something?
Reply
#2

Quote:
but not on fs reload
pawn Код:
public OnFilterScriptInit()
{
       for(new i=0;i<MAX_PLAYERS;i++)
       {
              if(IsPlayerConnected(i)) OnPlayerLogin(i);
       }
}

public OnFilterScriptExit()
{
       for(new i=0;i<MAX_PLAYERS;i++)
       {
             if(IsPlayerConnected(i)) OnPlayerSave(i);
       }
}
Reply
#3

This made my server crash i am pretty sure i added it correctly, and it says unloaded then my server crashes.

Do you know how to fix this or do you have a Y_ini, or dini etc way of making the variable save? pInfo[playerid][pSS] = 1;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)