Let admins read players' PM's selectively without players number limitation
#1

Hi everyone.
My question involves the very basics of PAWN (I guess).

The thing is that I have created a system which is letting admins to read players' private messages (selectively), but currently I have limited it to 2 players. When an admin enters the first player id, their variable 'readpm' gets equal to this player's id. When they enter the second player id, their variable 'readpm2' gets equal to the second player's id.
Of course, when an admin already has both variables, they're replacing for them further and they're removing when they enter the same variables.

That is how my system's working.


But is it possible to somehow create a system which would let admins read unlimited number of players' PM's?
I mean, without manual assigning new variables for each player being read by admin in the source code.

So, reformulating my question, I mean is there a way to make system create variables automatically and then destroy them when not needed?
Or am I limited to the conception I described above?


Thank you in advance.
Reply
#2

EDIT: posting the code..
Reply
#3

Quote:
Originally Posted by Rajat_Pawar
View Post
Something like this?
No. As I said, I don't need a function allowing admins to read everyone's PM at once.
There was such function in the mod, but I decided to create my own PM's reading system which would allow admins to select which players' PM's they want to read.

The problem is that I had to limit it to 2 players because of my knowledge limitation OR pawn limitation.
Now I just want to find out which limitation it is.
Reply
#4

Sorry to bump this, but it's the way to get your attention.
There's a simple idea:
1) Make a variable for each player -
pawn Code:
new bool: some_var[ MAX_PLAYERS ];
and an array for the admins (
pawn Code:
new a_array[ ] = { // player IDs come here };
)
2) In the event where your admin chooses to enable THAT player's PMs (OnPlayerClickPlayer, or any command) set THAT (not the admin's - the players) player's some_var as true and - in the admin's array, add the player's ID.
3) Under the PM command, check if the player's some_var is true and if it is, then loop through all the admins and check if the player ID is in the admin's array. If yes, send it to him.
4) On Player disconnect, remove the ID from the array.

OR

use the solution below.
Choice is yours
Reply
#5

No you have to place a limit... The limit for this in my server is 10 defined as:

Enum pInfo
{
pListenPM[10]
}

Usage PlayerInfo[playerid][pListenPM][0 - 9]

Outside of enum

Lusten[10]

Usage listen[0-9]

Then you can create a loop looking for blanks in there to fill in, once 10 is reached say 0 is over writable next.
Reply
#6

Rajat_Pawar, many thanks for the reply.

As I never worked with arrays (it is obvious from my, as it turned out, stupid question), can you please explain specifically, what is the code to add players' ID's to the admin's array automatically and also how to "loop through all the admins and check if the player ID is in the admin's array" and how to remove the ID from the array?

I checked SA-MP wiki about arrays, but honestly didn't find out how to make integers add to arrays automatically.

Thank you in advance.

IceCube!, I need a practical example of this also... Would be greatful for this.
Reply
#7

you could use pvars in this case seeing as most the time it won't be used

so to turn it on for the admin you'd format a string to be something like
format(listenString,..,"listeningTo%d",targetid);
then using pvars use that string to set a pvar to 1
SetPVarInt(adminid,listenString,1);

of course then when someone pms someone else you need to check by formatting a string again and looping through to check if an admin is listening in

pawn Code:
format(listenString,sizeof(listenString),"listeningTo%d",playerid);
for(new i=0;i<MAX_PLAYERS;i++)
{
    if(GetPVarInt(i,listenString) == 1)
    {
    //send message to i
    }
}
and to delete you just format the string and delete the PVar DeletePVar(playerid,string);
Reply


Forum Jump:


Users browsing this thread: