SA-MP Forums Archive
Getting half of a players 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 half of a players name (/showthread.php?tid=552491)



Getting half of a players name - jackx3rx - 24.12.2014

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'?


Re : Getting half of a players name - StreetRP - 24.12.2014

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); 



Re: Getting half of a players name - jackx3rx - 24.12.2014

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'.


Re: Getting half of a players name - Abagail - 24.12.2014

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).