SA-MP Forums Archive
ifIsplayername - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: ifIsplayername (/showthread.php?tid=111076)



ifIsplayername - patchkinson - 29.11.2009

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


Re: ifIsplayername - lolumadd - 29.11.2009

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);
}



Re: ifIsplayername - patchkinson - 29.11.2009

nice nice! will try now


Re: ifIsplayername - patchkinson - 29.11.2009

i dont need to do return 1;
?


Re: ifIsplayername - lolumadd - 29.11.2009

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.


Re: ifIsplayername - patchkinson - 29.11.2009

yea
that was siliness of me
ty


Re: ifIsplayername - Mike Garber - 04.12.2009

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;


Re: ifIsplayername - Donny_k - 04.12.2009

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).


Re: ifIsplayername - HydraX - 04.12.2009

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


Re: ifIsplayername - Gappy - 04.12.2009

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