Help me Please! - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help me Please! (
/showthread.php?tid=293749)
Help me Please! -
nmader - 29.10.2011
So, I have this...
Код:
public OnPlayerConnect(playerid)
{
new plname[MAX_PLAYER_NAME];
new namestring = strfind(plname, "_", true);
if(namestring == -1)
{
SendClientMessage(playerid, 0xAA3333AA, "SERVER: Incorrect name format: Firstname_Lastname.");
Kick(playerid);
return 1;
}
else
{
SendClientMessage(playerid, 0xDABB3EAA, "Welcome to World War III Roleplay!");
return 1;
}
}
It should not be kicking players who have a name format of Firstname_Lastname, but it is kicking EVERY username it gets thrown at it...
Any help will be appreciated with +rep!
Thanks,
nmader.
Re: Help me Please! -
Steven82 - 29.10.2011
Use this function. Credits to LennyTheCup.
pawn Код:
// Place this in script.
stock IsARoleplayName(name[]) // Function created by LennytheCup
{
new
szLastCell,
bool: bUnderScore;
for(new i; i < strlen(name); i++)
{
if(name[i] == '_')
{
if(bUnderScore == true)
{
return 0;
}
bUnderScore = true;
}
else if(!szLastCell || szLastCell == '_')
{
if(name[i] < 'A' || name[i] > 'Z')
{
return 0;
}
}
else
{
if(name[i] < 'a' || name[i] > 'z')
return 0;
}
szLastCell = name[i];
}
if(bUnderScore == false)
return 0;
return 1;
}
This in OnPlayerConnect
pawn Код:
public OnPlayerConnect(playerid)
{
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
if(!IsARoleplayName(pName))
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Error: Your name doesn't fit roleplay standards. Make sures it's in firstname_lastname format.");
Kick(playerid);
}
}
Re: Help me Please! -
=WoR=G4M3Ov3r - 29.10.2011
Why do this, when you can just use a callback for it ?, since its roleplay, I've made this some time ago.
PHP код:
public IsValidName(playerid)
{
new pname[MAX_PLAYER_NAME],underline=0;
GetPlayerName(playerid, pname, sizeof(pname));
if(strfind(pname,"[",true) != (-1)) return 0;
else if(strfind(pname,".",true) != (-1)) return 0;
else if(strfind(pname,"]",true) != (-1)) return 0;
else if(strfind(pname,"$",true) != (-1)) return 0;
else if(strfind(pname,"(",true) != (-1)) return 0;
else if(strfind(pname,")",true) != (-1)) return 0;
else if(strfind(pname,"=",true) != (-1)) return 0;
else if(strfind(pname,"@",true) != (-1)) return 0;
else if(strfind(pname,"1",true) != (-1)) return 0;
else if(strfind(pname,"2",true) != (-1)) return 0;
else if(strfind(pname,"3",true) != (-1)) return 0;
else if(strfind(pname,"4",true) != (-1)) return 0;
else if(strfind(pname,"5",true) != (-1)) return 0;
else if(strfind(pname,"6",true) != (-1)) return 0;
else if(strfind(pname,"7",true) != (-1)) return 0;
else if(strfind(pname,"8",true) != (-1)) return 0;
else if(strfind(pname,"9",true) != (-1)) return 0;
new maxname = strlen(pname);
for(new i=0; i<maxname; i++) { if(pname[i] == '_') underline ++; }
if(underline != 1) return 0;
pname[0] = toupper(pname[0]);
for(new x=1; x<maxname; x++)
{
if(pname[x] == '_') pname[x+1] = toupper(pname[x+1]);
else if(pname[x] != '_' && pname[x-1] != '_') pname[x] = tolower(pname[x]);
}
SetPlayerName(playerid, "New_Name");
SetPlayerName(playerid, pname);
return 1;
}
PS: for idiots, who're gonna complain about not using case switch, don't bother posting, I'm lazy.