SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/05/2013, 09:12 AM   #1
WellDone
Little Clucker
 
Join Date: Jul 2008
Posts: 39
Reputation: 0
Default Make system create and destroy variables automatically

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.

Last edited by WellDone; 13/05/2013 at 10:24 AM.
WellDone is offline   Reply With Quote
Old 13/05/2013, 10:24 AM   #2
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,286
Reputation: 311
Default Re: Let admins read players' PM's selectively without players number limitation

EDIT: posting the code..
RajatPawar is offline   Reply With Quote
Old 13/05/2013, 10:28 AM   #3
WellDone
Little Clucker
 
Join Date: Jul 2008
Posts: 39
Reputation: 0
Default Re: Let admins read players' PM's selectively without players number limitation

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.
WellDone is offline   Reply With Quote
Old 13/05/2013, 10:33 AM   #4
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,286
Reputation: 311
Default Re: Let admins read players' PM's selectively without players number limitation

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
RajatPawar is offline   Reply With Quote
Old 13/05/2013, 10:35 AM   #5
IceCube!
High-roller
 
IceCube!'s Avatar
 
Join Date: Aug 2011
Location: Grove Street, Home; Atleast it was before I fucked everything up. Motto: Carpe Diem, Bitch!
Posts: 1,797
Reputation: 230
Default Re: Let admins read players' PM's selectively without players number limitation

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.
__________________

Image by Phyzic
Projects (28/01/2017)
Skype: Hewlett_T
None.I'm dead, honest!
IceCube! is offline   Reply With Quote
Old 13/05/2013, 10:46 AM   #6
WellDone
Little Clucker
 
Join Date: Jul 2008
Posts: 39
Reputation: 0
Default Re: Let admins read players' PM's selectively without players number limitation

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.
WellDone is offline   Reply With Quote
Old 15/05/2013, 09:34 AM   #7
cessil
High-roller
 
cessil's Avatar
 
Join Date: Apr 2009
Posts: 2,753
Reputation: 296
Default Re: Let admins read players' PM's selectively without players number limitation

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);
cessil is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set a max number of properties per players ? Kethrios Scripting Help 4 22/11/2012 04:34 PM
[HELP] Players press key number 0 .Skool_. Scripting Help 1 19/04/2012 12:00 AM
[FilterScript] [FS] Number of Players Online + Last logged in & OUT! adsy Filterscripts 38 13/08/2011 12:25 PM
Players can ban admins and other players Laur13 Help Archive 5 06/04/2010 09:49 AM
MOVED: Players can ban admins and other players dugi Server Support 0 06/04/2010 09:01 AM


All times are GMT. The time now is 11:52 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.