Capitalizing 1st letters of First, and last name... ? Firstname_Lastname
#1

Soo.. I tried this
pawn Код:
new NewName[2][MAX_PLAYER_NAME];
    split(PlayerName(playerid),NewName,'_');
    toupper(NewName[0][1]);
    toupper(NewName[1][1]);
    format(string,sizeof(string),"%s_%s",NewName[0],NewName[1]);
    SetPlayerName(playerid,string);
But have no clue why it isn't working..
Reply
#2

I dont think those are used in pawno? Maybe in java yes..
Reply
#3

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
I dont think those are used in pawno? Maybe in java yes..
toupper ??
It's real.. lmfao
pawn Код:
native toupper(c);
Reply
#4

pawn Код:
toupper(NewName[0][1]);
Because you're capitalizing the first cell of the name, and not the other 23 cells.
Reply
#5

Quote:
Originally Posted by __
Посмотреть сообщение
pawn Код:
toupper(NewName[0][1]);
Because you're capitalizing the first cell of the name, and not the other 23 cells.
Uhm.. Yes, I've switched that to [0][0] and [1][0] .. As I am attempting to capitalize only the FIRST letter, but apparently it is not inserted back into the string.
Reply
#6

Ok.. now I have
pawn Код:
new NewName[2][MAX_PLAYER_NAME];
    split(PlayerName(playerid),NewName,'_');
    printf("%s_%s",NewName[0],NewName[1]);
    new pos;
    pos = strfind(PlayerName(playerid),NewName[1]);
    printf("%s_%s",NewName[0],NewName[1]);
    format(string,sizeof(string),"%s_%s",NewName[0],NewName[1]);
    new letter1[10];
    format(letter1,10,"%s",toupper(NewName[0][0]));
    new letter2[10];
    format(letter2,10,"%s",toupper(NewName[1][0]));
    strdel(string,0,0);
    strins(string,letter1,0,24);
    strdel(string,pos,pos);
    strins(string,letter2,pos,24);
    SetPlayerName(playerid,string);
It still isn't working..
Reply
#7

Here is full function list what you will need. It allows only Name_Lastname.
to check name use NameIsRP
Credits to PR-RP script
pawn Код:
IsUpper(ch)
{
    if(ch>64&&ch<91) return 1;
    return 0;
}

TooManyCaps(name[])
{
    new Float:caps,num,sz;
    sz=strlen(name[0]);
    while(sz--) {
    if(IsUpper(name[sz])) num++;
    }
    caps=floatdiv(num,float(strlen(name[0])-1)); //-1 because we don't include the _ in the percentage
    caps=floatmul(caps,float(100));
    if(caps>40) return 1; //40% seems to be the magic number for names
    return 0;
}

CapsOnEnd(name[])
{
    new sz;
    sz=strlen(name[0]);
    if(IsUpper(name[sz-1])) return 1;
    if(IsUpper(name[FirstSeperationLoc(name[0])-1])) return 1;
    return 0;
}

ConsecutiveCaps(name[])
{
    new sz,lastcaps;
    sz=strlen(name[0]);
    while(sz--) {
    if(IsUpper(name[sz])) {
    if(lastcaps==1) {
    return 1;
    }
    lastcaps=1;
    } else lastcaps=0;
    }
    return 0;
}

TooShortOnEnd(name[])
{
    new pnt;
    pnt=FirstSeperationLoc(name[0]);
    name[pnt]=0;
    if((strlen(name[0])<3)||strlen(name[pnt+1])<3) {
    name[pnt]='_'; //restore it for use later
    return 1;
     }
    name[pnt]='_';
    return 0;
}

NumOccurences(str[],ch)
{
    new num=0,strl;
    strl=strlen(str);
    while(strl--) {
    if(str[strl]==ch) num++;
    }
    return num;
}

IsInvalid(x)
{
    if(x==95) return 0;
    if(x>64&&x<91) return 0;
    if(x>96&&x<123) return 0;
    return 1;
}

FirstSeperationLoc(str[])
{
    new strl;
    strl=strlen(str);
    while(strl--) {
    if(str[strl]=='_') return strl;
    }
    return 0;
}

InvalidCaps(str[])
{
    if(!IsUpper(str[0])||!IsUpper(str[FirstSeperationLoc(str[0])+1])) return 1;
    return 0;
}

NameIsRP(name[])
{
    new len;
    len=strlen(name[0]);
    if(InvalidCaps(name[0]) || NumOccurences(name[0],'_') != 1) return 0;
    while(len--) {
    if(IsInvalid(name[len])) return 0;
    }
    if(TooManyCaps(name[0])) return 0;
    if(ConsecutiveCaps(name[0])) return 0;
    if(CapsOnEnd(name[0])) return 0;
    if(TooShortOnEnd(name[0])) return 0;
    return 1;
}
Edit: Bwah wrong thread
Reply
#8

pawn Код:
#define toupper(%0) \
    (((%0) >= 'a' && (%0) <= 'z') ? ((%0) & ~0x20) : (%0))

#define tolower(%0) \
    (((%0) >= 'A' && (%0) <= 'Z') ? ((%0) | 0x20) : (%0))
By ******, have you already been using this?
Reply
#9

Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
pawn Код:
#define toupper(%0) \
    (((%0) >= 'a' && (%0) <= 'z') ? ((%0) & ~0x20) : (%0))

#define tolower(%0) \
    (((%0) >= 'A' && (%0) <= 'Z') ? ((%0) | 0x20) : (%0))
By ******, have you already been using this?
Urrr..
pawn Код:
toupper(NewName[0][0]);
    toupper(NewName[1][0]);
And I get
Код:
C:\Users\Connor\Dropbox\RC6\gamemodes\wl-rp.pwn(3957) : warning 215: expression has no effect
C:\Users\Connor\Dropbox\RC6\gamemodes\wl-rp.pwn(3958) : warning 215: expression has no effect
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Warnings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)