Set PVarint or something like that to make this save? - 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: Set PVarint or something like that to make this save? (
/showthread.php?tid=381718)
Set PVarint or something like that to make this save? -
gnoomen2 - 30.09.2012
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 with Y_ini or dini or something?
Re: Set PVarint or something like that to make this save? -
CmZxC - 30.09.2012
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);
}
}
Re: Set PVarint or something like that to make this save? -
gnoomen2 - 30.09.2012
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;