/blockpm (Best way to make it-Structure)
#1

Hi guys
I want to make /blockpm on my server,with that command players can block PM for some players.I don't know on which way I can save it if I want that they can block more players?Is there any way that it can be unlimited?

Thank you and sorry for my bad English!
Reply
#2

Should the block be temporary (until you leave the server) or be persistent between sessions?

A char array will work, although it will be pretty big (1000 * 1000 bytes).

If you want to save them, a database is the best solution (MySQL or SQLite), using a seperate table for blocked users (so every block will be saved there, instead of having a block list for each player).
Reply
#3

Hello, GospodinX, there are some ways to do this, the first and easiest, is usal a Boolean variable to store the correct value with the player, as the example below:
PHP код:
new bool:BlockPMCheck[MAX_PLAYERS]; 
If you want to block the PM of any other player, when writing the command / blockpm you should change this value to true;

So when a player sends a PM, just make sure that the player's variable that will receive the message is either true or false, EX:

PHP код:
if(BlockPMCheck[targetid] == false)
{
    
//Then the message will be sent
}
else
{
    
//Otherwise you are informed that the player has blocked the PM.
    
SendClientMessage(playeridRED"Player has blocked PM");

This is the simple way, and will block for all players, now if you want to block a specific person, then you just store the ID of the person you want to lock in the variable, let's look at the example:

You write /blockpm 19 (id 19 for example)

Now the variable need not be more Boolean because it will store integer values, not just logical values;

PHP код:
new BlockPmID[MAX_PLAYERS]; //then you define the variable globally 
As stated in the example above with id 19, when giving the command just save this value in the variable, that is, our variable (BlockPmID) will be equal to 19.

Now you just need to check if the ID of the player who sent the PM is equal to or different from the ID stored in the variable:

PHP код:
if(BlockPmID[targetid] == GetPlayerID(playerid))
{
    
//If equal, you are informed that the player has blocked the PM.
    
SendClientMessage(playeridRED"Player has blocked you.");
}
else
{
    
//Otherwise, the message is sent.

OBS№ = The problem arises when GM is reset, or you Re-login in the server, because your variables are restored, so you have to lock again, but you can use DOF2 to store the names of blocked players, so you do not have to lock all of them again when you are on the server, CLICK HERE.

OBSІ = You can work with Arrays to store multiple ID's, I advise you to read about, CLICK HERE.

OBSі = You can use too ZCMD or SSCANF for a better management of codes, CLICK HERE.

The logic and concept are simple, I hope you have understood.
Reply
#4

Thank on answers.
So there is only way to make array for example:
Quote:

new BlockPmID[MAX_PLAYERS][10];

So that an player can block only 10 players.

Quote:

If you want to save them, a database is the best solution (MySQL or SQLite), using a seperate table for blocked users (so every block will be saved there, instead of having a block list for each player).

Yes,I use MySQL,and I will store it.But I just don't know what is best way to store it on variable(I don't like that I need to limit how much blocked players they can have..Someone maybe want to block 5 players,someone 100...
Reply
#5

also
pawn Код:
new bool:BlockPmID[MAX_PLAYERS][MAX_PLAYERS char];
re-define MAX_PLAYERS to your real server slots instead of 1000 or you can use also bit array
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)