Private Commands
#1

Hello guys, i want to make a few commands that will work only for the players that i will choose, when someone else type this command will take a message "You can't use this command" , how can i do this?
Reply
#2

new IsPlayerAuthorized[MAX_PLAYERS];

in onplayerconnect you set it to 0, then when the player may use it set it to 1,

in the cmd do an if statement that checks this variable,

shouldn't be so hard.
Reply
#3

Quote:
Originally Posted by gamer_Z
Посмотреть сообщение
new IsPlayerAuthorized[MAX_PLAYERS];

in onplayerconnect you set it to 0, then when the player may use it set it to 1,

in the cmd do an if statement that checks this variable,

shouldn't be so hard.
i didn't understand, i am beginner o.o
Reply
#4

any help??
Reply
#5

I'm going to show you an example using ZCMD.

So at the top of your script your going to make an array called
pawn Код:
canUse[MAX_PLAYERS];
Then were going to make a "private" command.

pawn Код:
CMD:sayhello(playerid, params[])
{
    if(canUse[playerid] == 0) return SendClientMessage(playerid, 0xFFFF00AA, "You can't use this command!"); //Checks if the array we made was equal to 0, if so sends that client message
    SendClientMessage(playerid, 0xFFFF00AA, "Hello!"); //This will be sent if the array canUse[playerid] is not 0, so it can be 1, 2, etc.
    return 1;
}
And here is command to allow the player to use the "private" command

pawn Код:
CMD:allowcmd(playerid, params[])
{
    if(canUse[playerid] == 1) return SendClientMessage(playerid, 0xFFFF00AA, "You can already use the private commands!"); //Checks if they can already use the commands or not
    canUse[playerid] = 1; //Sets the array to 1, allowing the sayhello command to work
    return 1;
}

*Also, how the array works is its called canUse and then the bracks [] contain a number, which we use for our playeird, so it sets canUse[NUMBER HERE] to our playerid, so it stays unique to that player.. so make sure to also put this OnPlayerDisconnect
pawn Код:
canUse[playerid] = 0;
^ We do this because say I'm id 0, then canUse[playerid] becomes canUse[0] and if I disconnect without making it equal 0 again, if someone joins as id 0, then canUse[0] would still be equal to 1, assuming I had done /allowcmd.
So by doing what I show above, it makes the variable (array) equal to 0 for the new joiner.
Reply
#6

Use booleans for this purpose I don't see whats the point to use an integer to check for somethings thats either on/off.
Reply
#7

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Use booleans for this purpose I don't see whats the point to use an integer to check for somethings thats either on/off.
It really doesn't matter, and this way he learns he can use it for different levels.
Reply
#8

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Use booleans for this purpose I don't see whats the point to use an integer to check for somethings thats either on/off.
I don't see a reason to f*ck around with warnings so just leave it with integers.
No more posts from newbies.
They will learn everithing.
Reply
#9

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Use booleans for this purpose I don't see whats the point to use an integer to check for somethings thats either on/off.
Also booleans are 32-bit values... so it doesn't matter if you are using integers or booleans.
In case of booleans arrays, a bit array is the best choice.
Reply
#10

Quote:
Originally Posted by gamer_Z
Посмотреть сообщение
I don't see a reason to f*ck around with warnings so just leave it with integers.
No more posts from newbies.
They will learn everithing.
Is it just me that never gets warnings with bools?
That didn't make quite sense, now here i'm not acting like i'm the best scripter though i know you're great at scripting, i was told something about booleans being very efficent from someone, i guess i shouldn't follow information by that person again, instead, i should start my own research about the PAWN language.. This isn't the only programming language i know. I know many others but they have different syntax's...

@Double-O-Seven

Didn't notice that, i might make a sort of include for a purpose like that.


I notice he is trying to learn, but he could try learning some basics as well as having booleans introduced
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)