SA-MP Forums Archive
Checking for specific player's name - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Checking for specific player's name (/showthread.php?tid=349499)



Checking for specific player's name - cosbraa - 09.06.2012

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?


Re: Checking for specific player's name - [KHK]Khalid - 09.06.2012

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!
}



AW: Checking for specific player's name - Extremo - 09.06.2012

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.


Re: Checking for specific player's name - zombieking - 09.06.2012

EDIT: I am late xD


Re: Checking for specific player's name - cosbraa - 09.06.2012

Ah, thanks all!