SA-MP Forums Archive
Getting First Initials of a RP 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: Getting First Initials of a RP Name (/showthread.php?tid=399387)



Getting First Initials of a RP Name - Ballu Miaa - 14.12.2012

Hello Everyone,

I am trying to make a stock function with a string parameter , in which i can pass a RPName and it will return me a First initial of the first name attached with the last name's first initial but im not getting a perfect idea to code it. The stock will do the following function with a String.

Examples with some RP names :
Is there anyone who can help me code this stock , please reply. Your help will be appreciated.

Example of the code:
pawn Код:
stock GetNameInitials(name[])
{
    //Function Body
    return initials; // string
}
Thanks
Ballu Miaa



Re: Getting First Initials of a RP Name - Babul - 14.12.2012

sscan2 can jump-search to a character like _
Код:
sscanf(name,"c'_'c",FirstChar,SecondChar);



Re: Getting First Initials of a RP Name - Ballu Miaa - 14.12.2012

Quote:
Originally Posted by Babul
Посмотреть сообщение
sscan2 can jump-search to a character like _
Код:
sscanf(name,"c'_'c",FirstChar,SecondChar);
Allright can you please explain that a bit Babul my friend? Thanks fore replying.


Re: Getting First Initials of a RP Name - ReneG - 14.12.2012

This works too, but the absolutely has to be in FirstName_LastName format to work.
pawn Код:
stock retFirstLeters(name[MAX_PLAYER_NAME])
{
    new
        strpos = strfind(name, "_", true),
        string[4];
   
    format(string, sizeof(string), "%c%c", name[0], name[strpos+1]);
    return string;
}



Re: Getting First Initials of a RP Name - LarzI - 14.12.2012

The c in the sscanf format represents a character.

You can make a two-dimensional array like this
pawn Код:
new pInitials[2][1] //two arrays - 1 cell each
Then use sscanf like Babul showed you to store the initials:
pawn Код:
sscanf( pName, "c'_'c", pInitials[ 0 ], pInitials[ 1 ]);
The sscanf line does this:

The string "name" is read by sscanf
The first character © it finds will be stored into pIntials[ 0 ].
Then it will search for the first underscore it finds
After it has done that, it will store the next character into pInitials[ 1 ]

This is the best way I can explain this - as I find it quite hard to explain correctly.


Re: Getting First Initials of a RP Name - Ballu Miaa - 14.12.2012

Thanks Vinci My bro, LarzI and Babul for the awesome replies. Reputation+8 given to all of you. Sorry Vinci can not rep you again because of the forums :S!

Much Love Guys!


Re: Getting First Initials of a RP Name - Babul - 15.12.2012

@Larz: what? your explanation looks good: dedictive, logical.
@Ballu: taking over at rep. erm, Da"Vinci"+=8;? done.


Re: Getting First Initials of a RP Name - Ballu Miaa - 15.12.2012

Quote:
Originally Posted by Babul
Посмотреть сообщение
@Ballu: taking over at rep. erm, Da"Vinci"+=8;? done.
Just a token of appreciation in my view. Nah when i rep someone they are repped with +=8 points. XD