[Tutorial] [TUT]How to create forbidden names
#1

How to create forbidden names
So, lots of people wonder about this, and some don't know how to do it, I'll show you how!

First off, lets look at the callback OnPlayerConnect(playerid).

pawn Code:
public OnPlayerConnect(playerid)
{
    return 1;
}
Now, lets use the strfind function:
The parameters are:
strfind(const string[], const sub[], bool:ignorecase=false, pos=0)
  • const string[] = The name string that you want to kick (e.g "Dick")
  • const sub[] = The main key word in the const string
  • bool:ignorecase = false/true Case sensitive if set to true (e.g LoL will kick lol as well)
  • pos != -1 if the string is not found
Lets do an example with the word "LOSER"

pawn Code:
public OnPlayerConnect(playerid)
{
    if(strfind("LOSER", "LOSER", true) != -1)
    {
        SendClientMessage(playerid, 0xFF0000FF, "SERVER: That name is not allowed here!");
        SendClientMessage(playerid, 0xFF0000FF, "SERVER: You have kicked");
        Kick(playerid);
    }
    return 1;
}

I hoped that helped.

-Toni
Reply
#2

Your tutorial is finding the word LOSER inside the word LOSER.
pawn Code:
public OnPlayerConnect(playerid)
{
   new name[MAX_PLAYER_NAME];
   GetPlayerName(playerid, name, MAX_PLAYER_NAME);
   if(!strfind(name, "LOSER", true))
   {
      SendClientMessage(playerid, 0x0000ff, "Name not allowed.");
      Kick(playerid);
   }
   return 1;
}
Reply
#3

this will kick everyone who joins as "LOSER" will allways equal "LOSER"

pawn Code:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    if(!strfind("LOSER", name, true))
    {
        SendClientMessage(playerid, 0xFF0000FF, "SERVER: That name is not allowed here!");
        SendClientMessage(playerid, 0xFF0000FF, "SERVER: You have kicked");
        Kick(playerid);
    }
    return 0;
}
me thinks this would work better

*eedit beat me to it grim
Reply
#4

yeah, well, I didn't really thing of a word to use other then loser, thanks for the tips.
Reply
#5

Instead of a million strfinds, why not do this?

pawn Code:
new ForbiddenNames[][] = {
     "Loser", "Noob", "Admin", "Moderator", "VIP"
};

public OnPlayerConnected(playerid) {
     for(new i = 0; i < sizeof(ForbiddenNames); i ++ ) {
         if(!strcmp(name, i, true)) {
             SendClientMessage(playerid, 0xFF0000FF, "SERVER: That name is not allowed here!");
             SendClientMessage(playerid, 0xFF0000FF, "SERVER: You have kicked");
             Kick(playerid);
         }
     }
     return 1;
}
I don't get why you're using strfind to get someone's banned name. You're just finding a word inside of it, the point was to forbid the name.
Reply
#6

I understand forbidden names will be a plus, but do you know how often people join and leave a server? (the big ones) The function would get called a lot, therefore lagging the server.
Reply
#7

Look, I know there are many ways to do it, I just chose a different way.

And don't just start a fight on that either...
Reply
#8

Yeah, I know there are different ways. I wasn't criticizing what you did, I was just stating my opinion.
Reply
#9

Well, there are a range or reasons why you would use strfind E.G. A blocked name is FUCKADMINS and someone could come on as FUCKADMINS1 etc.
Reply
#10

Is there any reason that someone has deleted mine and noobinatoirs posts?

- Had to edit and re-post. It seems the code was "hidden"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)