SA-MP Forums Archive
Checking if Legal Name - 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: Checking if Legal Name (/showthread.php?tid=479759)



Checking if Legal Name - Mattakil - 07.12.2013

I dont want anyone to be able to log in if they don't have "_" in their name, so I tried to copy strreplace stock, though it always returns true.

pawn Код:
stock IllegalName(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));

    for(new i=0; name[i]; i++)
    {
        if(name[i] != '_')
        {
            return true;
        }
    }
    return 1;
}



Re: Checking if Legal Name - Hansrutger - 07.12.2013

I don't know if it's the answer (no sarcasm) but you're returning true on all return places, that might be it?


Re: Checking if Legal Name - Mattakil - 07.12.2013

Well, I tried else return false, though it bitched at me for a warning if I remove the return 1 :/


Re: Checking if Legal Name - Hansrutger - 07.12.2013

Not remove but just change 1 to 0. Eh' I honestly don't know, I'm simply just guessing now… xD Sue me :P


Re: Checking if Legal Name - Mattakil - 07.12.2013

Nope.


Re: Checking if Legal Name - Memoryz - 07.12.2013

Not made by me, but I've saved this around.

Provide the name as the first argument, and two empty strings to the last two, it will return the first and second name into each string.

pawn Код:
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;
}



Re: Checking if Legal Name - Wizza - 07.12.2013

What do you want to do exactly? if he dosent have a '_' you kick him?


Re: Checking if Legal Name - Threshold - 07.12.2013

pawn Код:
stock IllegalName(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));
    for(new i = 0; i < strlen(name); i++)
    {
        if(name[i] == '_')
        {
            return 0;
        }
    }
    return 1;
}
This should work for you.


Re: Checking if Legal Name - Wizzy951 - 07.12.2013

pawn Код:
stock IsRPName(name[])
{
   new upos=strfind(name, "_");
   if(isnull(name)) return false;
   if(strlen(name)-2<upos<2) return false;
   for(new i = 0; i < 24; i++)
   {
      if(!name[i]) break;
      if(!i && 65 > name[i] > 90) return false;
      if(name[i] == 95 && i!=upos) return false;
      if(upos && i-upos == 1)
      {
         if(65 > name[i] > 90) return false;
      }
      if(65 <= name[i] <= 90)
      {
         if(!(!i || i==upos+1 || (i==2 && upos>5) || (i==upos+3 && strlen(name)-upos>5))) return false;
      }
      if(97 > name[i] > 122) return false;
   }
   if(upos==-1) return false;
   if(strlen(name)-upos<3) return false;
   return true;
}
//Credits to whoever has made this function (I don't really remember who used to create it)

//This goes under OnPlayerConnect
    if(!IsRPName(GetPName(playerid)))
    {
        SendClientMessage(playerid, RED, "SERVER: You have been kicked for having an invalid RP name! Your nickname should be like Firstname_Lastname");
        DelayedKick(playerid);
        return 1;
    }