Checking for specific player's name
#1

How do I check for a specific player name?
I want to create a command which works only for one person.
For example:
I want /slap to only work for a guyname John_Slapper.
How do I go about this?
Reply
#2

pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(!strcmp(name,"John_Slapper",true))
{
    // your stuff if the name is John_Slapper!
}
Reply
#3

You create an array to hold the players name. You use strcmp to compare the strings.


pawn Код:
new name[MAX_PLAYER_NAME]; // create an array that holds enough space to store the player name
GetPlayerName(playerid, name, MAX_PLAYER_NAME); // get the player name
if(!strcmp(name, "John_Slapper", false)) // compare both strings to match each other, aka identical
{
    // do cmd
}
Notice the difference in "true" and "false" from the above reply? Well, if you have a registration system that is case sensitive, someone might be able to join your server with different casing, like: "john_slapper" and still be able to execute the command.

The boolean tells the script if it should ignore cases or not.
Reply
#4

EDIT: I am late xD
Reply
#5

Ah, thanks all!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)