Rp Names
#1

Hey, i want to make if the player has a name like this: Name. he will be kicked and he will get a message:
You can only use a name like this Name_Surname.
If you know what i mean.
Reply
#2

Код:
RPName(name[],ret_first[],ret_last[])
{
	new len = strlen(name),
		point = -1,
		bool:done = false;
	for(new i = 0; i < len; i++)
	{
	  if(name[i] == '_')
	  {
	    if(point != -1) return 0;
	    else {
				if(i == 0) return 0;
				point = i + 1;
			}
	  } else if(point == -1) ret_first[i] = name[i];
	  else {
			ret_last[i - point] = name[i];
			done = true;
		}
	}
	if(!done) return 0;
	return 1;
}
Код:
public OnPlayerConnect(playerid)
{
	new name[MAX_PLAYER_NAME], first[MAX_PLAYER_NAME], last[MAX_PLAYER_NAME], ret;
	GetPlayerName(playerid,name,sizeof(name));
	if(RPName(name,first,last))
	{
		// Valid name, player is called first_last
	} else {
	  // Invalid name, deal accordingly
	}
	return 1;
}
Reply
#3

Where to put the first code?
Reply
#4

U can add it every where u want. Like put it at bottom of u script.
Reply
#5

If i try to compile i will get a message: Pawn Complier libary has stopped working.
Reply
#6

Maybe try this:
pawn Код:
//bottom of u script
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;
}
//onplayerconnect
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
        for(new i=0;i<MAX_PLAYERS;i++)
        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;
}
Let me know if it works
Reply
#7

Quote:
Originally Posted by admigo
Посмотреть сообщение
Maybe try this:
pawn Код:
//bottom of u script
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;
}
//onplayerconnect
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;
}
Let me know if it works
Almost but i got 2 errors.

Код:
C:\Users\Magdy\Desktop\Server 3.0e\gamemodes\RolePlay.pwn(65) : error 017: undefined symbol "i"
C:\Users\Magdy\Desktop\Server 3.0e\gamemodes\RolePlay.pwn(65) : error 017: undefined symbol "i"
Line 65
pawn Код:
if (IsPlayerConnected(i)) GetPlayerName(i, roleplayname, MAX_PLAYER_NAME);
Reply
#8

Edited the code.
Reply
#9

Quote:
Originally Posted by admigo
Посмотреть сообщение
Edited the code.
Thanks it worked
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)