ifIsplayername
#1

How to make
ifisplayername patch or john or jake
kick(playerid);
else
ban(playerid);
How can i do that?
Reply
#2

pawn Код:
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
if(strcmp(Name, "John", true) == 0)
{
SendClientMessage(playerid, COLOR, "Welcome John!");
}
else
{
SendClientMessage(playerid, COLOR, "Good-bye");
Kick(playerid);
}
Reply
#3

nice nice! will try now
Reply
#4

i dont need to do return 1;
?
Reply
#5

Quote:
Originally Posted by patchkinson
i dont need to do return 1;
?
You dont need one although you can add it. A return only stops the code from doing anything else.
Reply
#6

yea
that was siliness of me
ty
Reply
#7

Quote:
Originally Posted by patchkinson
yea
that was siliness of me
ty
No, It was not silly.
You are smart, because If you do not return 1; the code will repeat itself, in most cases.
So add return 1;
Reply
#8

Quote:
Originally Posted by mavtias
Quote:
Originally Posted by patchkinson
yea
that was siliness of me
ty
No, It was not silly.
You are smart, because If you do not return 1; the code will repeat itself, in most cases.
So add return 1;
"return" stops the routine it is linked to (in the scope of), nothing will loop unless you tell it to do so (while,for,do).

In callbacks (events) some returns have an important value as it tells the Pawn VM what to do like allow other scripts to process the same callback or like in texts it controls if or not you see the message:

pawn Код:
@ OnPlayerCommandText(......)
{
  return 1; //no message, the command is processed
  return 0; //SUC message, the command wasn't valid or was unable to be processed
}

@ OnPlayerText(......)
{
  return 1; //message, the chat is processed
  return 0; //no message, this script won't process the chat
}
Take a look in the pdf for an explination of "return" or look at some of the many script examples we have around the forum (any GM, FS, INC).
Reply
#9

Quote:
Originally Posted by lolumadd [cod5server.tk
]
pawn Код:
new Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
if(strcmp(Name, "John", true) == 0)
{
SendClientMessage(playerid, COLOR, "Welcome John!");
}
else
{
SendClientMessage(playerid, COLOR, "Good-bye");
Kick(playerid);
}
Won't that kick other people whose name isnt John
Reply
#10

You could do this:

pawn Код:
//At the top of your script
new InvalidNames[][] = {
  "Patch",
  "John",
  "Jake" //add as many names as you want, just don't put a comma(,) on the last one
};

public OnPlayerConnect(playerid)
{
  new pName[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pName, sizeof(pName));
  for(new i = 0; i < sizeof(InvalidNames); i++)
  {
    if(!strcmp(pName, InvalidNames[i], true))
    {
      Kick(playerid);
    }
  }
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)