Firstname lastname
#1

If a player has ethically this name: Super_Man
How do you get the words specifically on each side of the line?
Like instead of doing:

format(string, sizeof(string), "{33AA33}Full name: {FFFFFF}%s", RPN(playerid));
SendClientMessage(playerb, COLOR_WHITE, string);

You could do:

format(string, sizeof(string), "{33AA33}Firstname: {FFFFFF}%s", ??(playerid));
SendClientMessage(playerb, COLOR_WHITE, string);
format(string, sizeof(string), "{33AA33}Lastname: {FFFFFF}%s", ??(playerid));
SendClientMessage(playerb, COLOR_WHITE, string);
Reply
#2

You can check with strfind where the '_' is.

Then you can use the first letters till the output of strfind for the first name. Same with the lastname.

https://sampwiki.blast.hk/wiki/Strfind
Reply
#3

I don't really know how to do that though.

I have a code to remove the underscore, could it be worked out from that?
pawn Код:
stock RemoveUnderScore(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}
Reply
#4

I don't understand why removing that _ now. :P

It's easy to detect it in a string(the playername) and then you can make 2 strings out of this one.

Read 2 times how strfind works then you will understand how this comes in handy. It's the output that strfind gives.
Reply
#5

Quote:
Originally Posted by Flori
Посмотреть сообщение
It's easy to detect it in a string(the playername) and then you can make 2 strings out of this one.
It's the output that strfind gives.
First of all, how am i supposed to make 2 strings out of a strfind line, and make them work giving firstname lastname to put somewhere else, and i don't even understand what the output is?

(const string[],const sub[],bool:ignorecase=false,pos=0)
const string[] The string you want to search in (haystack).
const sub[] The string you want to search for (needle).
ignorecase (optional) When set to true, the case doesn't matter - HeLLo is the same as Hello. When false, they're not the same.
Position (optional)

This is the wiki page for strfind, i don't see how that's gonna divide firstname and lastname from each other, and them make a parameter(think its called) to put it in another string.
Reply
#6

I make a a very short example:

pawn Код:
strfind("hello_lalala"/*get the name from a player, just an example here*/,"_",false)
//now it will give "5" as output. So you can create a code now in which you use the first 5 letters for the "firstname and the 6+ letters for the lastname
Reply
#7

Quote:
Originally Posted by Flori
Посмотреть сообщение
I make a a very short example:

pawn Код:
strfind("hello_lalala"/*get the name from a player, just an example here*/,"_",false)
//now it will give "5" as output. So you can create a code now in which you use the first 5 letters for the "firstname and the 6+ letters for the lastname
I kind of understand it, but not everyone has a specific number of characters as first/last name. And i don't know how to make a code to get the first/last name and convert it so that it can be used in a string as Firstname(playerid) and Lastname(playerid) instead of RPN(playerid).
Reply
#8

Bump.
Reply
#9

pawn Код:
stock GetPlayerFirstName(playerid)
{
    new namestring[2][MAX_PLAYER_NAME], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    split(name, namestring, '_');
    return namestring[0];
}
or

pawn Код:
new name[MAX_PLAYER_NAME], find, length;
GetPlayerName(playerid,name,sizeof(name));
find = strfind(name,"_",false);
length = strlen(name);
strdel(name,find,length);

// Players first name is stored in 'name'.
Reply
#10

Couldn't you do this?

new string[128];
format(STRING, "[SERVER]: %s has joined the server!", GetPlayerName(playerid));
SendClientMessageToAll(COLOR_YELLOW, string);

Or something like that to show a person has joined with _ in the name?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)