Restricting names
#1

Is there a way I can make a file in scriptfiles, example:

Quote:

John_Big
Wayne_Johnson
Oele_Piemel

and whenever a player connects it will check if the name is in the file, if it is, kick them?
Reply
#2

That's not needed. Just add this code under the OnPlayerConnect callback.
PHP код:
new PlayerName[24]; 
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
if(
strcmp(PlayerName,"John_Big",true)) 
{
 
Kick(playerid);
}
if(
strcmp(PlayerName,"Wayne_Johnson",true)) 
{
 
Kick(playerid);
}
if(
strcmp(PlayerName,"Oele_piemel",true)) 
{
 
Kick(playerid);

Reply
#3

Quote:
Originally Posted by karan007
Посмотреть сообщение
That's not needed. Just add this code under the OnPlayerConnect callback.
PHP код:
new PlayerName[24]; 
GetPlayerName(playeridPlayerNamesizeof(PlayerName));
if(
strcmp(PlayerName,"John_Big",true)) 
{
 
Kick(playerid);
}
if(
strcmp(PlayerName,"Wayne_Johnson",true)) 
{
 
Kick(playerid);
}
if(
strcmp(PlayerName,"Oele_piemel",true)) 
{
 
Kick(playerid);

Yes, I was aware this was possible but I just gave an example of names.
In reality I want to block ALOT of names and doing it that way will take alot of time
Reply
#4

PHP код:
new PlayerName[24];  
GetPlayerName(playeridPlayerNamesizeof(PlayerName)); 
if(
strcmp(PlayerName,"John_Big" || "Name" || "Name",true))  // Use or ||

 
Kick(playerid); 

Try this.
Reply
#5

Quote:
Originally Posted by karan007
Посмотреть сообщение
PHP код:
new PlayerName[24];  
GetPlayerName(playeridPlayerNamesizeof(PlayerName)); 
if(
strcmp(PlayerName,"John_Big" || "Name" || "Name",true))  // Use or ||

 
Kick(playerid); 

Try this.
Do you even know what you are doing dude?
Reply
#6

Quote:
Originally Posted by karan007
Посмотреть сообщение
PHP код:
new PlayerName[24];  
GetPlayerName(playeridPlayerNamesizeof(PlayerName)); 
if(
strcmp(PlayerName,"John_Big" || "Name" || "Name",true))  // Use or ||

 
Kick(playerid); 

Try this.
What are you doing?

Quote:
Originally Posted by Sellize
Посмотреть сообщение
Do you even know what you are doing dude?
That is possible, yes. Though why don't you just add a variable to their account?
Reply
#7

Quote:
Originally Posted by BleverCastard
Посмотреть сообщение
What are you doing?


That is possible, yes. Though why don't you just add a variable to their account?
It's not like that.
I just want to ban people from using certain names that might influence their reputation on my server.
Reply
#8

You need a datasource. What that source is, is up to you. It can be a hard coded array, or a file, or a table in a database. In either case, you will need to find out if the name exists in the datasource. For arrays and fiiles the method is similar: loop through the entire list to find out if the name is in there. For databases, a regular select.
Reply
#9

Okay, lets say you have a file called 'BlockedNames.txt' in your scriptfiles folder.

I'm going to assume you're using ZCMD and SSCANF just to make my life easier.

pawn Код:
CMD:blockname(playerid, params[])
{
    // if(!IsPlayerAdmin(playerid)) return 0; // Your admin variable here, blah blah
    new targetname[MAX_PLAYER_NAME];
    if(sscanf(params, "s", targetname)) return SendClientMessage(playerid, -1, "USAGE: /blockname [player name]");
    new append[55];
    format(append, sizeof(append), "%s\r\n", targetname);
    new File:blockedlist = fopen("BlockedNames.txt", io_append);
    if(!blockedlist) return SendClientMessage(playerid, -1, "Failed to open blocked names list.");
    fwrite(blockedlist, append);
    fclose(blockedlist);
    format(append, sizeof(append), "Name '%s' successfully blocked.", targetname);
    SendClientMessage(playerid, -1, append);
    return 1;
}

public OnPlayerConnect(playerid)
{
    CheckBlockedName(playerid);
    return 1;
}

CheckBlockedName(playerid)
{
    if(!fexist("BlockedNames.txt")) return 0;
    new File:blockedlist = fopen("BlockedNames.txt", io_read);
    new output[30], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, sizeof(playername));
    while(fread(blockedlist, output))
    {
        if(!strcmp(playername, output, true))
        {
            // Player is using a blocked name, kick player?
            break;
        }
    }
    return 1;
}
References:
https://sampwiki.blast.hk/wiki/Fopen
https://sampwiki.blast.hk/wiki/Fwrite
https://sampwiki.blast.hk/wiki/Fread
https://sampwiki.blast.hk/wiki/Strcmp
https://sampwiki.blast.hk/wiki/GetPlayerName

EDIT: By the way, this is one of the 'data source' methods that Vince mentioned.
Reply
#10

Pretty simple, using simple string and file functions:
pawn Код:
#define MAX_NAMES 100//how many mximum names your file can have

new bad_names[MAX_NAMES][MAX_PLAYER_NAME + 7];
new total_bad_names_from_file = 0;

public OnGameModeInit()
{
    new File:file = fopen("bad_names.txt", io_read);
    new names[MAX_PLAYER_NAME + 7];//7 for extra characters
    if(file)
    {
        while(fread(file, names))
        {
            for(new i, j = strlen(names); i < j; i++)
            {
                if(names[i] == '\n' || names[i] == '\r')
                {
                    names[i] = '\0';
                }
                bad_names[total_bad_names_from_file] = names;
                //add to total
                total_bad_names_from_file += 1;
            }
        }
        fclose(file);
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new username[MAX_PLAYER_NAME];
    GetPlayerName(playerid, username, sizeof(username));
    for(new i; i < total_bad_names_from_file; i++)
    {
        if(! strcmp(bad_names[i], username))
        {
            Kick(playerid);//kick the player
            return 1;
        }
    }
    return 1;
}
This will allow you kick all the players listed in Scriptfiles/bad_names.txt.

EDIT: i was late in replying though but this one works well.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)