dcmd_kicknonrp(playerid,params[])
{
new target;
if(!sscanf(params,"u",target))
{
if(IsPlayerConnected(target))
{
new Playername[MAX_PLAYER_NAME],str[70];
GetPlayerName(target,Playername,sizeof(Playername));
format(str,sizeof(str),"* %s was kicked, come back with a roleplay name.",Playername);
SendClientMessageToAll(-1,str);
Kick(target);
}
else return SendClientMessage(playerid,-1,"Invalid player.");
}
else return SendClientMessage(playerid,-1,"Error: /kicknonrp [ID].");
}
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
pawn Код:
pawn Код:
|
dcmd_kicknonrp(playerid,params[])
{
new target;
if(!sscanf(params,"u",target))
{
if(IsPlayerConnected(target))
{
new Playername[MAX_PLAYER_NAME],Targetname[MAX_PLAYER_NAME],str[110];
GetPlayerName(playerid,Playername,sizeof(Playername));
GetPlayerName(target,Targetname,sizeof(Targetname));
format(str,sizeof(str),"* %s was kicked, come back with a roleplay name such as %s.",Targetname,Playername);
SendClientMessageToAll(-1,str);
Kick(target);
}
else return SendClientMessage(playerid,-1,"Invalid player.");
}
else return SendClientMessage(playerid,-1,"Error: /kicknonrp [ID].");
}
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;
}
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;
}