18.07.2011, 09:29
It's quite simple; You can use PVars to store and set the players VIP rank and save it to a file. When they enter the server, set their VIP level to that in the file.
Now that it is saved and loaded, you can set the player's level like so:
You can also access the variable inside of commands, for example, to see if they can use it or not.
pawn Код:
public OnPlayerConnect( playerid )
{
new name[ MAX_PLAYER_NAME ], file[ MAX_PLAYER_NAME + 9 ], File: h;
GetPlayerName( playerid, name, MAX_PLAYER_NAME );
format( file, sizeof( file ), "VIP/%s.ini", name );
if( fexists( file ) )
{
h = fopen( file, io_read );
fread( h, file ); // we re-use the 'file' variable as it won't be used anymore, and ther'es no need to create another
new pos = strfind( file, "=", true );
SetPVarInt( playerid, "VIP", strval( file[ pos + 1 ] ) );
fclose( h );
}
return 1;
}
public OnPlayerDisconnect( playerid, reason )
{
new name[ MAX_PLAYER_NAME ], file[ MAX_PLAYER_NAME + 9 ], File: h;
GetPlayerName( playerid, name, MAX_PLAYER_NAME );
format( file, sizeof( file ), "VIP/%s.ini", name );
h = fopen( file, io_write );
format( file, sizeof( file ), "VIP=%i", GetPVarInt( playerid, "VIP" ) ); // Once again re-using 'file' variable
fwrite( h, file );
fclose( h );
return 1;
}
pawn Код:
SetPVarInt( playerid, "VIP", /*level here*/ );
pawn Код:
CMD:command( playerid, params[ ] )
{
if( GetPVarInt( playerid, "VIP" ) > 0 )
{
// code here
}
return 1;
}