Forbidname [help]
#6

Rough example
pawn Код:
CMD:forbidname(playerid, params[])
{
    new
        name[24], // The name to write
        string[28] // The string we will be writing.
    ;
    if(isnull(params)) // If they didn't type a name.
    {
        return SendClientMessage(playerid, -1, "USAGE: /forbidname [name]");
    }
    else
    {
        File:names = fopen("forbidden_names.txt",io_append); // Opens the file for writing.
        format(string, 28, "%s\r\n", name); // Formats the string for file format. "\r\n" starts a new line each time.
        fwrite(names, string); // write the formatted string to the file
        fclose(names); // and close it!
    }
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    new
        name[24], // name of the player
        string[28] // the string that we will read from the file
    ;
    GetPlayerName(playerid, name, 24); // Get the player's name
    if(!fexist("forbidden_names.txt"))
    {
        // if the file does not exist, then stop running the code.
        // because reading a file that doesn't exist crashes the server
        print("File [forbidden_names.txt] does not exist");
        return 1;
    }
    new File:names = fopen("forbidden_names.txt", io_read); // open the file for reading.
    while(fread(names,string)) // while there is text in a line read it and store in the string
    {
        if(!strcmp(name, string, true)) // if the player's name matches any name in the file
        {
            SendClientMessage(playerid, -1, "That is an invalid name");
            Kick(playerid); // it kicks them
        }
    }
    return 1;
}
EDIT: didn't read that you needed a /remove name command
Reply


Messages In This Thread
Forbidname [help] - by Kudoz - 08.05.2012, 21:03
Re: Forbidname [help] - by warcodes_ - 08.05.2012, 21:27
Re: Forbidname [help] - by Infinity90 - 08.05.2012, 21:29
Re: Forbidname [help] - by Kudoz - 08.05.2012, 21:32
Re: Forbidname [help] - by warcodes_ - 08.05.2012, 21:50
Re: Forbidname [help] - by ReneG - 08.05.2012, 22:36

Forum Jump:


Users browsing this thread: 2 Guest(s)