Checking if Legal Name
#1

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;
}
Reply
#2

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

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

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

Nope.
Reply
#6

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;
}
Reply
#7

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

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.
Reply
#9

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;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)