Non-Rp name Kick
#10

you can also use this stock function to detect if the player uses Non-RP name:
pawn Код:
stock IsRPName(const name[], max_underscores = 2)
{
    new underscores = 0;
    if (name[0] < 'A' || name[0] > 'Z') return false; // First letter is not capital
    for(new i = 1; i < strlen(name); i++)
    {
        if(name[i] != '_' && (name[i] < 'A' || name[i] > 'Z') && (name[i] < 'a' || name[i] > 'z')) return false; // a-zA-Z_
        if( (name[i] >= 'A' && name[i] <= 'Z') && (name[i - 1] != '_') ) return false; // unneeded capital letter
        if(name[i] == '_')
        {
            underscores++;
            if(underscores > max_underscores || i == strlen(name)) return false; // More underlines than limit, or underline at the last pos
            if(name[i + 1] < 'A' || name[i + 1] > 'Z') return false; // Not a capital letter after underline
        }
    }
    if (underscores == 0) return false; // No underline detected
    return true;
}
under OnPlayerConnect, you put:
pawn Код:
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME], roleplayname[MAX_PLAYER_NAME] = "Will_Smith", goodbyemessage[108];
    GetPlayerName(playerid, name, sizeof(name));
    if (!IsRPName(name)) // you can control the max underlines, e.g if you allow max. 1 underlines, write this: if (!IsRPName(name, 1))
    {
        for (new i = 0; i < MAX_PLAYERS; i++) if (IsPlayerConnected(i)) break; // find a player who is online (and hasn't got kicked from the server -> has got a RolePlay name
        if (IsPlayerConnected(i)) GetPlayerName(i, roleplayname, MAX_PLAYER_NAME); // if there was an online player, it's name will be the suggested roleplay name
        format (goodbyemessage, sizeof(goodbyemessage), "* %s was kicked, come back with a roleplay name such as %s", name, roleplayname);
        SendClientMessageToAll(-1, goodbyemessage);
        return Kick(playerid);
    }

    // more things you do in OnPlayerConnect
    return 1;
}
Reply


Messages In This Thread
Non-Rp name Kick - by uprp - 26.08.2011, 17:11
Re: Non-Rp name Kick - by Jochemd - 26.08.2011, 17:15
Re: Non-Rp name Kick - by uprp - 26.08.2011, 17:18
Re: Non-Rp name Kick - by Jochemd - 26.08.2011, 17:20
Re: Non-Rp name Kick - by uprp - 26.08.2011, 17:22
Re: Non-Rp name Kick - by KeeDee - 26.08.2011, 17:24
Re: Non-Rp name Kick - by Jochemd - 26.08.2011, 17:26
Re: Non-Rp name Kick - by uprp - 26.08.2011, 17:29
Re: Non-Rp name Kick - by uprp - 26.08.2011, 17:37
Re: Non-Rp name Kick - by KoczkaHUN - 26.08.2011, 17:40

Forum Jump:


Users browsing this thread: 1 Guest(s)