Getting half of a players name
#1

If a players name is David_Smith and I only wanted to get the first half (David), how would I do so?

I want a command for example:

ID 1 is David_Smith

/whois 1 > displays "David, Age %i"

But I don't know how to grab the first part, 'David'?
Reply
#2

String to short ?
PHP код:
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME]; 
PHP код:
    GetPlayerName(playeridnamesizeof(name)); 
PHP код:
    format(stringsizeof(string), "%s Age %d."name,'variableofyear');
    
SendClientMessageToAll(-1string); 
Reply
#3

No I want it to only display 'David' rather than 'David_Smith', so only the players firstname.

And I want it to work with all different sizes of names so 'Elizabeth_Rudolph', would give me 'Elizabeth'.
Reply
#4

Something like this?

pawn Код:
stock GetPlayerFirstName(playerid)
{
    new NickName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, NickName, MAX_PLAYER_NAME);
    strdel(NickName, strfind(NickName, "_"), strlen(NickName));
    return NickName;
}
or
pawn Код:
sscanf(PlayerName,"s[24]'_'{s[24]}",FirstName);
Credits go to this thread: https://sampforum.blast.hk/showthread.php?tid=328590
A search would've gave you an answer pretty fast(******.com).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)