Get name before underscore - 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: Get name before underscore (
/showthread.php?tid=392516)
Get name before underscore -
SKAzini - 14.11.2012
How do I get the name before the underscore in roleplay names?
Eg. Michelle_Rodriguez
Is there a way to put the "Michelle" in a variable, without the characters after the underscore from GetPlayerName?
Re: Get name before underscore -
Faisal_khan - 14.11.2012
This will help you out buddy:
pawn Код:
stock getFirstName(szPlayerName[]) {
new
_tmpSzPlayerName[MAX_PLAYER_NAME],
iCh = strfind(szPlayerName, "_", true);
if(iCh != -1) {
strcat(_tmpSzPlayerName, szPlayerName, MAX_PLAYER_NAME);
strdel(_tmpSzPlayerName, iCh, strlen(szPlayerName));
} else {
format(_tmpSzPlayerName, sizeof(_tmpSzPlayerName), "Nameless");
}
return _tmpSzPlayerName;
}
Re: Get name before underscore -
SKAzini - 14.11.2012
Thanks. Worked for me.
pawn Код:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
SetPlayerName(playerid, getFirstName(name));