03.08.2011, 17:52
How To Save Players Score Using No Extra Include Like dini, Y_ini, Fini.
Just Include <samp>. Can Anyone Tell Me?
Just Include <samp>. Can Anyone Tell Me?
// For saving:
new name[MAX_PLAYER_NAME], scr, string[64];
GetPlayerName( playerid, name, sizeof(name) );
scr = GetPlayerScore( playerid );
format( string, sizeof(string), "%s.scr" );
new File:userfile = fopen( string, io_write );
format( string, sizeof(string), "%i",scr );
fwrite( userfile, string );
fclose( userfile );
return 1;
// For Loading:
new name[MAX_PLAYER_NAME], string[64];
GetPlayerName( playerid, name, sizeof(name) );
format( string, sizeof(string), "%s.scr" );
if( !fexist(string) ) return true;
new File:userfile = fopen( string, io_read );
fread( userfile, string );
fclose( userfile );
SetPlayerScore( playerid, strval(string) );
return 1;
//saving:
new
file[ 128 ]
,pName[ 24 ]
;
GetPlayerName( playerid, pName, 24 );
format( file, sizeof file, "%sscr.txt", pName );
if( !dini_Exists( file ) ) {
dini_Create( file );
}
dini_IntSet( file, "score", GetPlayerScore( playerid ) );
//loading:
new
file[ 128 ]
,pName[ 24 ]
;
GetPlayerName( playerid, pName, 24 );
format( file, sizeof file, "%sscr.txt", pName );
if( dini_Exists( file ) ) {
SetPlayerScore( playerid, dini_Int( file, "score" ) );
}
It's because you save it in OnPlayerDisconnect, and you can't save it on timeout/disconnect. Try to leave the server, and join back in, your score will probably be the same from when you left.
Anyways, here's a DINI version, which I wouldn't recommend: pawn Код:
|
SavePlayer(playerid)
{
new filename[64];
format(filename, sizeof(filename), "users/%s.ini", PlayerName(playerid));
new File:handle = fopen(filename, io_write);
new line[128];
format(line, sizeof(line), "Score=%d\r\n", GetPlayerScore(playerid)); fwrite(handle, line);
fclose(handle);
}