How i can make command only for a player
#1

How i can make it with strcmp
Reply
#2

pawn Code:
new playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
if(!strcmp(playerName, "Dark_Kostas", true, 11))//change 11 with the length of your name
{
//your command things in here
}
else return SendClientMessage(playerid, 0xFF000000, "This command is not for you!");
Reply
#3

Quote:
Originally Posted by Dark_Kostas
View Post
pawn Code:
new playerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
if(!strcmp(playerName, "Dark_Kostas", true, 11))//change 11 with the length of your name
{
//your command things in here
}
else return SendClientMessage(playerid, 0xFF000000, "This command is not for you!");
Never use length in comparison checks, unless you want Dark_Kostasxxx to work as well.

OT: Checking names to get access is not a good idea, checking an IP would be better, using a login system would be best.

IP check:
pawn Code:
new ip[16];
GetPlayerIp(playerid, ip, sizeof(ip));
if(!strcmp(ip, "127.0.0.1")) //change 127.0.0.1 with the IP you wish to check against
{
//rest of command
}
As for the login system, you can find plenty of them in the filterscripts forum.
Reply
#4

..
pawn Code:
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
if(!strcmp(pname,"MyName",true)) return SendClientMessage(playerid,-1,"ERROR:You are not this player");
else
{
//do something here
}
return 1;
}
Reply
#5

I don't suggest ip, because there is a chance this player has no static ip.
pawn Code:
// Your Command Here
    new playername[64];
    GetPlayerName(playerid, playername, 64);
    if(!strcmp(playername, "Name_Here", true)) {
        // Code Here
    }
    else {
        SendClientMessage(playerid, -1, "You cannot use this command");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)