How i can make command only for a player - 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: How i can make command only for a player (
/showthread.php?tid=304161)
How i can make command only for a player -
boyan96 - 17.12.2011
How i can make it with strcmp
Re: How i can make command only for a player -
Dark_Kostas - 17.12.2011
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!");
Re: How i can make command only for a player -
SloProKiller - 17.12.2011
Quote:
Originally Posted by Dark_Kostas
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.
Re: How i can make command only for a player -
vassilis - 17.12.2011
..
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;
}
Re: How i can make command only for a player -
Kostas' - 17.12.2011
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;
}